Open beetrees opened 1 month ago
So the behaviour of spawning a configured command after the (not-inherited) jobserver Client
is dropped differs:
(I've also fixed an unused import warning in the unix.rs
tests on Linux)
* On Windows: The command spawns successfully but attempting to inherit the jobserver will error.
That's unfortunate since windows don't have pre_exec
.
I have a fork of jobserver, which I workaround this issue by forcing user to pass in a closure and spawn the process there Client::configure_and_run
:
pub fn configure_and_run<Cmd, F, R>(&self, cmd: Cmd, f: F) -> Result<R>
where
Cmd: Command,
F: FnOnce(&mut Cmd) -> Result<R>;
* On Unix after this PR: The command spawns successfully and the jobserver is inheritable and usable.
I was planning to open a PR to optimize away the pre_exec
, if the Client
is created from_env
, since the original fds inherited from the environment should be valid.
Though that'd mean the jobserver would be inherited without Client::configure
As well as using
BorrowedFd
as opposed toc_int
in more places, this PR fixes two related bugs:Client::configure()
wouldn't ensure the file descriptors passed toCommand::configure
remained valid until the command was actually spawned. This meant that if theClient
was dropped before theCommand
was spawned, theset_cloexec
call could end up hitting an unrelated file descriptor (which the spawned process would then treat as a jobserver).string_arg
uses the FDs fromClientCreationArg::Fds
to put in the environment variables, but before this PRClient::configure
would use the FDs fromself.read
/self.write
instead. This would result in the wrong FDs getting passed toset_cloexec
. This was basically harmless (apart from having the use-after-drop problem) as the only time the two sets of FDs differ is when the jobserver has been inherited from the environment, in which case the FDs are going to be not-CLOEXEC anyway.I've also removed the
unsafe
from the definitions ofClient::mk
andClient::from_fds
as they don't appear to have any safety requirements.