Skip to content

Fix tty capture when started in background#5358

Merged
MichaelEischer merged 3 commits into
restic:masterfrom
MichaelEischer:fix-tty-capture-in-background
Sep 6, 2025
Merged

Fix tty capture when started in background#5358
MichaelEischer merged 3 commits into
restic:masterfrom
MichaelEischer:fix-tty-capture-in-background

Conversation

@MichaelEischer

@MichaelEischer MichaelEischer commented Apr 14, 2025

Copy link
Copy Markdown
Member

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 tests for all code changes.
  • [ ] I have added documentation for relevant changes (in the manual).
  • There's a new file in changelog/unreleased/ that describes the changes for our users (see template).
  • I'm done! This pull request is ready for review.

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.
@MichaelEischer MichaelEischer force-pushed the fix-tty-capture-in-background branch from 6103619 to b96fdc7 Compare September 6, 2025 17:51
@MichaelEischer MichaelEischer force-pushed the fix-tty-capture-in-background branch from b96fdc7 to 42f690d Compare September 6, 2025 18:50

@MichaelEischer MichaelEischer left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@MichaelEischer MichaelEischer merged commit 7f1ac57 into restic:master Sep 6, 2025
11 checks passed
@MichaelEischer MichaelEischer deleted the fix-tty-capture-in-background branch September 6, 2025 19:01
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.
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.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rclone backup cannot be run in background, fails with ENOTTY

1 participant