Skip to content
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

Rollup of 9 pull requests #82983

Closed
wants to merge 24 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5fe84c8
always eagerly eval consts in Relate
lcnr Jan 23, 2021
2beea2c
add test for lazy norm err
lcnr Jan 23, 2021
1ab9fe5
Add {core,std}::prelude::{rust_2015,rust_2018,rust_2021}.
m-ou-se Feb 17, 2021
d3b564c
Pick the injected prelude based on the edition.
m-ou-se Feb 17, 2021
218cf30
Update test output for edition preludes.
m-ou-se Feb 17, 2021
d274d87
Update test/pretty output for edition preludes.
m-ou-se Feb 17, 2021
76fd8d7
Use intra-doc links.
m-ou-se Feb 25, 2021
28135b7
Remove redundant enableSearchInput function
notriddle Mar 5, 2021
d854789
Do not attempt to unlock envlock in child process after a fork.
the8472 Mar 9, 2021
e40b3d6
Treat header as first paragraph for shortened markdown descriptions
notriddle Mar 10, 2021
37543ce
fix: wrong word
ltoddy Mar 10, 2021
b7d91b0
Remove `masked_crates` from `clean::Crate`
camelid Mar 10, 2021
66b6504
Simplify some of the rendering code in the index
notriddle Mar 10, 2021
55c88f5
fix error message for copy(_nonoverlapping) overflow
RalfJung Mar 10, 2021
b0514a6
Rename Option::get_or_insert_default
camsteffen Mar 10, 2021
4ff62b3
Rollup merge of #81309 - lcnr:lazy-norm-err-msgh, r=nikomatsakis
jonas-schievink Mar 10, 2021
71444a4
Rollup merge of #82217 - m-ou-se:edition-prelude, r=nikomatsakis
jonas-schievink Mar 10, 2021
7da6185
Rollup merge of #82807 - notriddle:cleanup-js, r=jyn514
jonas-schievink Mar 10, 2021
d6ad430
Rollup merge of #82949 - the8472:forget-envlock-on-fork, r=joshtriplett
jonas-schievink Mar 10, 2021
1d3076b
Rollup merge of #82955 - ltoddy:fix/wrong, r=jonas-schievink
jonas-schievink Mar 10, 2021
d103f4f
Rollup merge of #82960 - camelid:masked_crates, r=jyn514
jonas-schievink Mar 10, 2021
b7ca86a
Rollup merge of #82962 - notriddle:cleanup-index, r=jyn514
jonas-schievink Mar 10, 2021
bc6bc42
Rollup merge of #82976 - RalfJung:copy-nonoverlapping, r=oli-obk
jonas-schievink Mar 10, 2021
ea66bfc
Rollup merge of #82977 - camsteffen:opt-get-insert-def, r=m-ou-se
jonas-schievink Mar 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Do not attempt to unlock envlock in child process after a fork.
This is a breaking change for cases where the environment is
accessed in a Command::pre_exec closure. Except for
single-threaded programs these uses were not correct
anyway since they aren't async-signal safe.
the8472 committed Mar 9, 2021
commit d854789ce191be25f2953c60fd50ce711776d9eb
11 changes: 10 additions & 1 deletion library/std/src/sys/unix/ext/process.rs
Original file line number Diff line number Diff line change
@@ -62,9 +62,14 @@ pub trait CommandExt: Sealed {
/// `fork`. This primarily means that any modifications made to memory on
/// behalf of this closure will **not** be visible to the parent process.
/// This is often a very constrained environment where normal operations
/// like `malloc` or acquiring a mutex are not guaranteed to work (due to
/// like `malloc`, accessing environment variables through [`std::env`]
/// or acquiring a mutex are not guaranteed to work (due to
/// other threads perhaps still running when the `fork` was run).
///
/// For further details refer to the [POSIX fork() specification]
/// and the equivalent documentation for any targeted
/// platform, especially the requirements around *async-signal-safety*.
///
/// This also means that all resources such as file descriptors and
/// memory-mapped regions got duplicated. It is your responsibility to make
/// sure that the closure does not violate library invariants by making
@@ -73,6 +78,10 @@ pub trait CommandExt: Sealed {
/// When this closure is run, aspects such as the stdio file descriptors and
/// working directory have successfully been changed, so output to these
/// locations may not appear where intended.
///
/// [POSIX fork() specification]:
/// https://pubs.opengroup.org/onlinepubs/9699919799/functions/fork.html
/// [`std::env`]: mod@crate::env
#[stable(feature = "process_pre_exec", since = "1.34.0")]
unsafe fn pre_exec<F>(&mut self, f: F) -> &mut process::Command
where
15 changes: 9 additions & 6 deletions library/std/src/sys/unix/process/process_unix.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::convert::TryInto;
use crate::fmt;
use crate::io::{self, Error, ErrorKind};
use crate::mem;
use crate::ptr;
use crate::sys;
use crate::sys::cvt;
@@ -45,15 +46,14 @@ impl Command {
//
// Note that as soon as we're done with the fork there's no need to hold
// a lock any more because the parent won't do anything and the child is
// in its own process.
let result = unsafe {
let _env_lock = sys::os::env_lock();
cvt(libc::fork())?
};
// in its own process. Thus the parent drops the lock guard while the child
// forgets it to avoid unlocking it on a new thread, which would be invalid.
let (env_lock, result) = unsafe { (sys::os::env_lock(), cvt(libc::fork())?) };

let pid = unsafe {
match result {
0 => {
mem::forget(env_lock);
drop(input);
let Err(err) = self.do_exec(theirs, envp.as_ref());
let errno = err.raw_os_error().unwrap_or(libc::EINVAL) as u32;
@@ -74,7 +74,10 @@ impl Command {
rtassert!(output.write(&bytes).is_ok());
libc::_exit(1)
}
n => n,
n => {
drop(env_lock);
n
}
}
};

14 changes: 0 additions & 14 deletions src/test/ui/command/command-pre-exec.rs
Original file line number Diff line number Diff line change
@@ -43,20 +43,6 @@ fn main() {
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")