RFC: Use pipe2 and O_CLOEXEC to check if exec succeeds after fork #8126
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The problem with issue #8002 and #6914 is that the
exec()
call fails afterfork()
. After the failure, the parent process does not know about the failure. The parent process hangs during thewaitpid()
call.I tried to use
pipe2
andO_CLOEXEC
to check in the parent process ifexec()
succeeds afterfork()
.This PR fixes the problem with `pandoc'. I tested this on the latest master revision.
$ rustdoc --output-dir doc btree.rs rust: task failed at 'failure in execvp: errno=No such file or directory', /home/smvv/work/rust/rust/src/libstd/run.rs:689
However, there is still some work to do before it can be merged:
O_CLOEXEC
value. This should be derived from the C header file. What would be the approach to derive this properly?O_CLOEXEC
is defined in: http://pubs.opengroup.org/onlinepubs/9699919799/functions/open.htmlIt is also possible to use
fcntl()
to setFD_CLOEXEC
, but thefcntl
defined in libc.rs takes only two arguments instead of three.pipe2
, which is not defined in libc.rs. Shouldpipe2
be added to libc.rs, or what would be the way to proceed here?false
being used in the FILE reader and writer constructor. I was not sure if it should usefalse
ortrue
.I read that
pipe2
is Linux-specific, but perhaps it is also available on other Unix platforms?