@@ -13,7 +13,7 @@ import (
13
13
// to indicated that the process is a child as opposed to the reaper.
14
14
// Since we are forkexec'ing we need to be able to differentiate between
15
15
// the two to avoid fork bombing ourselves.
16
- const agentEnvMark = "CODER_REAPER_AGENT "
16
+ const agentEnvMark = "CODER_DO_NOT_REAP "
17
17
18
18
// IsChild returns true if we're the forked process.
19
19
func IsChild () bool {
@@ -34,41 +34,43 @@ func IsInitProcess() bool {
34
34
func ForkReap (pids reap.PidCh ) error {
35
35
// Check if the process is the parent or the child.
36
36
// If it's the child we want to skip attempting to reap.
37
- if ! IsChild () {
38
- go reap .ReapChildren (pids , nil , nil , nil )
37
+ if IsChild () {
38
+ return nil
39
+ }
40
+
41
+ go reap .ReapChildren (pids , nil , nil , nil )
39
42
40
- args := os .Args
41
- // This is simply done to help identify the real agent process
42
- // when viewing in something like 'ps'.
43
- args = append (args , "#Agent" )
43
+ args := os .Args
44
+ // This is simply done to help identify the real agent process
45
+ // when viewing in something like 'ps'.
46
+ args = append (args , "#Agent" )
44
47
45
- pwd , err := os .Getwd ()
46
- if err != nil {
47
- return xerrors .Errorf ("get wd: %w" , err )
48
- }
48
+ pwd , err := os .Getwd ()
49
+ if err != nil {
50
+ return xerrors .Errorf ("get wd: %w" , err )
51
+ }
49
52
50
- pattrs := & syscall.ProcAttr {
51
- Dir : pwd ,
52
- // Add our marker for identifying the child process.
53
- Env : append (os .Environ (), fmt .Sprintf ("%s=true" , agentEnvMark )),
54
- Sys : & syscall.SysProcAttr {
55
- Setsid : true ,
56
- },
57
- Files : []uintptr {
58
- uintptr (syscall .Stdin ),
59
- uintptr (syscall .Stdout ),
60
- uintptr (syscall .Stderr ),
61
- },
62
- }
53
+ pattrs := & syscall.ProcAttr {
54
+ Dir : pwd ,
55
+ // Add our marker for identifying the child process.
56
+ Env : append (os .Environ (), fmt .Sprintf ("%s=true" , agentEnvMark )),
57
+ Sys : & syscall.SysProcAttr {
58
+ Setsid : true ,
59
+ },
60
+ Files : []uintptr {
61
+ uintptr (syscall .Stdin ),
62
+ uintptr (syscall .Stdout ),
63
+ uintptr (syscall .Stderr ),
64
+ },
65
+ }
63
66
64
- pid , _ := syscall .ForkExec (args [0 ], args , pattrs )
67
+ //#nosec G204
68
+ pid , _ := syscall .ForkExec (args [0 ], args , pattrs )
65
69
66
- var wstatus syscall.WaitStatus
70
+ var wstatus syscall.WaitStatus
71
+ _ , err = syscall .Wait4 (pid , & wstatus , 0 , nil )
72
+ for xerrors .Is (err , syscall .EINTR ) {
67
73
_ , err = syscall .Wait4 (pid , & wstatus , 0 , nil )
68
- for xerrors .Is (err , syscall .EINTR ) {
69
- _ , err = syscall .Wait4 (pid , & wstatus , 0 , nil )
70
- }
71
- return nil
72
74
}
73
75
74
76
return nil
0 commit comments