From 281eea9c05405b4ed2ddb40e18fa62aa5c9da2a1 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 5 Jul 2015 11:06:28 +0200 Subject: [PATCH] sftp: Use own process group for ssh subprocess --- backend/sftp/sftp.go | 10 +++++++++- cmd/restic/lock.go | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.go index 4361eed69..71c874f0b 100644 --- a/backend/sftp/sftp.go +++ b/backend/sftp/sftp.go @@ -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() } diff --git a/cmd/restic/lock.go b/cmd/restic/lock.go index 5f6c18802..389241644 100644 --- a/cmd/restic/lock.go +++ b/cmd/restic/lock.go @@ -49,7 +49,9 @@ func lockRepository(repo *repository.Repository, exclusive bool) (*restic.Lock, } func unlockRepo(lock *restic.Lock) error { + debug.Log("unlockRepo", "unlocking repository") if err := lock.Unlock(); err != nil { + debug.Log("unlockRepo", "error while unlocking: %v", err) return err } @@ -67,8 +69,10 @@ func unlockAll() error { debug.Log("unlockAll", "unlocking %d locks", len(globalLocks)) for _, lock := range globalLocks { if err := lock.Unlock(); err != nil { + debug.Log("unlockAll", "error while unlocking: %v", err) return err } + debug.Log("unlockAll", "successfully removed lock") } return nil