-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Add O_CLOEXEC to open calls. #624
Conversation
This change seems reasonable to me. Can you please add tests? |
5d92beb
to
18136e9
Compare
Added a test as requested. Sorry about being lazy about it before. Before:
After:
|
Hm, seems that while it passes fine for |
18136e9
to
91f3f44
Compare
Fixed the error. It does seem somewhat concerning that travis considers the build to have passed even if a unit test fails like that, however. |
91f3f44
to
ece748c
Compare
Sorry for the noise earlier. Been spoiled by for Go too long I guess. The PR is now stable. Please take a look and let me know if further changes are desired. |
Are there any further changes you'd like to see on this PR? |
Rebased to master to resolve conflicts. |
@adam-azarchs Thank you for your work, and sorry for the slow response! This looks good, and I'll look at adopting it next time I have a chunk of time for LevelDB. I may try to use CMake for the O_CLOEXEC feature detection, but everything else looks good to me. |
This prevents file descriptors from leaking to child processes. When compiled for older (pre-2.6.23) kernels which lack support for O_CLOEXEC there is no change in behavior. With newer kernels, child processes will no longer inherit leveldb's file handles, which reduces the changes of accidentally corrupting the database. Fixes google#623
I've rebased to master and modified things to use cmake for the feature detection. Admittedly I don't use cmake often so I'm cargo culting that bit, but it seems to work. |
@adam-azarchs Thank you very much for the revisions! I expect us to get the Windows CI green over the next couple of days. I plan to look into this PR right after the CI becomes green. |
This seems to have broken the travis build on mac. I don't have a mac to test on so it's a bit difficult for me to resolve this. It looks like those errors were being inadvertently ignored by travis, previously. I'm guessing the issue is that macs don't have a |
Macs don't have procfs, indeed. So, no The bigger question is -- why did this PR pass CI in the first place. I think it's fair to say we were all relying on the Travis results here. I'm trying to see if I can figure out a quick fix for this issue. |
(continued from the previous comment, I accidentally hit Enter) https://travis-ci.org/google/leveldb/jobs/497244562#L2789 shows that the test failed on Mac, as expected, but the failure didn't bubble up to the Travis status. Good news: the travis config used by the PR had a bug that was fixed in 808e59e So, I'll assume that the CI configuration problem was fixed, and we only have to deal with the broken test. This is a good example of the importance of getting that CI config right 😄 |
@@ -15,6 +15,11 @@ | |||
#cmakedefine01 HAVE_FULLFSYNC | |||
#endif // !defined(HAVE_FULLFSYNC) | |||
|
|||
// Define to 1 if you have a definition for O_CLOEXEC in <fcntl.h>. | |||
#if !defined(HAVE_O_CLOEXEC) | |||
#cmakedefine01 HAVE_O_CLOEXEC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#cmakedefine01
always defines the HAVE_O_CLOEXEC
macro:
Input file lines of the form
#cmakedefine01 VAR
will be replaced with either#define VAR 1
or#define VAR 0
similarly.
Therefore, it looks wrong to use #if defined(HAVE_O_CLOEXEC)
in the code:
Line 52 in 75fceae
#if defined(HAVE_O_CLOEXEC) |
leveldb/util/env_posix_test.cc
Line 62 in 75fceae
#if defined(HAVE_O_CLOEXEC) |
UPDATE: The latter has been fixed in 27dc99f.
UPDATE 2: Have just noticed that a fix has been suggested in #1028.
* Use EXPECT_DOUBLE_EQ when comparing doubles in tests. Fixes google#623 * disable 'float-equal' warning
1eeb1cb fix macro HAVE_O_CLOEXEC when O_CLOEXEC not found (emptyx.wong) Pull request description: google#624 was [buggy](google#624 (comment)). One bug was fixed in google@27dc99f. google#1028 addresses another one. This PR cherry-picks from google#1028, and is an alternative to bitcoin/bitcoin#25463. ACKs for top commit: fanquake: ACK 1eeb1cb - I think the likelyhood of this being merged upstream is quite low, so that shouldn't be a blocker in us merging it here. jarolrod: ACK 1eeb1cb Tree-SHA512: 67a4e05372e71ba12abf84c633284afbaa54852b616fc86939231e72d5054d9f7973caad5a18944a84f0fdf924f404a35b50287d53a704c7d320f04068800ebf
This prevents file descriptors from leaking to child processes.
When compiled for older (pre-2.6.23) kernels which lack support for
O_CLOEXEC
, there is no change in behavior. With newer kernels, child processes will no longer inherit leveldb's file handles, which reduces the changes of accidentally corrupting the database.Fixes #623