Fix tty capture when started in background#5358
Merged
MichaelEischer merged 3 commits intoSep 6, 2025
Merged
Conversation
The rclone and sftp backends require starting a child process. The are first moved into the foreground and back into the background after the initial startup is done. However, this behavior is also active if restic itself is started in the background. In this case, restic changing the foreground process may confuse the shell and in case of bash causes it to exit. Thus, disable modification of the controlling process group of the tty if restic is run in the background.
The process group is necessary to properly handle ctrl-c.
6103619 to
b96fdc7
Compare
b96fdc7 to
42f690d
Compare
greatroar
added a commit
to greatroar/restic
that referenced
this pull request
Sep 7, 2025
PR restic#5358 reintroduced a version of the TIOCGPGRP ioctl call that works on all Unix platforms except Linux, due to a bug/inconsistency in x/sys/unix. This commit fixes that by introducing termstatus.Tcgetpgrp. It also introduces termstatus.Getpgrp to deal with the different signature of unix.Getpgrp in AIX and Solaris vs. all other Unix platforms, so that some AIX/Solaris-specific code can be removed elsewhere and foreground/background detection is done the same everywhere except on Windows.
4 tasks
greatroar
added a commit
to greatroar/restic
that referenced
this pull request
Sep 7, 2025
PR restic#5358 reintroduced a version of the TIOCGPGRP ioctl call that works on all Unix platforms except Linux, due to a bug/inconsistency in x/sys/unix. This commit fixes that by introducing termstatus.Tcgetpgrp. It also introduces termstatus.Getpgrp to deal with the different signature of unix.Getpgrp in AIX and Solaris vs. all other Unix platforms, so that some AIX/Solaris-specific code can be removed elsewhere and foreground/background detection is done the same everywhere except on Windows.
4 tasks
greatroar
added a commit
to greatroar/restic
that referenced
this pull request
Sep 8, 2025
PR restic#5358 reintroduced a version of the TIOCGPGRP ioctl call that works on all Unix platforms except Linux, due to a bug/inconsistency in x/sys/unix. This commit fixes that by introducing termstatus.Tcgetpgrp. It also introduces termstatus.Getpgrp to deal with the different signature of unix.Getpgrp in Solaris vs. all other Unix platforms, so that some AIX/Solaris-specific code can be removed elsewhere and foreground/background detection is done the same everywhere except on Windows.
greatroar
added a commit
to greatroar/restic
that referenced
this pull request
Sep 8, 2025
PR restic#5358 reintroduced a version of the TIOCGPGRP ioctl call that works on all Unix platforms except Linux, due to a bug/inconsistency in x/sys/unix. This commit fixes that by introducing termstatus.Tcgetpgrp. It also introduces termstatus.Getpgrp to deal with the different signature of unix.Getpgrp in Solaris vs. all other Unix platforms, so that some AIX/Solaris-specific code can be removed elsewhere and foreground/background detection is done the same everywhere except on Windows.
greatroar
added a commit
to greatroar/restic
that referenced
this pull request
Sep 8, 2025
PR restic#5358 reintroduced a version of the TIOCGPGRP ioctl call that works on all Unix platforms except Linux, due to a bug/inconsistency in x/sys/unix. This commit fixes that by introducing termstatus.Tcgetpgrp. It also introduces termstatus.Getpgrp and termstatus.Tcsetpgrp to deal with the different signature of unix.Getpgrp in Solaris vs. all other Unix platforms and an int-overflowing constant on AIX, so that some AIX/Solaris-specific code can be removed elsewhere and foreground/background detection is done the same everywhere except on Windows.
greatroar
added a commit
to greatroar/restic
that referenced
this pull request
Sep 8, 2025
PR restic#5358 reintroduced a version of the TIOCGPGRP ioctl call that works on all Unix platforms except Linux, due to a bug/inconsistency in x/sys/unix. This commit fixes that by introducing termstatus.Tcgetpgrp. It also introduces termstatus.Getpgrp and termstatus.Tcsetpgrp to deal with the different signature of unix.Getpgrp in Solaris vs. all other Unix platforms and an int-overflowing constant on AIX, so that some AIX/Solaris-specific code can be removed elsewhere and foreground/background detection is done the same everywhere except on Windows.
greatroar
added a commit
to greatroar/restic
that referenced
this pull request
Sep 8, 2025
PR restic#5358 reintroduced a version of the TIOCGPGRP ioctl call that works on all Unix platforms except Linux, due to a bug/inconsistency in x/sys/unix. This commit fixes that by introducing termstatus.Tcgetpgrp. It also introduces termstatus.Getpgrp and termstatus.Tcsetpgrp to deal with the different signature of unix.Getpgrp in Solaris vs. all other Unix platforms and an int-overflowing constant on AIX, so that some AIX/Solaris-specific code can be removed elsewhere and foreground/background detection is done the same everywhere except on Windows.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR change? What problem does it solve?
The rclone and sftp backends require starting a child process. It is first moved into the foreground and back into the background after the initial startup is done.
However, this behavior is also active if restic itself is started in the background. In this case, restic changing the foreground process may confuse the shell and in case of bash causes it to exit. Thus, disable modification of the controlling process group of the tty if restic is run in the background.
Was the change previously discussed in an issue or on the forum?
Fixes #5354
Checklist
[ ] I have added documentation for relevant changes (in the manual).changelog/unreleased/that describes the changes for our users (see template).