sftp: Prompt for password, don't terminate on SIGINT

This is a follow-up on fb9729fdb9, which
runs the `ssh` in its own process group and selects that process group
as the foreground group. After the sftp connection is established,
restic switches back to the previous foreground process group.

This allows `ssh` to prompt for the password, but it won't receive
the interrupt signal (SIGINT, ^C) later on, because it is not in the
foreground process group any more, allowing a clean tear down.
This commit is contained in:
Alexander Neumann 2018-01-17 23:02:47 +01:00
parent 87e31799f2
commit 05958caf6e
3 changed files with 101 additions and 2 deletions

View file

@ -69,8 +69,8 @@ func startClient(preExec, postExec func(), program string, args ...string) (*SFT
preExec()
}
// start the process
if err := cmd.Start(); err != nil {
bg, err := startForeground(cmd)
if err != nil {
return nil, errors.Wrap(err, "cmd.Start")
}
@ -92,6 +92,11 @@ func startClient(preExec, postExec func(), program string, args ...string) (*SFT
return nil, errors.Errorf("unable to start the sftp session, error: %v", err)
}
err = bg()
if err != nil {
return nil, errors.Wrap(err, "bg")
}
return &SFTP{c: client, cmd: cmd, result: ch}, nil
}