From eabe3481820358b2d4c20f5e2542d48a2449af83 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 | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) 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..0a8e21d 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -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