@@ -36,7 +36,7 @@ pub trait CommandExt {
36
36
/// will be called and the spawn operation will immediately return with a
37
37
/// failure.
38
38
///
39
- /// # Notes
39
+ /// # Notes and Safety
40
40
///
41
41
/// This closure will be run in the context of the child process after a
42
42
/// `fork`. This primarily means that any modifications made to memory on
@@ -45,12 +45,32 @@ pub trait CommandExt {
45
45
/// like `malloc` or acquiring a mutex are not guaranteed to work (due to
46
46
/// other threads perhaps still running when the `fork` was run).
47
47
///
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
+ ///
48
53
/// When this closure is run, aspects such as the stdio file descriptors and
49
54
/// working directory have successfully been changed, so output to these
50
55
/// 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
51
67
#[ stable( feature = "process_exec" , since = "1.15.0" ) ]
68
+ #[ rustc_deprecated( since = "1.34.0" , reason = "should be unsafe, use `pre_exec` instead" ) ]
52
69
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
+ }
54
74
55
75
/// Performs all the required setup by this `Command`, followed by calling
56
76
/// the `execvp` syscall.
@@ -87,10 +107,10 @@ impl CommandExt for process::Command {
87
107
self
88
108
}
89
109
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
91
111
where F : FnMut ( ) -> io:: Result < ( ) > + Send + Sync + ' static
92
112
{
93
- self . as_inner_mut ( ) . before_exec ( Box :: new ( f) ) ;
113
+ self . as_inner_mut ( ) . pre_exec ( Box :: new ( f) ) ;
94
114
self
95
115
}
96
116
0 commit comments