File tree 2 files changed +29
-2
lines changed
2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -924,10 +924,27 @@ impl Child {
924
924
///
925
925
/// # Examples
926
926
///
927
+ /// Due to this function’s behavior regarding destructors, a conventional way
928
+ /// to use the function is to extract the actual computation to another
929
+ /// function and compute the exit code from its return value:
930
+ ///
927
931
/// ```
928
- /// use std::process;
932
+ /// use std::io::{self, Write};
933
+ ///
934
+ /// fn run_app() -> Result<(), ()> {
935
+ /// // Application logic here
936
+ /// Ok(())
937
+ /// }
929
938
///
930
- /// process::exit(0);
939
+ /// fn main() {
940
+ /// ::std::process::exit(match run_app() {
941
+ /// Ok(_) => 0,
942
+ /// Err(err) => {
943
+ /// writeln!(io::stderr(), "error: {:?}", err).unwrap();
944
+ /// 1
945
+ /// }
946
+ /// });
947
+ /// }
931
948
/// ```
932
949
///
933
950
/// Due to [platform-specific behavior], the exit code for this example will be
Original file line number Diff line number Diff line change @@ -67,10 +67,20 @@ pub trait CommandExt {
67
67
/// an error indicating why the exec (or another part of the setup of the
68
68
/// `Command`) failed.
69
69
///
70
+ /// `exec` not returning has the same implications as calling
71
+ /// [`process::exit`] – no destructors on the current stack or any other
72
+ /// thread’s stack will be run. Therefore, it is recommended to only call
73
+ /// `exec` at a point where it is fine to not run any destructors. Note,
74
+ /// that the `execvp` syscall independently guarantees that all memory is
75
+ /// freed and all file descriptors with the `CLOEXEC` option (set by default
76
+ /// on all file descriptors opened by the standard library) are closed.
77
+ ///
70
78
/// This function, unlike `spawn`, will **not** `fork` the process to create
71
79
/// a new child. Like spawn, however, the default behavior for the stdio
72
80
/// descriptors will be to inherited from the current process.
73
81
///
82
+ /// [`process::exit`]: ../../../process/fn.exit.html
83
+ ///
74
84
/// # Notes
75
85
///
76
86
/// The process may be in a "broken state" if this function returns in
You can’t perform that action at this time.
0 commit comments