Skip to content

Commit 6bfb280

Browse files
committed
deprecate before_exec in favor of unsafe pre_exec
1 parent 742fcc7 commit 6bfb280

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
@@ -97,10 +117,10 @@ impl CommandExt for process::Command {
97117
self
98118
}
99119

100-
fn before_exec<F>(&mut self, f: F) -> &mut process::Command
120+
unsafe fn pre_exec<F>(&mut self, f: F) -> &mut process::Command
101121
where F: FnMut() -> io::Result<()> + Send + Sync + 'static
102122
{
103-
self.as_inner_mut().before_exec(Box::new(f));
123+
self.as_inner_mut().pre_exec(Box::new(f));
104124
self
105125
}
106126

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Command {
149149
&mut self.closures
150150
}
151151

152-
pub fn before_exec(&mut self,
152+
pub unsafe fn pre_exec(&mut self,
153153
f: Box<dyn FnMut() -> io::Result<()> + Send + Sync>) {
154154
self.closures.push(f);
155155
}

0 commit comments

Comments
 (0)