pipe2() is better to set O_CLOEXEC flag to avoid file descriptor leakage.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
clang-tools-extra/clang-tidy/android/CloexecPipe2Check.h | ||
---|---|---|
1 ↗ | (On Diff #199951) | Please extend to 80 characters. Same in source file. |
clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe2.rst | ||
---|---|---|
19 ↗ | (On Diff #200066) | Shouldn't this be "O_NONBLOCK | O_CLOEXEC" instead? Why drop the O_NONBLOCK? |
clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe2.rst | ||
---|---|---|
19 ↗ | (On Diff #200066) | Good catch! |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp | ||
---|---|---|
52 ↗ | (On Diff #200066) | I'm not all that familiar with writing clang-tidy-specific tests, but should these tests here denote that a diagnostic should NOT be issued? That is usually the convention in regular Clang tests, so I assume the test runner here should be equally supportive of ensuring that the contents passed through without any other diagnostics related to pipe2 and/or O_CLOEXEC. |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp | ||
---|---|---|
52 ↗ | (On Diff #200066) | That makes sense, and I have seem tests for similar checks with (e.g. android-cloexec-open) and without (e.g. android-cloexec-accep4 and android-cloexec-socket) additional CHECK-MESSAGES-NOT check. But based on the Testing Checks section of https://clang.llvm.org/extra/clang-tidy/Contributing.html, it seems typically CHECK-MASSAGES and CHECK-FIXES are sufficient for clang-tidy checks. Please let me know what you think. |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp | ||
---|---|---|
52 ↗ | (On Diff #200066) | If you look in test/clang-tidy/android-cloexec-creat.cpp, you will see that there are "CHECK-MESSAGES-NOT" checks that ensure the diagnostic is not issued in correct cases. You can put the checks on lines 39, 58, and 67, which will ensure that there are no additional diagnostics being generated. |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp | ||
---|---|---|
52 ↗ | (On Diff #200066) | Sounds good! Thanks for the reference. |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp | ||
---|---|---|
48 ↗ | (On Diff #202030) | Much like line 39 (which covers both lines 37 and 38), you can delete this CHECK-MESSAGES-NOT. The one on line 50 will cover both of these. |
64 ↗ | (On Diff #202030) | Only keep this CHECK-MESSAGES-NOT line. |
75 ↗ | (On Diff #202030) | Only keep this CHECK-MESSAGES-NOT line. |
Everything looks great. Thanks for adding these improvements. While it's probably safe to commit this, perhaps you should give it 24 hours in case some of the other clang-tidy folks have different style or testing concerns.
LGTM.
clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp | ||
---|---|---|
60 ↗ | (On Diff #202072) | no need to verify it explicitly. |
clang-tools-extra/docs/clang-tidy/checks/android-cloexec-pipe2.rst | ||
---|---|---|
6 ↗ | (On Diff #202072) | This checks ensures that pipe2() is called with the O_CLOEXEC flag. This flag helps to avoid accidentally leaking file descriptors to child processes. |
17 ↗ | (On Diff #202072) | "Suggested replacement" Also use a separate code block for the replacement. |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp | ||
20 ↗ | (On Diff #202072) | Same comment about the message as in D61967 -- the message should briefly explain why the user should make this change. Users tend to ignore warnings they don't understand. "pipe2 should be called with O_CLOEXEC to avoid leaking file descriptors to child processes" |
27 ↗ | (On Diff #202072) | Please give the tests informative names instead of a, f, g etc. |
54 ↗ | (On Diff #202072) | How is e different from a? |
48 ↗ | (On Diff #202030) | Not done -- you don't need any CHECK-MESSAGES-NOT at all. |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp | ||
---|---|---|
54 ↗ | (On Diff #202072) | e uses O_CLOEXEC properly with pipe2() and makes sure that we don't issue additional diagnostics/fixes that are unnecessary. |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp | ||
---|---|---|
54 ↗ | (On Diff #202072) | Thanks -- I see it now. I think a descriptive test name would help here. |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp | ||
---|---|---|
20 ↗ | (On Diff #202072) | It appeared to me that there was no easy way to change the warning message due to the way insertMacroFlag is implemented (called in CloexecPipe2Check::check(...) to add O_CLOEXEC flag when necessary). The function always issue a warning in the format of "%0 should use %1 where possible". So unless we parameterize the warning string (which could be solved by a different code change), we might end up implementing a similar function with different warning message, which creates extra work if we need to modify insertMacroFlag in the future. I am new to Clang so please let me know if there is a better way to udpate the warning message. |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp | ||
---|---|---|
17 ↗ | (On Diff #202832) | warning1, warning2 is better than a and b, but we can do even better. warningForPipeCall Similarly in the rest of the patch. |
20 ↗ | (On Diff #202072) | I don't see an issue with parameterizing insertMacroFlag -- the current message that it produces is not descriptive enough anyway, users tend to ignore such messages. |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp | ||
---|---|---|
20 ↗ | (On Diff #202072) | I agree. But my point is insertMacroFlag is used by several other checks. Shouldn't we parameterize the warning message and update these checks together in a separate change? |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp | ||
---|---|---|
20 ↗ | (On Diff #202072) | SGTM! |
clang-tools-extra/test/clang-tidy/android-cloexec-pipe2.cpp | ||
---|---|---|
17 ↗ | (On Diff #202832) | Sounds good. I have updated the function names, although I feel the "ForPipeCall" part is already implied in the test so I did not include it to keep the names shorter. Let me know if you think it is better to have it included. |