Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also create epoll and pipe fds with close-on-exec (#155) #219

Merged
merged 2 commits into from Mar 12, 2019

Conversation

JohannesEbke
Copy link
Contributor

@JohannesEbke JohannesEbke commented Sep 1, 2017

  • Add the unix.O_CLOEXEC to the Pipe2 call
  • Add unix.EPOLL_CLOEXEC to the Epoll call

I've signed the CLA.

What does this pull request do?

When creating a fsnotify.NewWatcher(), four file descriptors are opened: One for inotify, one for epoll and two for the two ends of a pipe. Only the inotify one has CLOEXEC set. This PR adds the CLOEXEC flag to all four file descriptors, preventing a leak in cases where execve is used e.g. to reload an executable on code change.

Where should the reviewer start?

I read the manpages of pipe2 and epoll_create2 to get an idea of the flags.

How should this be manually tested?

In a simple program which just opens a NewWatcher, does a syscall.Exec, and sleeps, the difference in the number of open file descriptors is visible in /proc//fd/

@pwaller
Copy link

pwaller commented Sep 1, 2017

I can confirm that this fixes a problem I see, too. Bit surprised this wasn't fixed in #178.

pwaller
pwaller previously approved these changes Sep 1, 2017
cpuguy83
cpuguy83 previously approved these changes Nov 9, 2017
Copy link
Contributor

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sipsma
Copy link

sipsma commented Sep 26, 2018

Is there anything preventing this fix from being merged (other than needing a re-base on master)? This PR is from 2017 but the issue of these FDs leaking across execs is still present today.

@JohannesEbke
Copy link
Contributor Author

I've rebased the patch onto current master, everything still seems to work fine. It would be good to have it merged.

pwaller
pwaller previously approved these changes Oct 14, 2018
cpuguy83
cpuguy83 previously approved these changes Feb 28, 2019
Copy link
Contributor

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

* Add the unix.O_CLOEXEC to the Pipe2 call
* Add unix.EPOLL_CLOEXEC to the Epoll call
@cpuguy83 cpuguy83 dismissed stale reviews from pwaller and themself via 92451cc February 28, 2019 17:27
@cpuguy83
Copy link
Contributor

I just force-pushed a no-op change to try and re-trigger the CI.

Copy link
Contributor

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cpuguy83
Copy link
Contributor

ugh 😞 CI issues due to golint not working on go1.8 anymore.
Also appveyor/branch is not doing anything need to look into that as well. Can't merge until these are cleared up.

@cpuguy83
Copy link
Contributor

Finally, all green. Merging. Thanks! 🎉 ❤️

@cpuguy83 cpuguy83 merged commit 1485a34 into fsnotify:master Mar 12, 2019
@pwaller
Copy link

pwaller commented Mar 12, 2019

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants