jobserver-rs
jobserver-rs copied to clipboard
Fix IO safety in `unix.rs`
As well as using BorrowedFd
as opposed to c_int
in more places, this PR fixes two related bugs:
- Unix
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). - Unix
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 of Client::mk
and Client::from_fds
as they don't appear to have any safety requirements.