libnative: process spawning should not close inherited file descriptors #16407
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.
When creating a subprocess via
std::io::process::Command
it is possible to allow the child to inherit certain open file descriptors. When the process is spawned (innative::io::process
), however, the file descriptor is unconditionally closed. This is an error for the following reasons:native::io::file::open
, which returns aFileDesc
on success. Since there is no public interface for specifying that the internal fd should NOT be cleaned up, theFileDesc
structure will attempt to close the fd when it is destroyed. Since spawning closes the file descriptor, when theFileDesc
structure mentioned above goes out of scope, it will print an error message to screen. This behavior may be unwanted, and there is no way to prevent it without leaking theFileDesc
structure (which is not a good alternative).FileDesc
structure returned bynative::io::file::open
before said structure goes out of scope. Thus when it does, it will incorrectly succeed at closing the file, causing unexpected errors for the task that opened the file.Thus the caller must be solely responsible for cleaning up (or leaking if so desired) any opened file descriptors, especially since the
std::io::process:Command
interface for adding inherited file descriptors involves using a literal descriptor and not a wrapper likeFileDesc
.