mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-10-31 05:40:42 +00:00 
			
		
		
		
	godep restore pushd $GOPATH/src/github.com/appc/spec git co master popd go get go4.org/errorutil rm -rf Godeps godep save ./... git add vendor git add -f $(git ls-files --other vendor/) git co -- Godeps/LICENSES Godeps/.license_file_state Godeps/OWNERS
		
			
				
	
	
		
			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
 | |
| }
 |