2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-22 21:05:10 +00:00

Create ignoreSigIntProcAttr()

Retrieve the SysProcAttr from a separate function. Completely eliminates syscall from main file.
This commit is contained in:
Klaus Post 2015-08-16 12:51:01 +02:00
parent 520b1b65b0
commit 0e7d0d8dba
3 changed files with 16 additions and 7 deletions

View File

@ -10,7 +10,6 @@ import (
"os/exec"
"path/filepath"
"sort"
"syscall"
"github.com/juju/errors"
"github.com/pkg/sftp"
@ -28,8 +27,6 @@ type SFTP struct {
cmd *exec.Cmd
}
var sysProcAttr syscall.SysProcAttr
func startClient(program string, args ...string) (*SFTP, error) {
// Connect to a remote host and request the sftp subsystem via the 'ssh'
// command. This assumes that passwordless login is correctly configured.
@ -39,7 +36,7 @@ func startClient(program string, args ...string) (*SFTP, error) {
cmd.Stderr = os.Stderr
// ignore signals sent to the parent (e.g. SIGINT)
cmd.SysProcAttr = &sysProcAttr
cmd.SysProcAttr = ignoreSigIntProcAttr()
// get stdin and stdout
wr, err := cmd.StdinPipe()

View File

@ -6,7 +6,8 @@ import (
"syscall"
)
func init() {
// ignore signals sent to the parent (e.g. SIGINT)
sysProcAttr = syscall.SysProcAttr{Setsid: true}
// ignoreSigIntProcAttr returns a syscall.SysProcAttr that
// disables SIGINT on parent.
func ignoreSigIntProcAttr() *syscall.SysProcAttr {
return &syscall.SysProcAttr{Setsid: true}
}

View File

@ -0,0 +1,11 @@
package sftp
import (
"syscall"
)
// ignoreSigIntProcAttr returns a default syscall.SysProcAttr
// on Windows.
func ignoreSigIntProcAttr() *syscall.SysProcAttr {
return &syscall.SysProcAttr{}
}