Skip to content

Commit

Permalink
Merge pull request #1 from stapelberg/cloexec
Browse files Browse the repository at this point in the history
reader: set file descriptor CloseOnExec
  • Loading branch information
s-urbaniak authored Aug 11, 2021
2 parents 0e9837f + 40d619f commit 7999964
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@ func NewReader() (io.ReadCloser, error) {
syscall.SOCK_RAW,
NETLINK_KOBJECT_UEVENT,
)

if err != nil {
return nil, err
}

// os/exec does not close existing file descriptors by convention as per
// https://github.com/golang/go/blob/release-branch.go1.14/src/syscall/exec_linux.go#L483
// so explicitly mark this file descriptor as close-on-exec to avoid leaking
// it to child processes accidentally.
syscall.CloseOnExec(fd)

nl := syscall.SockaddrNetlink{
Family: syscall.AF_NETLINK,
Pid: uint32(os.Getpid()),
Expand Down

0 comments on commit 7999964

Please sign in to comment.