Skip to content

Better document that process::exit does not result in a clean shutdown #28058

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

Closed
crumblingstatue opened this issue Aug 28, 2015 · 4 comments
Closed

Comments

@crumblingstatue
Copy link
Contributor

The documentation states If a clean shutdown is needed it is recommended to only call this function at a known point where there are no more destructors left to run., however simply running it when no more destructors are left to run does not guarantee a clean exit. For example, output buffers are not flushed, as opposed to normal program termination. There might be other things that process::exit does not do that normal program termination does that I'm not aware of. These too should be documented. Or at the least, the documentation should not imply that if you run process::exit when there are no more destructors left to run, you get a clean exit.

Furthermore, process::exit should not be recommended as a mechanism for simply setting the exit code. env::set_exit_status was deprecated with the message Deprecated since 1.2.0: use process::exit instead, then removed. process::exit is simply not a good alternative. There are valid reasons for setting the exit code without abormal program termination.

Examples:

  • Incorrect command line argument: Print help, set exit status to non-zero. Clean exit.
  • File stated in command line argument does not exist. State this to the user, set exit status to non-zero. Clean exit.
@crumblingstatue crumblingstatue changed the title Better document lack of clean shutdown with process::exit Better document that process::exit does not result in a clean shutdown Aug 28, 2015
@sfackler
Copy link
Member

Which output buffers are not flushed? We register atexit handlers to take care of the global stdout buffer: https://github.com/rust-lang/rust/blob/master/src/libstd/io/lazy.rs#L53, and stderr is unbuffered.

@crumblingstatue
Copy link
Contributor Author

Which output buffers are not flushed? We register atexit handlers to take care of the global stdout buffer: https://github.com/rust-lang/rust/blob/master/src/libstd/io/lazy.rs#L53, and stderr is unbuffered.

fn main() { print!("Hi!"); } results in "Hi!", fn main() { print!("Hi!"); std::process::exit(0); } results in no output.

@sfackler
Copy link
Member

That seems like a bug in rt::atexit: #28065

@mbrubeck mbrubeck added the A-docs label Sep 4, 2015
@steveklabnik
Copy link
Member

Given that the bug has been fixed, I'm going to give this a close. Please let me know if that's still wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants