Skip to content

Commit 2a37582

Browse files
committed
std: Move a process test out of libstd
This commit moves a test out of libstd which is causing deadlocks on musl on CI. Looks like the recent update in musl versions brings in some internal updates to musl which makes `setgid` and `setuid` invalid to call after a `fork` in a multithreaded program. The issue seen here is that the child thread was attempting to grab a lock held by a nonexistent thread, meaning that the child process simply deadlocked causing the whole test to deadlock. This commit moves the test to its own file with no threads which should work.
1 parent a6b5d22 commit 2a37582

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

src/libstd/process.rs

-27
Original file line numberDiff line numberDiff line change
@@ -1765,33 +1765,6 @@ mod tests {
17651765
assert_eq!(out, "foobar\n");
17661766
}
17671767

1768-
1769-
#[test]
1770-
#[cfg_attr(target_os = "android", ignore)]
1771-
#[cfg(unix)]
1772-
fn uid_works() {
1773-
use crate::os::unix::prelude::*;
1774-
1775-
let mut p = Command::new("/bin/sh")
1776-
.arg("-c").arg("true")
1777-
.uid(unsafe { libc::getuid() })
1778-
.gid(unsafe { libc::getgid() })
1779-
.spawn().unwrap();
1780-
assert!(p.wait().unwrap().success());
1781-
}
1782-
1783-
#[test]
1784-
#[cfg_attr(target_os = "android", ignore)]
1785-
#[cfg(unix)]
1786-
fn uid_to_root_fails() {
1787-
use crate::os::unix::prelude::*;
1788-
1789-
// if we're already root, this isn't a valid test. Most of the bots run
1790-
// as non-root though (android is an exception).
1791-
if unsafe { libc::getuid() == 0 } { return }
1792-
assert!(Command::new("/bin/ls").uid(0).gid(0).spawn().is_err());
1793-
}
1794-
17951768
#[test]
17961769
#[cfg_attr(target_os = "android", ignore)]
17971770
fn test_process_status() {

src/test/run-pass/command-uid-gid.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![feature(rustc_private)]
2+
3+
fn main() {
4+
#[cfg(unix)]
5+
run()
6+
}
7+
8+
#[cfg(unix)]
9+
fn run() {
10+
extern crate libc;
11+
use std::process::Command;
12+
use std::os::unix::prelude::*;
13+
14+
let mut p = Command::new("/bin/sh")
15+
.arg("-c").arg("true")
16+
.uid(unsafe { libc::getuid() })
17+
.gid(unsafe { libc::getgid() })
18+
.spawn().unwrap();
19+
assert!(p.wait().unwrap().success());
20+
21+
// if we're already root, this isn't a valid test. Most of the bots run
22+
// as non-root though (android is an exception).
23+
if unsafe { libc::getuid() != 0 } {
24+
assert!(Command::new("/bin/ls").uid(0).gid(0).spawn().is_err());
25+
}
26+
}

0 commit comments

Comments
 (0)