Skip to content

Commit f7338ec

Browse files
committed
Ensure any pending stdout writes are flushed.
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
1 parent c7aa7e0 commit f7338ec

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

mkmain.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@ use std::fs::File;
55
static TEMPLATE: &'static str = "\
66
extern crate @UTIL_CRATE@ as uu@UTIL_CRATE@;
77
8-
use std::env;
8+
use std::io::Write;
99
use uu@UTIL_CRATE@::uumain;
1010
1111
fn main() {
12-
std::process::exit(uumain(env::args().collect()));
12+
let code = uumain(std::env::args().collect());
13+
14+
// Since stdout is line-buffered by default, we need to ensure any pending
15+
// writes are flushed before exiting. Ideally, this should be enforced by
16+
// each utility.
17+
//
18+
// See: https://github.com/rust-lang/rust/issues/23818
19+
//
20+
std::io::stdout().flush().unwrap();
21+
22+
std::process::exit(code);
1323
}
1424
";
1525

0 commit comments

Comments
 (0)