terminal: unexport tcgetpgrp, tcsetpgrp and getpgrp

This commit is contained in:
Michael Eischer
2025-09-08 10:55:58 +02:00
parent e7890d7b81
commit b71b77fa77
8 changed files with 12 additions and 12 deletions

View File

@@ -16,9 +16,9 @@ func IsProcessBackground(fd uintptr) bool {
}
func isProcessBackground(fd int) (bg bool, err error) {
pgid, err := Tcgetpgrp(fd)
pgid, err := tcgetpgrp(fd)
if err != nil {
return false, err
}
return pgid != Getpgrp(), nil
return pgid != getpgrp(), nil
}

View File

@@ -28,13 +28,13 @@ func startForeground(cmd *exec.Cmd) (bg func() error, err error) {
}
// only move child process to foreground if restic is in the foreground
prev, err := Tcgetpgrp(int(tty.Fd()))
prev, err := tcgetpgrp(int(tty.Fd()))
if err != nil {
_ = tty.Close()
return nil, err
}
self := Getpgrp()
self := getpgrp()
if prev != self {
debug.Log("restic is not controlling the tty; err = %v", err)
if err := tty.Close(); err != nil {
@@ -55,7 +55,7 @@ func startForeground(cmd *exec.Cmd) (bg func() error, err error) {
}
// move the command's process group into the foreground
err = Tcsetpgrp(int(tty.Fd()), cmd.Process.Pid)
err = tcsetpgrp(int(tty.Fd()), cmd.Process.Pid)
if err != nil {
_ = tty.Close()
return nil, err
@@ -66,7 +66,7 @@ func startForeground(cmd *exec.Cmd) (bg func() error, err error) {
signal.Reset(unix.SIGTTOU)
// reset the foreground process group
err = Tcsetpgrp(int(tty.Fd()), prev)
err = tcsetpgrp(int(tty.Fd()), prev)
if err != nil {
_ = tty.Close()
return err

View File

@@ -2,7 +2,7 @@ package terminal
import "golang.org/x/sys/unix"
func Getpgrp() int {
func getpgrp() int {
pid, _ := unix.Getpgrp()
return pid
}

View File

@@ -4,4 +4,4 @@ package terminal
import "golang.org/x/sys/unix"
func Getpgrp() int { return unix.Getpgrp() }
func getpgrp() int { return unix.Getpgrp() }

View File

@@ -2,7 +2,7 @@ package terminal
import "golang.org/x/sys/unix"
func Tcgetpgrp(ttyfd int) (int, error) {
func tcgetpgrp(ttyfd int) (int, error) {
// We need to use IoctlGetUint32 here, because pid_t is 32-bit even on
// 64-bit Linux. IoctlGetInt doesn't work on big-endian platforms:
// https://github.com/golang/go/issues/45585

View File

@@ -4,6 +4,6 @@ package terminal
import "golang.org/x/sys/unix"
func Tcgetpgrp(ttyfd int) (int, error) {
func tcgetpgrp(ttyfd int) (int, error) {
return unix.IoctlGetInt(ttyfd, unix.TIOCGPGRP)
}

View File

@@ -2,7 +2,7 @@ package terminal
import "golang.org/x/sys/unix"
func Tcsetpgrp(fd int, pid int) error {
func tcsetpgrp(fd int, pid int) error {
// The second argument to IoctlSetPointerInt has type int on AIX,
// but the constant overflows 64-bit int, hence the two-step cast.
req := uint(unix.TIOCSPGRP)

View File

@@ -4,6 +4,6 @@ package terminal
import "golang.org/x/sys/unix"
func Tcsetpgrp(fd int, pid int) error {
func tcsetpgrp(fd int, pid int) error {
return unix.IoctlSetPointerInt(fd, unix.TIOCSPGRP, pid)
}