aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/osutil/osutil_linux.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2019-03-18 10:52:18 +0100
committerDmitry Vyukov <dvyukov@google.com>2019-03-18 10:52:18 +0100
commitbdb7b93f25823c4a76d03592ab4c2baa7c30a1b9 (patch)
tree07e26f0e729f32d075148bed0e664b6bcf758af1 /pkg/osutil/osutil_linux.go
parent08db11409e951dec09f7320771d95167e05b06d3 (diff)
pkg/osutil: kill subprocesses more reliably
In some cases we start scp, which starts ssh, then kill scp but the ssh subprocess is not killed. As the result cmd.Wait hangs waiting for EOF on the stdout/stderr, which are still kept alive by ssh subprocess. But ssh just hangs forever. Create a process group for each command and kill whole process group. Hopefully this will help.
Diffstat (limited to 'pkg/osutil/osutil_linux.go')
-rw-r--r--pkg/osutil/osutil_linux.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/pkg/osutil/osutil_linux.go b/pkg/osutil/osutil_linux.go
index 35e5646fd..732d8e4c2 100644
--- a/pkg/osutil/osutil_linux.go
+++ b/pkg/osutil/osutil_linux.go
@@ -139,6 +139,12 @@ func setPdeathsig(cmd *exec.Cmd) {
cmd.SysProcAttr = new(syscall.SysProcAttr)
}
cmd.SysProcAttr.Pdeathsig = syscall.SIGKILL
+ // We will kill the whole process group.
+ cmd.SysProcAttr.Setpgid = true
+}
+
+func killPgroup(cmd *exec.Cmd) {
+ syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
}
func prolongPipe(r, w *os.File) {