2018-04-28 13:24:36 +00:00
|
|
|
package termstatus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/restic/restic/internal/debug"
|
|
|
|
|
2020-10-13 10:56:23 +00:00
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
2018-04-28 13:24:36 +00:00
|
|
|
|
2020-10-13 10:56:23 +00:00
|
|
|
// 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 {
|
2018-04-28 13:24:36 +00:00
|
|
|
debug.Log("Can't check if we are in the background. Using default behaviour. Error: %s\n", err.Error())
|
|
|
|
return false
|
|
|
|
}
|
2020-10-13 10:56:23 +00:00
|
|
|
return bg
|
|
|
|
}
|
2018-04-28 13:24:36 +00:00
|
|
|
|
2020-10-13 10:56:23 +00:00
|
|
|
func isProcessBackground(fd uintptr) (bool, error) {
|
|
|
|
pid, err := unix.IoctlGetInt(int(fd), unix.TIOCGPGRP)
|
|
|
|
return pid != unix.Getpgrp(), err
|
2018-04-28 13:24:36 +00:00
|
|
|
}
|