Skip to content

Commit 35a28ad

Browse files
authored
Merge pull request #4596 from evanphx/evanphx/b-close-range
utils: Handle close_range more gracefully
2 parents 3cfcb69 + 33315a0 commit 35a28ad

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

libcontainer/utils/utils_unix.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,14 @@ func fdRangeFrom(minFd int, fn fdFunc) error {
102102
func CloseExecFrom(minFd int) error {
103103
// Use close_range(CLOSE_RANGE_CLOEXEC) if possible.
104104
if haveCloseRangeCloexec() {
105-
err := unix.CloseRange(uint(minFd), math.MaxUint, unix.CLOSE_RANGE_CLOEXEC)
106-
return os.NewSyscallError("close_range", err)
105+
err := unix.CloseRange(uint(minFd), math.MaxInt32, unix.CLOSE_RANGE_CLOEXEC)
106+
if err == nil {
107+
return nil
108+
}
109+
110+
logrus.Debugf("close_range failed, closing range one at a time (error: %v)", err)
111+
112+
// If close_range fails, we fall back to the standard loop.
107113
}
108114
// Otherwise, fall back to the standard loop.
109115
return fdRangeFrom(minFd, unix.CloseOnExec)

0 commit comments

Comments
 (0)