Skip to content

Commit 7999964

Browse files
authored
Merge pull request #1 from stapelberg/cloexec
reader: set file descriptor CloseOnExec
2 parents 0e9837f + 40d619f commit 7999964

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

reader.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ func NewReader() (io.ReadCloser, error) {
5656
syscall.SOCK_RAW,
5757
NETLINK_KOBJECT_UEVENT,
5858
)
59-
6059
if err != nil {
6160
return nil, err
6261
}
6362

63+
// os/exec does not close existing file descriptors by convention as per
64+
// https://github.com/golang/go/blob/release-branch.go1.14/src/syscall/exec_linux.go#L483
65+
// so explicitly mark this file descriptor as close-on-exec to avoid leaking
66+
// it to child processes accidentally.
67+
syscall.CloseOnExec(fd)
68+
6469
nl := syscall.SockaddrNetlink{
6570
Family: syscall.AF_NETLINK,
6671
Pid: uint32(os.Getpid()),

0 commit comments

Comments
 (0)