-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpyproc_unix.go
45 lines (39 loc) · 879 Bytes
/
pyproc_unix.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
//go:build !windows
// +build !windows
package jumpboot
import (
_ "embed"
"errors"
"fmt"
"os"
"os/exec"
"os/signal"
"syscall"
)
func setSignalsForChannel(c chan os.Signal) {
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
}
func waitForExit(cmd *exec.Cmd) error {
err := cmd.Wait()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
if exitErr.ExitCode() == -1 {
// The child process was killed
return errors.New("child process was killed")
}
}
return err
}
return nil
}
// return the file descriptors as numerical strings
func setExtraFiles(cmd *exec.Cmd, extraFiles []*os.File) []string {
cmd.ExtraFiles = extraFiles
retv := make([]string, len(extraFiles))
// stdio file descriptors are 0, 1, 2
// extra file descriptors are 3, 4, 5, ...
for i, _ := range extraFiles {
retv[i] = fmt.Sprintf("%d", i+3)
}
return retv
}