Move backend/sftp.StartForeground to backend/

This commit is contained in:
Alexander Neumann 2018-03-13 21:09:16 +01:00
parent 34f27edc03
commit cf4cf94418
4 changed files with 11 additions and 8 deletions

View File

@ -1,4 +1,4 @@
package sftp package backend
import ( import (
"os/exec" "os/exec"
@ -7,7 +7,10 @@ import (
"github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/errors"
) )
func startForeground(cmd *exec.Cmd) (bg func() error, err error) { // StartForeground runs cmd in the foreground, by temporarily switching to the
// new process group created for cmd. The returned function `bg` switches back
// to the previous process group.
func StartForeground(cmd *exec.Cmd) (bg func() error, err error) {
// run the command in it's own process group so that SIGINT // run the command in it's own process group so that SIGINT
// is not sent to it. // is not sent to it.
cmd.SysProcAttr = &syscall.SysProcAttr{ cmd.SysProcAttr = &syscall.SysProcAttr{

View File

@ -1,7 +1,7 @@
// +build !solaris // +build !solaris
// +build !windows // +build !windows
package sftp package backend
import ( import (
"os" "os"
@ -24,10 +24,10 @@ func tcsetpgrp(fd int, pid int) error {
return errno return errno
} }
// startForeground runs cmd in the foreground, by temporarily switching to the // StartForeground runs cmd in the foreground, by temporarily switching to the
// new process group created for cmd. The returned function `bg` switches back // new process group created for cmd. The returned function `bg` switches back
// to the previous process group. // to the previous process group.
func startForeground(cmd *exec.Cmd) (bg func() error, err error) { func StartForeground(cmd *exec.Cmd) (bg func() error, err error) {
// open the TTY, we need the file descriptor // open the TTY, we need the file descriptor
tty, err := os.OpenFile("/dev/tty", os.O_RDWR, 0) tty, err := os.OpenFile("/dev/tty", os.O_RDWR, 0)
if err != nil { if err != nil {

View File

@ -1,4 +1,4 @@
package sftp package backend
import ( import (
"os/exec" "os/exec"
@ -6,7 +6,7 @@ import (
"github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/errors"
) )
// startForeground runs cmd in the foreground, by temporarily switching to the // StartForeground runs cmd in the foreground, by temporarily switching to the
// new process group created for cmd. The returned function `bg` switches back // new process group created for cmd. The returned function `bg` switches back
// to the previous process group. // to the previous process group.
func startForeground(cmd *exec.Cmd) (bg func() error, err error) { func startForeground(cmd *exec.Cmd) (bg func() error, err error) {

View File

@ -65,7 +65,7 @@ func startClient(program string, args ...string) (*SFTP, error) {
return nil, errors.Wrap(err, "cmd.StdoutPipe") return nil, errors.Wrap(err, "cmd.StdoutPipe")
} }
bg, err := startForeground(cmd) bg, err := backend.StartForeground(cmd)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "cmd.Start") return nil, errors.Wrap(err, "cmd.Start")
} }