diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-03-17 14:15:16 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-03-17 14:15:16 +0900 |
| commit | d1fc1a3db73e61ef85667f835005659dc7c1cb1f (patch) | |
| tree | 14496375da04771a2857450718e2301f5c8e222f | |
| parent | 1c2d5f6b57af2bb05759647d6e6ff1aa8ff47de0 (diff) | |
ext: wrap close_range syscall
This is useful for container when called with CLOSE_RANGE_CLOEXEC.
Signed-off-by: Ophestra <cat@gensokyo.uk>
| -rw-r--r-- | ext/syscall.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/ext/syscall.go b/ext/syscall.go index e6d9e9f2..cee35cc5 100644 --- a/ext/syscall.go +++ b/ext/syscall.go @@ -7,6 +7,26 @@ import ( "syscall" ) +// include/uapi/linux/close_range.h +const ( + CLOSE_RANGE_UNSHARE = 1 << (iota + 1) + CLOSE_RANGE_CLOEXEC +) + +// CloseRange close all file descriptors in a given range. +func CloseRange(first, last Uint, flags Int) error { + _, _, errno := syscall.Syscall( + SYS_CLOSE_RANGE, + uintptr(first), + uintptr(last), + uintptr(flags), + ) + if errno != 0 { + return errno + } + return nil +} + // SchedPolicy denotes a scheduling policy defined in include/uapi/linux/sched.h. type SchedPolicy int |
