From 09d284498109b847da0da1e2c5f883268a7f2d46 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Thu, 21 Aug 2025 21:59:07 +0900 Subject: 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 --- container/syscall.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'container/syscall.go') 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. -- cgit v1.3.1