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