mirror of
https://github.com/restic/restic.git
synced 2025-10-30 01:38:35 +00: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:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user