backend,termstatus: Unify foreground/background detection

PR #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 commit is contained in:
greatroar
2025-09-07 12:57:01 +02:00
parent 42f690dbab
commit 1ed93bd54d
12 changed files with 89 additions and 76 deletions

View File

@@ -0,0 +1,22 @@
//go:build unix
package termstatus
import (
"os"
"testing"
rtest "github.com/restic/restic/internal/test"
)
func TestIsProcessBackground(t *testing.T) {
tty, err := os.Open("/dev/tty")
if err != nil {
t.Skipf("can't open terminal: %v", err)
}
_, err = isProcessBackground(int(tty.Fd()))
rtest.OK(t, err)
_ = tty.Close()
}