-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust SetupUser to Fchown all open file descriptors so they're appro…
…priately usable by the forked process
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"strconv" | ||
"syscall" | ||
) | ||
|
||
func chownFds(uid, gid 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 err = syscall.Fchown(fd, uid, gid); err != nil { | ||
// "bad file descriptor" probably just means it no longer exists since we did "readdir", so ignore that | ||
if err != syscall.EBADF { | ||
return err | ||
} | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters