diff --git a/internal/backend/util/foreground_unix.go b/internal/backend/util/foreground_unix.go index b60a19c44..cba22ab26 100644 --- a/internal/backend/util/foreground_unix.go +++ b/internal/backend/util/foreground_unix.go @@ -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() }