mirror of
https://github.com/restic/restic.git
synced 2026-02-03 04:20:45 -05:00
backend: always start backend process in separate process group
The process group is necessary to properly handle ctrl-c.
This commit is contained in:
parent
4c19d6410f
commit
914bd699be
1 changed files with 7 additions and 5 deletions
|
|
@ -25,6 +25,12 @@ func tcsetpgrp(fd int, pid int) error {
|
|||
}
|
||||
|
||||
func startForeground(cmd *exec.Cmd) (bg func() error, err error) {
|
||||
// run the command in its own process group
|
||||
// this ensures that sending ctrl-c to restic will not immediately stop the backend process.
|
||||
cmd.SysProcAttr = &unix.SysProcAttr{
|
||||
Setpgid: true,
|
||||
}
|
||||
|
||||
// open the TTY, we need the file descriptor
|
||||
tty, err := os.OpenFile("/dev/tty", os.O_RDWR, 0)
|
||||
if err != nil {
|
||||
|
|
@ -52,11 +58,6 @@ func startForeground(cmd *exec.Cmd) (bg func() error, err error) {
|
|||
signal.Ignore(unix.SIGTTIN)
|
||||
signal.Ignore(unix.SIGTTOU)
|
||||
|
||||
// run the command in its own process group
|
||||
cmd.SysProcAttr = &unix.SysProcAttr{
|
||||
Setpgid: true,
|
||||
}
|
||||
|
||||
// start the process
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
|
|
@ -92,5 +93,6 @@ func startFallback(cmd *exec.Cmd) (bg func() error, err error) {
|
|||
bg = func() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return bg, cmd.Start()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue