Commit 5390457
compat/mingw: handle O_CLOEXEC in
Our MinGW emulation of the open(3p) syscall uses one of three different
code paths depending on the flags passed by the caller. Ideally, we
would just use `_wopen()` for all of these directly and instead rely on
the Windows SDK to implement the logic for us. But unfortunately, this
interface does not allow us to set the `FILE_SHARING_*` flags, which we
need to have control over to implement POSIX semantics.
One of the code paths is for opening existing files, where we end up
calling `mingw_open_existing()`. While this code path is executed when
the user passes `O_NOINHERIT`, we don't know to handle `O_CLOEXEC` yet,
which causes a couple of code paths that use the flag to not use the
emulation. The consequence is that those code paths do not support POSIX
semantics because we don't know to set the sharing mode correctly.
Supporting `O_CLOEXEC` is quite trivial: we don't have to do anything,
as Windows already closes the file handle by default when exec'ing into
another process. This is further supported by the fact that we indeed
define `O_CLOEXEC` as `O_NOINHERIT` in case the former isn't defined in
"compat/mingw.h".
Adapt the code so that we know to handle `O_CLOEXEC` in case it has a
different definition than `O_NOINHERIT` to improve our POSIX semantics
handling.
Signed-off-by: Patrick Steinhardt <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>mingw_open_existing()
1 parent 4b68faf commit 5390457
1 file changed
+2
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
560 | 560 | | |
561 | 561 | | |
562 | 562 | | |
563 | | - | |
| 563 | + | |
564 | 564 | | |
565 | 565 | | |
566 | 566 | | |
| |||
632 | 632 | | |
633 | 633 | | |
634 | 634 | | |
635 | | - | |
| 635 | + | |
636 | 636 | | |
637 | 637 | | |
638 | 638 | | |
| |||
0 commit comments