diff --git a/src/error.rs b/src/error.rs index 8b3fe74..6b20f29 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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. diff --git a/src/unix.rs b/src/unix.rs index ee1e923..2589f3e 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -130,6 +130,12 @@ impl Client { .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