Skip to content

Commit d48433d

Browse files
committed
also replace before_exec by pre_exec on redox
1 parent 6bfb280 commit d48433d

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

src/libstd/sys/redox/ext/process.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub trait CommandExt {
3636
/// will be called and the spawn operation will immediately return with a
3737
/// failure.
3838
///
39-
/// # Notes
39+
/// # Notes and Safety
4040
///
4141
/// This closure will be run in the context of the child process after a
4242
/// `fork`. This primarily means that any modifications made to memory on
@@ -45,12 +45,32 @@ pub trait CommandExt {
4545
/// like `malloc` or acquiring a mutex are not guaranteed to work (due to
4646
/// other threads perhaps still running when the `fork` was run).
4747
///
48+
/// This also means that all resources such as file descriptors and
49+
/// memory-mapped regions got duplicated. It is your responsibility to make
50+
/// sure that the closure does not violate library invariants by making
51+
/// invalid use of these duplicates.
52+
///
4853
/// When this closure is run, aspects such as the stdio file descriptors and
4954
/// working directory have successfully been changed, so output to these
5055
/// locations may not appear where intended.
56+
#[stable(feature = "process_pre_exec", since = "1.34.0")]
57+
unsafe fn pre_exec<F>(&mut self, f: F) -> &mut process::Command
58+
where F: FnMut() -> io::Result<()> + Send + Sync + 'static;
59+
60+
/// Schedules a closure to be run just before the `exec` function is
61+
/// invoked.
62+
///
63+
/// This method should be unsafe, so it got deprecated in favor of the
64+
/// unsafe [`pre_exec`].
65+
///
66+
/// [`pre_exec`]: #tymethod.pre_exec
5167
#[stable(feature = "process_exec", since = "1.15.0")]
68+
#[rustc_deprecated(since = "1.34.0", reason = "should be unsafe, use `pre_exec` instead")]
5269
fn before_exec<F>(&mut self, f: F) -> &mut process::Command
53-
where F: FnMut() -> io::Result<()> + Send + Sync + 'static;
70+
where F: FnMut() -> io::Result<()> + Send + Sync + 'static
71+
{
72+
unsafe { self.pre_exec(f) }
73+
}
5474

5575
/// Performs all the required setup by this `Command`, followed by calling
5676
/// the `execvp` syscall.
@@ -87,10 +107,10 @@ impl CommandExt for process::Command {
87107
self
88108
}
89109

90-
fn before_exec<F>(&mut self, f: F) -> &mut process::Command
110+
unsafe fn pre_exec<F>(&mut self, f: F) -> &mut process::Command
91111
where F: FnMut() -> io::Result<()> + Send + Sync + 'static
92112
{
93-
self.as_inner_mut().before_exec(Box::new(f));
113+
self.as_inner_mut().pre_exec(Box::new(f));
94114
self
95115
}
96116

src/libstd/sys/redox/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl Command {
116116
self.gid = Some(id);
117117
}
118118

119-
pub fn before_exec(&mut self,
119+
pub unsafe fn pre_exec(&mut self,
120120
f: Box<dyn FnMut() -> io::Result<()> + Send + Sync>) {
121121
self.closures.push(f);
122122
}

src/libstd/sys/unix/ext/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub trait CommandExt {
3636
/// will be called and the spawn operation will immediately return with a
3737
/// failure.
3838
///
39-
/// # Notes
39+
/// # Notes and Safety
4040
///
4141
/// This closure will be run in the context of the child process after a
4242
/// `fork`. This primarily means that any modifications made to memory on

0 commit comments

Comments
 (0)