Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process. ConflictsNo conflicts as of last run. |
8f26bcf to
c354037
Compare
| { | ||
| #ifndef WIN32 | ||
| return ::fopen(p.c_str(), mode); | ||
| const std::string safe_mode(std::string{mode} + "e"); |
There was a problem hiding this comment.
Is "e" available on all non-Windows systems?
There was a problem hiding this comment.
Could we keep the original e approach on Linux and handle macOS separately with open using O_CLOEXEC, followed by fdopen?
There was a problem hiding this comment.
I changed implementation into three cases
- linux
- windows
- posix
references/docs
-
linux
-
windows
-
UNIX
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
| #ifndef WIN32 | ||
| return ::fopen(p.c_str(), mode); | ||
| FILE *fp = ::fopen(p.c_str(), mode); | ||
| if(fp && fcntl(::fileno(fp), F_SETFD, FD_CLOEXEC) == -1) { |
There was a problem hiding this comment.
Unfortunately, the consecutive fopen and fcntl(..., FD_CLOEXEC) calls are not atomic, which is a race in a multithreaded process.
There was a problem hiding this comment.
Yes, you are right, I will try to find a solution on how I can make it safe under multi threaded processes.
|
I tested The compilation errors in |
bb15d68 to
9ebc30b
Compare
| flags |= read_write ? O_RDWR : O_RDONLY; | ||
| break; | ||
| case 'w': | ||
| flags |= (read_write ? ORDWR : O_WRONLY) | O_CREAT | O_TRUNC; |
There was a problem hiding this comment.
| flags |= (read_write ? ORDWR : O_WRONLY) | O_CREAT | O_TRUNC; | |
| flags |= (read_write ? O_RDWR : O_WRONLY) | O_CREAT | O_TRUNC; |
|
|
||
| // Match fopen's initial position for append. | ||
| if(mode[0] == 'a') { | ||
| (void)::lseek(fd, 0, SEED_END); |
There was a problem hiding this comment.
| (void)::lseek(fd, 0, SEED_END); | |
| (void)::lseek(fd, 0, SEEK_END); |
f2eac03 to
30c974f
Compare
|
Thanks @ValeraFinebits. I fixed the typos. Let me know what you think. |
Could we also add |
e423eb6 to
55f35a2
Compare
|
Added the missing include! |
winterrdog
left a comment
There was a problem hiding this comment.
could you please squash your commits into two: one for the unit test and one for the fix ?
|
Tested on Windows at |
0c9ab56 to
6a1ff77
Compare
I performed a squash to clean up the git history, as asked. |
6a1ff77 to
17ea8dd
Compare
|
seems like this fixes #36668. you can add |

Fixes #36668
Use the 'e' mode on POSIX to set close-on-exec and the 'N' mode on windows to prevent file handle inheritance by child processes.
This PR is still in WIP... until I add some test cases and verify that it works on Windows and Mac. I've only tested it on Linux (OpenSUSE Tumbleweed)