Skip to content

Commit

Permalink
Ensure any pending stdout writes are flushed.
Browse files Browse the repository at this point in the history
Since stdout is line-buffered by default, we need to ensure any pending
writes are flushed before exiting. Ideally, this should be enforced by
each utility. Since all utilities are wrapped by mkmain, this was a
convenient location to enforce this behavior. I previously was handling
this on a case-by-case basis.

See: rust-lang/rust#23818
  • Loading branch information
jbcrail committed May 30, 2015
1 parent 5050601 commit 174b834
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions mkmain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ use std::fs::File;
static TEMPLATE: &'static str = "\
extern crate @UTIL_CRATE@ as uu@UTIL_CRATE@;
use std::env;
use std::io::Write;
use uu@UTIL_CRATE@::uumain;
fn main() {
std::process::exit(uumain(env::args().collect()));
let code = uumain(std::env::args().collect());
// Since stdout is line-buffered by default, we need to ensure any pending
// writes are flushed before exiting. Ideally, this should be enforced by
// each utility.
//
// See: https://github.com/rust-lang/rust/issues/23818
//
std::io::stdout().flush().unwrap();
std::process::exit(code);
}
";

Expand Down

0 comments on commit 174b834

Please sign in to comment.