Skip to content

Commit

Permalink
disable jobserver on unix, if file descriptors are negative
Browse files Browse the repository at this point in the history
  • Loading branch information
belovdv committed Feb 1, 2024
1 parent d357534 commit eabe348
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct FromEnvError {
pub enum FromEnvErrorKind {
/// There is no environment variable that describes jobserver to inherit.
NoEnvVar,
/// There is no jobserver in the environment variable.
/// There is no jobserver in the environment variable, or it was disabled.
/// Variables associated with Make can be used for passing data other than jobserver info.
NoJobserver,
/// Cannot parse jobserver environment variable value, incorrect format.
Expand Down
10 changes: 8 additions & 2 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,19 @@ impl Client {
Some(w) => w,
None => return Ok(None),
};
let read = read
let read: c_int = read
.parse()
.map_err(|e| FromEnvErrorInner::CannotParse(format!("cannot parse `read` fd: {e}")))?;
let write = write
let write: c_int = write
.parse()
.map_err(|e| FromEnvErrorInner::CannotParse(format!("cannot parse `write` fd: {e}")))?;

// If either or both of these file descriptors are negative,
// it means the jobserver is disabled for this process.
if read < 0 || write < 0 {
return Err(FromEnvErrorInner::NoJobserver);
}

// Ok so we've got two integers that look like file descriptors, but
// for extra sanity checking let's see if they actually look like
// valid files and instances of a pipe if feature enabled before we
Expand Down

0 comments on commit eabe348

Please sign in to comment.