2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-26 23:06:32 +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" "os/exec"
"path/filepath" "path/filepath"
"sort" "sort"
"syscall"
"github.com/juju/errors" "github.com/juju/errors"
"github.com/pkg/sftp" "github.com/pkg/sftp"
@ -28,8 +27,6 @@ type SFTP struct {
cmd *exec.Cmd cmd *exec.Cmd
} }
var sysProcAttr syscall.SysProcAttr
func startClient(program string, args ...string) (*SFTP, error) { func startClient(program string, args ...string) (*SFTP, error) {
// Connect to a remote host and request the sftp subsystem via the 'ssh' // Connect to a remote host and request the sftp subsystem via the 'ssh'
// command. This assumes that passwordless login is correctly configured. // 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 cmd.Stderr = os.Stderr
// ignore signals sent to the parent (e.g. SIGINT) // ignore signals sent to the parent (e.g. SIGINT)
cmd.SysProcAttr = &sysProcAttr cmd.SysProcAttr = ignoreSigIntProcAttr()
// get stdin and stdout // get stdin and stdout
wr, err := cmd.StdinPipe() wr, err := cmd.StdinPipe()

View File

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