aboutsummaryrefslogtreecommitdiffhomepage
path: root/ext
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-03-17 14:15:16 +0900
committerOphestra <cat@gensokyo.uk>2026-03-17 14:15:16 +0900
commitd1fc1a3db73e61ef85667f835005659dc7c1cb1f (patch)
tree14496375da04771a2857450718e2301f5c8e222f /ext
parent1c2d5f6b57af2bb05759647d6e6ff1aa8ff47de0 (diff)
ext: wrap close_range syscall
This is useful for container when called with CLOSE_RANGE_CLOEXEC. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'ext')
-rw-r--r--ext/syscall.go20
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