diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-08-21 21:59:07 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-08-22 19:27:31 +0900 |
| commit | 09d284498109b847da0da1e2c5f883268a7f2d46 (patch) | |
| tree | 3784dee4b4e4ec97a95cb222c70d05463ae640ef /container/syscall.go | |
| parent | d500d6e55917e12a3f98b39cf0d29b6c96de9667 (diff) | |
container/init: wrap syscall helper functions
This allows tests to stub all kernel behaviour, enabling measurement of all function call arguments and error injection.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'container/syscall.go')
| -rw-r--r-- | container/syscall.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/container/syscall.go b/container/syscall.go index 20ac068d..edb6e7e3 100644 --- a/container/syscall.go +++ b/container/syscall.go @@ -2,6 +2,7 @@ package container import ( "syscall" + "unsafe" ) // SetPtracer allows processes to ptrace(2) the calling process. @@ -37,6 +38,18 @@ func SetNoNewPrivs() error { return errno } +// Isatty tests whether a file descriptor refers to a terminal. +func Isatty(fd int) bool { + var buf [8]byte + r, _, _ := syscall.Syscall( + syscall.SYS_IOCTL, + uintptr(fd), + syscall.TIOCGWINSZ, + uintptr(unsafe.Pointer(&buf[0])), + ) + return r == 0 +} + // IgnoringEINTR makes a function call and repeats it if it returns an // EINTR error. This appears to be required even though we install all // signal handlers with SA_RESTART: see #22838, #38033, #38836, #40846. |
