Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand documentation of process::exit and exec #38518

Merged
merged 1 commit into from
Feb 5, 2017

Conversation

nagisa
Copy link
Member

@nagisa nagisa commented Dec 21, 2016

Show a conventional way to use process::exit when destructors are considered important and also
mention that the same caveats wrt destructors apply to exec as well.

@rust-highfive
Copy link
Collaborator

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@steveklabnik
Copy link
Member

steveklabnik commented Dec 21, 2016

@bors: delegate=kmcallister

r? @kmcallister

@bors
Copy link
Contributor

bors commented Dec 21, 2016

✌️ @keeganmacallister can now approve this pull request

@bors
Copy link
Contributor

bors commented Dec 21, 2016

✌️ @kmcallister can now approve this pull request

/// 1
/// }
/// });
/// }
/// ```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about this as an example:

use std::io::{self, Write};
use std::process;

fn run_app() -> Result<(), ()> {
    // Your application logic here
    Ok(())
}

fn main() {
    process::exit(match run_app() {
        Ok(_) => 0,
        Err(_) => 1,
    });
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer to not include an import for only one use of a function. I incorporated some of the other changes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you printing the error if the error type is ()?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose I can see why, but it does seem unrelated to the point of this example. Not a big deal.

@@ -67,10 +67,20 @@ pub trait CommandExt {
/// an error indicating why the exec (or another part of the setup of the
/// `Command`) failed.
///
/// `exec` not returning has the same implications as calling
/// [`process::exit`] – no destructors on the current stack or any other
/// thread’s stack will be run. Therefore, it is recommended to only call
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more accurate to replace "any other thread's" with "child thread's"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. “Child thread” makes sense in relation to “main thread”, but you can call process::exit on any thread you want.

/// `exec` at a point where it is fine to not run any destructors. Note,
/// that `execvp` syscall independently guarantees that all memory is freed
/// and all file descriptors with the `CLOEXEC` option (set by default on all
/// file descriptors opened by the standard library) are closed.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this platform specific behavior? I'm not familiar with how all the platforms handle execvp

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not. We always try our best to set CLOEXEC on all filedescriptors in the standard library and the behaviour of execvp wrt CLOEXEC fds is documented in posix: http://pubs.opengroup.org/onlinepubs/9699919799/functions/execvp.html

/// [`process::exit`] – no destructors on the current stack or any other
/// thread’s stack will be run. Therefore, it is recommended to only call
/// `exec` at a point where it is fine to not run any destructors. Note,
/// that `execvp` syscall independently guarantees that all memory is freed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: that the execvp syscall

@@ -875,10 +875,23 @@ impl Child {
///
/// # Examples
///
/// Due to this function’s behaviour regarding destructors, a conventional way
/// to use the function is to extract the actual computation to another
/// function and compute exit code from its return value:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: compute the exit code

@nagisa
Copy link
Member Author

nagisa commented Jan 7, 2017

Ping?

@@ -875,10 +875,27 @@ impl Child {
///
/// # Examples
///
/// Due to this function’s behaviour regarding destructors, a conventional way
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the documentation uses American English, so this should be "behavior"

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jan 19, 2017
Show a conventional way to use process::exit when destructors are considered important and also
mention that the same caveats wrt destructors apply to exec as well.
@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Feb 4, 2017

📌 Commit c2eab73 has been approved by alexcrichton

@frewsxcv
Copy link
Member

frewsxcv commented Feb 4, 2017

@bors rollup

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 5, 2017
Expand documentation of process::exit and exec

Show a conventional way to use process::exit when destructors are considered important and also
mention that the same caveats wrt destructors apply to exec as well.
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 5, 2017
Expand documentation of process::exit and exec

Show a conventional way to use process::exit when destructors are considered important and also
mention that the same caveats wrt destructors apply to exec as well.
bors added a commit that referenced this pull request Feb 5, 2017
@bors bors merged commit c2eab73 into rust-lang:master Feb 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants