-
Notifications
You must be signed in to change notification settings - Fork 13.5k
deprecate before_exec in favor of unsafe pre_exec #58059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+171
−95
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6bfb280
deprecate before_exec in favor of unsafe pre_exec
RalfJung d48433d
also replace before_exec by pre_exec on redox
RalfJung b1709d2
update test
RalfJung cbbf8a7
deprecate things a bit slower
RalfJung 6c67a76
pre_exec: expand docs
RalfJung 59da97d
rustfmt the test
RalfJung 33ee99b
more formatting
RalfJung e023403
POSIX requires async signal safety for fork in signal handlers, not i…
RalfJung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#![allow(stable_features)] | ||
// ignore-windows - this is a unix-specific test | ||
// ignore-cloudabi no processes | ||
// ignore-emscripten no processes | ||
#![feature(process_exec, rustc_private)] | ||
|
||
extern crate libc; | ||
|
||
use std::env; | ||
use std::io::Error; | ||
use std::os::unix::process::CommandExt; | ||
use std::process::Command; | ||
use std::sync::atomic::{AtomicUsize, Ordering}; | ||
use std::sync::Arc; | ||
|
||
fn main() { | ||
if let Some(arg) = env::args().nth(1) { | ||
match &arg[..] { | ||
"test1" => println!("hello2"), | ||
"test2" => assert_eq!(env::var("FOO").unwrap(), "BAR"), | ||
"test3" => assert_eq!(env::current_dir().unwrap().to_str().unwrap(), "/"), | ||
"empty" => {} | ||
_ => panic!("unknown argument: {}", arg), | ||
} | ||
return; | ||
} | ||
|
||
let me = env::current_exe().unwrap(); | ||
|
||
let output = unsafe { | ||
Command::new(&me) | ||
.arg("test1") | ||
.pre_exec(|| { | ||
println!("hello"); | ||
Ok(()) | ||
}) | ||
.output() | ||
.unwrap() | ||
}; | ||
assert!(output.status.success()); | ||
assert!(output.stderr.is_empty()); | ||
assert_eq!(output.stdout, b"hello\nhello2\n"); | ||
|
||
let output = unsafe { | ||
Command::new(&me) | ||
.arg("test2") | ||
.pre_exec(|| { | ||
env::set_var("FOO", "BAR"); | ||
Ok(()) | ||
}) | ||
.output() | ||
.unwrap() | ||
}; | ||
assert!(output.status.success()); | ||
assert!(output.stderr.is_empty()); | ||
assert!(output.stdout.is_empty()); | ||
|
||
let output = unsafe { | ||
Command::new(&me) | ||
.arg("test3") | ||
.pre_exec(|| { | ||
env::set_current_dir("/").unwrap(); | ||
Ok(()) | ||
}) | ||
.output() | ||
.unwrap() | ||
}; | ||
assert!(output.status.success()); | ||
assert!(output.stderr.is_empty()); | ||
assert!(output.stdout.is_empty()); | ||
|
||
let output = unsafe { | ||
Command::new(&me) | ||
.arg("bad") | ||
.pre_exec(|| Err(Error::from_raw_os_error(102))) | ||
.output() | ||
.unwrap_err() | ||
}; | ||
assert_eq!(output.raw_os_error(), Some(102)); | ||
|
||
let pid = unsafe { libc::getpid() }; | ||
assert!(pid >= 0); | ||
let output = unsafe { | ||
Command::new(&me) | ||
.arg("empty") | ||
.pre_exec(move || { | ||
let child = libc::getpid(); | ||
assert!(child >= 0); | ||
assert!(pid != child); | ||
Ok(()) | ||
}) | ||
.output() | ||
.unwrap() | ||
}; | ||
assert!(output.status.success()); | ||
assert!(output.stderr.is_empty()); | ||
assert!(output.stdout.is_empty()); | ||
|
||
let mem = Arc::new(AtomicUsize::new(0)); | ||
let mem2 = mem.clone(); | ||
let output = unsafe { | ||
Command::new(&me) | ||
.arg("empty") | ||
.pre_exec(move || { | ||
assert_eq!(mem2.fetch_add(1, Ordering::SeqCst), 0); | ||
Ok(()) | ||
}) | ||
.output() | ||
.unwrap() | ||
}; | ||
assert!(output.status.success()); | ||
assert!(output.stderr.is_empty()); | ||
assert!(output.stdout.is_empty()); | ||
assert_eq!(mem.load(Ordering::SeqCst), 0); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.