aboutsummaryrefslogtreecommitdiffstats
path: root/src/kube2msb/vendor/github.com/opencontainers/runc/libcontainer/utils/utils_unix.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/kube2msb/vendor/github.com/opencontainers/runc/libcontainer/utils/utils_unix.go')
-rw-r--r--src/kube2msb/vendor/github.com/opencontainers/runc/libcontainer/utils/utils_unix.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/kube2msb/vendor/github.com/opencontainers/runc/libcontainer/utils/utils_unix.go b/src/kube2msb/vendor/github.com/opencontainers/runc/libcontainer/utils/utils_unix.go
new file mode 100644
index 0000000..408918f
--- /dev/null
+++ b/src/kube2msb/vendor/github.com/opencontainers/runc/libcontainer/utils/utils_unix.go
@@ -0,0 +1,33 @@
+// +build !windows
+
+package utils
+
+import (
+ "io/ioutil"
+ "strconv"
+ "syscall"
+)
+
+func CloseExecFrom(minFd int) error {
+ fdList, err := ioutil.ReadDir("/proc/self/fd")
+ if err != nil {
+ return err
+ }
+ for _, fi := range fdList {
+ fd, err := strconv.Atoi(fi.Name())
+ if err != nil {
+ // ignore non-numeric file names
+ continue
+ }
+
+ if fd < minFd {
+ // ignore descriptors lower than our specified minimum
+ continue
+ }
+
+ // intentionally ignore errors from syscall.CloseOnExec
+ syscall.CloseOnExec(fd)
+ // the cases where this might fail are basically file descriptors that have already been closed (including and especially the one that was created when ioutil.ReadDir did the "opendir" syscall)
+ }
+ return nil
+}