From cee1695e0839d0672113e7445cec0722559585ee Mon Sep 17 00:00:00 2001 From: Dirk Gadsden Date: Sun, 31 Jan 2016 11:50:22 -0800 Subject: [PATCH 1/2] Safety docs about `std::process::Child` going out of scope There is no `Drop` implemented for `Child`, so if it goes out of scope in Rust-land and gets deallocated, the child process will continue to exist and execute. If users want a guarantee that the process has finished running and exited they must manually use `kill`, `wait`, or `wait_with_output`. Fixes #31289. --- src/libstd/process.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 7197dfa8b2d47..2cfbef1e1b7d9 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -47,6 +47,14 @@ use thread::{self, JoinHandle}; /// /// assert!(ecode.success()); /// ``` +/// +/// # Safety +/// +/// Take note that there is no implementation of +/// [`Drop`](../../core/ops/trait.Drop.html) for child processes, so if you +/// not ensure the `Child` has exited (through `kill`, `wait`, or +/// `wait_with_output`) then it will continue to run even after the `Child` +/// handle to it has gone out of scope. #[stable(feature = "process", since = "1.0.0")] pub struct Child { handle: imp::Process, From 76839221ff9bc4fd65ab9e7c0f1cd8e7514446f0 Mon Sep 17 00:00:00 2001 From: Dirk Gadsden Date: Sun, 31 Jan 2016 12:33:37 -0800 Subject: [PATCH 2/2] Minor corrections in docs for `std::process::Child` --- src/libstd/process.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 2cfbef1e1b7d9..5e0a54392d23d 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -48,13 +48,15 @@ use thread::{self, JoinHandle}; /// assert!(ecode.success()); /// ``` /// -/// # Safety +/// # Note /// /// Take note that there is no implementation of /// [`Drop`](../../core/ops/trait.Drop.html) for child processes, so if you -/// not ensure the `Child` has exited (through `kill`, `wait`, or -/// `wait_with_output`) then it will continue to run even after the `Child` -/// handle to it has gone out of scope. +/// do not ensure the `Child` has exited then it will continue to run, even +/// after the `Child` handle to the child process has gone out of scope. +/// +/// Calling `wait` (or other functions that wrap around it) will make the +/// parent process wait until the child has actually exited before continuing. #[stable(feature = "process", since = "1.0.0")] pub struct Child { handle: imp::Process,