-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsource_logger.go
45 lines (38 loc) · 1.04 KB
/
source_logger.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"github.com/creack/pty"
"io"
"os"
"os/exec"
"os/signal"
)
func main() {
args := os.Args[1:]
// Calling the srcds_linux executable in the same directory
cmd := exec.Command("./srcds_linux", args...)
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
cmd.Env = append(cmd.Env, "LD_LIBRARY_PATH=.:bin:"+os.Getenv("LD_LIBRARY_PATH"))
// Redirecting the SIGINT or SIGKILL signal to the srcds_linux
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for sig := range c {
err := cmd.Process.Signal(sig)
if err != nil {
fmt.Printf("[sourcelogger] couldn't redirect signal %v to srcds_linux\n", sig)
}
}
}()
// Starting the pseudo terminal for catching the stdout of gmod
file, err := pty.Start(cmd)
if err != nil {
fmt.Println("[sourcelogger] couldn't start the srcds_linux executable")
panic(err)
}
// Redirecting the output of gmod to the stdout
go func() { _, _ = io.Copy(file, os.Stdin) }()
// Redirecting the stdin to input of gmod
_, _ = io.Copy(os.Stdout, file)
}