From 914bd699be2d050da7acb3dd3fb42a7478b20c16 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Mon, 14 Apr 2025 20:18:58 +0200 Subject: [PATCH] backend: always start backend process in separate process group The process group is necessary to properly handle ctrl-c. --- internal/backend/util/foreground_unix.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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() }