sftp: Use own process group for ssh subprocess

This commit is contained in:
Alexander Neumann 2015-07-05 11:06:28 +02:00
parent 4a2e0b5423
commit 281eea9c05
2 changed files with 13 additions and 1 deletions

View file

@ -10,6 +10,7 @@ import (
"os/exec"
"path/filepath"
"sort"
"syscall"
"github.com/juju/errors"
"github.com/pkg/sftp"
@ -35,6 +36,9 @@ func startClient(program string, args ...string) (*SFTP, error) {
// send errors from ssh to stderr
cmd.Stderr = os.Stderr
// ignore signals sent to the parent (e.g. SIGINT)
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
// get stdin and stdout
wr, err := cmd.StdinPipe()
if err != nil {
@ -452,6 +456,10 @@ func (s *SFTP) Close() error {
}
s.c.Close()
// TODO: add timeout after which the process is killed
if err := s.cmd.Process.Kill(); err != nil {
return err
}
return s.cmd.Wait()
}