rust/minijail: Make sure spawned jobs termininate during unit tests.
BUG=chromium:1096175,chromium:1097761
TEST=FEATURES=test emerge-${BOARD} dev-rust/minijail
Change-Id: I4ab231e616975031892b2211a78e41b8c99bfcde
diff --git a/rust/minijail/src/lib.rs b/rust/minijail/src/lib.rs
index 3741a1d..d9f273e 100644
--- a/rust/minijail/src/lib.rs
+++ b/rust/minijail/src/lib.rs
@@ -699,6 +699,8 @@
#[cfg(test)]
mod tests {
+ use std::process::exit;
+
use super::*;
#[test]
@@ -722,8 +724,8 @@
j.parse_seccomp_filters(Path::new("src/test_filter.policy"))
.unwrap();
j.use_seccomp_filter();
- unsafe {
- j.fork(None).unwrap();
+ if unsafe { j.fork(None).unwrap() } == 0 {
+ exit(0);
}
}
@@ -742,6 +744,7 @@
if j.fork(Some(&fds)).unwrap() == 0 {
assert!(libc::close(second) < 0); // Should fail as second should be closed already.
assert_eq!(libc::close(first), 0); // Should succeed as first should be untouched.
+ exit(0);
}
}
}
@@ -751,8 +754,8 @@
fn chroot() {
let mut j = Minijail::new().unwrap();
j.enter_chroot(Path::new(".")).unwrap();
- unsafe {
- j.fork(None).unwrap();
+ if unsafe { j.fork(None).unwrap() } == 0 {
+ exit(0);
}
}
@@ -761,8 +764,8 @@
fn namespace_vfs() {
let mut j = Minijail::new().unwrap();
j.namespace_vfs();
- unsafe {
- j.fork(None).unwrap();
+ if unsafe { j.fork(None).unwrap() } == 0 {
+ exit(0);
}
}