mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-04 18:51:17 +00:00
This caused a dependency chain reaction (sigh):
* All the k8s packages had to be fetched again. This in turn required:
* Pining github.com/docker/docker/pkg/parsers to
0f5c9d301b9b1cca66b3ea0f9dec3b5317d3686d to cirvumvent
https://github.com/kubernetes/kubernetes/issues/18774
* Update github.com/juju/ratelimit
* Make probe/kubernetes/client.go comply with API changes.
34 lines
728 B
Go
34 lines
728 B
Go
// +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
|
|
}
|