Don't use libc::exit. #9473

This can cause unexpected errors in the runtime when done while
scheduler threads are still initializing. Required some restructuring
of the main_args functions in our libraries.
This commit is contained in:
Brian Anderson
2013-09-24 16:34:23 -07:00
parent 7535479633
commit 6d03897376
6 changed files with 45 additions and 45 deletions

View File

@@ -52,7 +52,7 @@ enum OutputFormat {
}
pub fn main() {
main_args(std::os::args());
std::os::set_exit_status(main_args(std::os::args()));
}
pub fn opts() -> ~[groups::OptGroup] {
@@ -76,14 +76,14 @@ pub fn usage(argv0: &str) {
argv0), opts()));
}
pub fn main_args(args: &[~str]) {
pub fn main_args(args: &[~str]) -> int {
//use extra::getopts::groups::*;
let matches = groups::getopts(args.tail(), opts()).unwrap();
if matches.opt_present("h") || matches.opt_present("help") {
usage(args[0]);
return;
return 0;
}
let (format, cratefile) = match matches.free.clone() {
@@ -92,17 +92,17 @@ pub fn main_args(args: &[~str]) {
[s, _] => {
println!("Unknown output format: `{}`", s);
usage(args[0]);
exit(1);
return 1;
}
[_, .._] => {
println!("Expected exactly one crate to process");
usage(args[0]);
exit(1);
return 1;
}
_ => {
println!("Expected an output format and then one crate");
usage(args[0]);
exit(1);
return 1;
}
};
@@ -179,6 +179,8 @@ pub fn main_args(args: &[~str]) {
}
let ended = time::precise_time_ns();
info2!("Took {:.03f}s", (ended as f64 - started as f64) / 1000000000f64);
return 0;
}
fn jsonify(crate: clean::Crate, res: ~[plugins::PluginJson], dst: Path) {
@@ -208,9 +210,3 @@ fn jsonify(crate: clean::Crate, res: ~[plugins::PluginJson], dst: Path) {
let output = extra::json::Object(json).to_str();
file.write(output.as_bytes());
}
fn exit(status: int) -> ! {
#[fixed_stack_segment]; #[inline(never)];
use std::libc;
unsafe { libc::exit(status as libc::c_int) }
}