From 1ea961f3da2088891a253e46e79458b403aa1d06 Mon Sep 17 00:00:00 2001 From: belovdv <70999565+belovdv@users.noreply.github.com> Date: Thu, 1 Feb 2024 21:47:10 +0300 Subject: [PATCH] disable jobserver on unix, if file descriptors are negative --- src/error.rs | 2 +- src/unix.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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