mirror of
https://github.com/restic/restic.git
synced 2024-08-28 12:51:29 +02:00
![greatroar](/assets/img/avatar_default.png)
The previous implementation assumed that stdin was a terminal. It now checks the terminal's fd.
24 lines
620 B
Go
24 lines
620 B
Go
package termstatus
|
|
|
|
import (
|
|
"github.com/restic/restic/internal/debug"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
// IsProcessBackground reports whether the current process is running in the
|
|
// background. fd must be a file descriptor for the terminal.
|
|
func IsProcessBackground(fd uintptr) bool {
|
|
bg, err := isProcessBackground(fd)
|
|
if err != nil {
|
|
debug.Log("Can't check if we are in the background. Using default behaviour. Error: %s\n", err.Error())
|
|
return false
|
|
}
|
|
return bg
|
|
}
|
|
|
|
func isProcessBackground(fd uintptr) (bool, error) {
|
|
pid, err := unix.IoctlGetInt(int(fd), unix.TIOCGPGRP)
|
|
return pid != unix.Getpgrp(), err
|
|
}
|