also replace before_exec by pre_exec on redox

This commit is contained in:
Ralf Jung
2019-02-01 19:57:06 +01:00
parent 6bfb280189
commit d48433d920
3 changed files with 27 additions and 7 deletions

View File

@@ -36,7 +36,7 @@ pub trait CommandExt {
/// will be called and the spawn operation will immediately return with a /// will be called and the spawn operation will immediately return with a
/// failure. /// failure.
/// ///
/// # Notes /// # Notes and Safety
/// ///
/// This closure will be run in the context of the child process after a /// This closure will be run in the context of the child process after a
/// `fork`. This primarily means that any modifications made to memory on /// `fork`. This primarily means that any modifications made to memory on
@@ -45,13 +45,33 @@ pub trait CommandExt {
/// like `malloc` or acquiring a mutex are not guaranteed to work (due to /// like `malloc` or acquiring a mutex are not guaranteed to work (due to
/// other threads perhaps still running when the `fork` was run). /// other threads perhaps still running when the `fork` was run).
/// ///
/// 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
/// invalid use of these duplicates.
///
/// When this closure is run, aspects such as the stdio file descriptors and /// When this closure is run, aspects such as the stdio file descriptors and
/// working directory have successfully been changed, so output to these /// working directory have successfully been changed, so output to these
/// locations may not appear where intended. /// locations may not appear where intended.
#[stable(feature = "process_exec", since = "1.15.0")] #[stable(feature = "process_pre_exec", since = "1.34.0")]
fn before_exec<F>(&mut self, f: F) -> &mut process::Command unsafe fn pre_exec<F>(&mut self, f: F) -> &mut process::Command
where F: FnMut() -> io::Result<()> + Send + Sync + 'static; where F: FnMut() -> io::Result<()> + Send + Sync + 'static;
/// Schedules a closure to be run just before the `exec` function is
/// invoked.
///
/// This method should be unsafe, so it got deprecated in favor of the
/// unsafe [`pre_exec`].
///
/// [`pre_exec`]: #tymethod.pre_exec
#[stable(feature = "process_exec", since = "1.15.0")]
#[rustc_deprecated(since = "1.34.0", reason = "should be unsafe, use `pre_exec` instead")]
fn before_exec<F>(&mut self, f: F) -> &mut process::Command
where F: FnMut() -> io::Result<()> + Send + Sync + 'static
{
unsafe { self.pre_exec(f) }
}
/// Performs all the required setup by this `Command`, followed by calling /// Performs all the required setup by this `Command`, followed by calling
/// the `execvp` syscall. /// the `execvp` syscall.
/// ///
@@ -87,10 +107,10 @@ impl CommandExt for process::Command {
self self
} }
fn before_exec<F>(&mut self, f: F) -> &mut process::Command unsafe fn pre_exec<F>(&mut self, f: F) -> &mut process::Command
where F: FnMut() -> io::Result<()> + Send + Sync + 'static where F: FnMut() -> io::Result<()> + Send + Sync + 'static
{ {
self.as_inner_mut().before_exec(Box::new(f)); self.as_inner_mut().pre_exec(Box::new(f));
self self
} }

View File

@@ -116,7 +116,7 @@ impl Command {
self.gid = Some(id); self.gid = Some(id);
} }
pub fn before_exec(&mut self, pub unsafe fn pre_exec(&mut self,
f: Box<dyn FnMut() -> io::Result<()> + Send + Sync>) { f: Box<dyn FnMut() -> io::Result<()> + Send + Sync>) {
self.closures.push(f); self.closures.push(f);
} }

View File

@@ -36,7 +36,7 @@ pub trait CommandExt {
/// will be called and the spawn operation will immediately return with a /// will be called and the spawn operation will immediately return with a
/// failure. /// failure.
/// ///
/// # Notes /// # Notes and Safety
/// ///
/// This closure will be run in the context of the child process after a /// This closure will be run in the context of the child process after a
/// `fork`. This primarily means that any modifications made to memory on /// `fork`. This primarily means that any modifications made to memory on