Skip to content

Commit be32a7d

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

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/error.rs

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ pub enum FromEnvErrorKind {
1818
/// There is no jobserver in the environment variable.
1919
/// Variables associated with Make can be used for passing data other than jobserver info.
2020
NoJobserver,
21+
/// POSIX jobserver allows passing negative file descriptors to notify that
22+
/// jobserver is disabled for this process
23+
/// (See ["GNU male manual: POSIX Jobserver Interaction"](https://www.gnu.org/software/make/manual/make.html#POSIX-Jobserver)).
24+
NegativeFd,
2125
/// Cannot parse jobserver environment variable value, incorrect format.
2226
CannotParse,
2327
/// Cannot open path or name from the jobserver environment variable value.
@@ -36,6 +40,7 @@ impl FromEnvError {
3640
match self.inner {
3741
FromEnvErrorInner::NoEnvVar => FromEnvErrorKind::NoEnvVar,
3842
FromEnvErrorInner::NoJobserver => FromEnvErrorKind::NoJobserver,
43+
FromEnvErrorInner::NegativeFd(..) => FromEnvErrorKind::NegativeFd,
3944
FromEnvErrorInner::CannotParse(_) => FromEnvErrorKind::CannotParse,
4045
FromEnvErrorInner::CannotOpenPath(..) => FromEnvErrorKind::CannotOpenPath,
4146
FromEnvErrorInner::CannotOpenFd(..) => FromEnvErrorKind::CannotOpenFd,
@@ -50,6 +55,7 @@ impl std::fmt::Display for FromEnvError {
5055
match &self.inner {
5156
FromEnvErrorInner::NoEnvVar => write!(f, "there is no environment variable that describes jobserver to inherit"),
5257
FromEnvErrorInner::NoJobserver => write!(f, "there is no `--jobserver-fds=` or `--jobserver-auth=` in the environment variable"),
58+
FromEnvErrorInner::NegativeFd(read, write) => write!(f, "either or both passed file descriptors are negative: {read}, {write}"),
5359
FromEnvErrorInner::CannotParse(s) => write!(f, "cannot parse jobserver environment variable value: {s}"),
5460
FromEnvErrorInner::CannotOpenPath(s, err) => write!(f, "cannot open path or name {s} from the jobserver environment variable value: {err}"),
5561
FromEnvErrorInner::CannotOpenFd(fd, err) => write!(f, "cannot open file descriptor {fd} from the jobserver environment variable value: {err}"),
@@ -76,6 +82,7 @@ impl std::error::Error for FromEnvError {
7682
pub(crate) enum FromEnvErrorInner {
7783
NoEnvVar,
7884
NoJobserver,
85+
NegativeFd(RawFd, RawFd),
7986
CannotParse(String),
8087
CannotOpenPath(String, std::io::Error),
8188
CannotOpenFd(RawFd, std::io::Error),

src/unix.rs

+6
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ impl Client {
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::NegativeFd(read, write));
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)