Skip to content

Commit eabe348

Browse files
committed
disable jobserver on unix, if file descriptors are negative
1 parent d357534 commit eabe348

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct FromEnvError {
1515
pub enum FromEnvErrorKind {
1616
/// There is no environment variable that describes jobserver to inherit.
1717
NoEnvVar,
18-
/// There is no jobserver in the environment variable.
18+
/// There is no jobserver in the environment variable, or it was disabled.
1919
/// Variables associated with Make can be used for passing data other than jobserver info.
2020
NoJobserver,
2121
/// Cannot parse jobserver environment variable value, incorrect format.

src/unix.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,19 @@ impl Client {
123123
Some(w) => w,
124124
None => return Ok(None),
125125
};
126-
let read = read
126+
let read: c_int = read
127127
.parse()
128128
.map_err(|e| FromEnvErrorInner::CannotParse(format!("cannot parse `read` fd: {e}")))?;
129-
let write = write
129+
let write: c_int = write
130130
.parse()
131131
.map_err(|e| FromEnvErrorInner::CannotParse(format!("cannot parse `write` fd: {e}")))?;
132132

133+
// If either or both of these file descriptors are negative,
134+
// it means the jobserver is disabled for this process.
135+
if read < 0 || write < 0 {
136+
return Err(FromEnvErrorInner::NoJobserver);
137+
}
138+
133139
// Ok so we've got two integers that look like file descriptors, but
134140
// for extra sanity checking let's see if they actually look like
135141
// valid files and instances of a pipe if feature enabled before we

0 commit comments

Comments
 (0)