Skip to content

Commit 72d8e4c

Browse files
committed
[temp] switch 'check_pipe' to runtime option
1 parent 65bf01a commit 72d8e4c

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
[package]
23
name = "jobserver"
34
version = "0.1.26"
@@ -14,9 +15,6 @@ edition = "2018"
1415
[target.'cfg(unix)'.dependencies]
1516
libc = "0.2.50"
1617

17-
[features]
18-
do_not_check_pipe = []
19-
2018
[dev-dependencies]
2119
futures = "0.1"
2220
num_cpus = "1.0"
@@ -45,4 +43,4 @@ harness = false
4543

4644
[[test]]
4745
name = "helper"
48-
path = "tests/helper.rs"
46+
path = "tests/helper.rs"

src/lib.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ impl Client {
250250
/// with `CLOEXEC` so they're not automatically inherited by spawned
251251
/// children.
252252
///
253-
/// There is a feature to configure, will this function check if provided
254-
/// files are actually pipes.
253+
/// On unix if `unix_check_is_pipe` enabled this function will check if
254+
/// provided files are actually pipes.
255255
///
256256
/// # Safety
257257
///
@@ -269,7 +269,7 @@ impl Client {
269269
///
270270
/// Note, though, that on Windows it should be safe to call this function
271271
/// any number of times.
272-
pub unsafe fn from_env_ext() -> Result<Client, ErrFromEnv> {
272+
pub unsafe fn from_env_ext(check_pipe: bool) -> Result<Client, ErrFromEnv> {
273273
let (env, var) = ["CARGO_MAKEFLAGS", "MAKEFLAGS", "MFLAGS"]
274274
.iter()
275275
.map(|&env| env::var(env).map(|var| (env, var)))
@@ -283,7 +283,11 @@ impl Client {
283283
.ok_or(ErrFromEnv::IsNotConfigured)?;
284284

285285
let s = var[pos + arg.len()..].split(' ').next().unwrap();
286-
match imp::Client::open(s) {
286+
#[cfg(unix)]
287+
let imp_client = imp::Client::open(s, check_pipe);
288+
#[cfg(not(unix))]
289+
let imp_client = imp::Client::open(s);
290+
match imp_client {
287291
Ok(c) => Ok(Client { inner: Arc::new(c) }),
288292
Err(err) => Err(ErrFromEnv::PlatformSpecific { err, env, var }),
289293
}
@@ -294,7 +298,7 @@ impl Client {
294298
///
295299
/// Wraps `from_env_ext` and discards error details.
296300
pub unsafe fn from_env() -> Option<Client> {
297-
Self::from_env_ext().ok()
301+
Self::from_env_ext(false).ok()
298302
}
299303

300304
/// Acquires a token from this jobserver client.

src/unix.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ impl Client {
8181
Ok(Client::from_fds(pipes[0], pipes[1]))
8282
}
8383

84-
pub unsafe fn open(s: &str) -> io::Result<Client> {
84+
pub unsafe fn open(s: &str, check_pipe: bool) -> io::Result<Client> {
8585
if let Some(client) = Self::from_fifo(s)? {
8686
return Ok(client);
8787
}
88-
if let Some(client) = Self::from_pipe(s)? {
88+
if let Some(client) = Self::from_pipe(s, check_pipe)? {
8989
return Ok(client);
9090
}
9191
Err(io::Error::new(
@@ -111,7 +111,7 @@ impl Client {
111111
}
112112

113113
/// `--jobserver-auth=R,W`
114-
unsafe fn from_pipe(s: &str) -> io::Result<Option<Client>> {
114+
unsafe fn from_pipe(s: &str, check_pipe: bool) -> io::Result<Option<Client>> {
115115
let mut parts = s.splitn(2, ',');
116116
let read = parts.next().unwrap();
117117
let write = match parts.next() {
@@ -133,8 +133,8 @@ impl Client {
133133
// If we're called from `make` *without* the leading + on our rule
134134
// then we'll have `MAKEFLAGS` env vars but won't actually have
135135
// access to the file descriptors.
136-
check_fd(read)?;
137-
check_fd(write)?;
136+
check_fd(read, check_pipe)?;
137+
check_fd(write, check_pipe)?;
138138
drop(set_cloexec(read, true));
139139
drop(set_cloexec(write, true));
140140
Ok(Some(Client::from_fds(read, write)))
@@ -386,9 +386,8 @@ impl Helper {
386386
}
387387
}
388388

389-
fn check_fd(fd: c_int) -> io::Result<()> {
390-
#[cfg(not(feature = "do_not_check_pipe"))]
391-
unsafe {
389+
unsafe fn check_fd(fd: c_int, check_pipe: bool) -> io::Result<()> {
390+
if check_pipe {
392391
let mut stat = mem::zeroed();
393392
if libc::fstat(fd, &mut stat) == -1 {
394393
Err(io::Error::last_os_error())
@@ -404,9 +403,7 @@ fn check_fd(fd: c_int) -> io::Result<()> {
404403
}
405404
Err(io::Error::last_os_error()) //
406405
}
407-
}
408-
#[cfg(feature = "do_not_check_pipe")]
409-
unsafe {
406+
} else {
410407
match libc::fcntl(fd, libc::F_GETFD) {
411408
r if r == -1 => Err(io::Error::new(
412409
io::ErrorKind::InvalidData,

0 commit comments

Comments
 (0)