From ce19eb4329df398dc8ad2db3da08d1e7b8a06ffe Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 11 Jun 2014 21:29:16 -0700 Subject: [PATCH 01/10] Update to Rust nightly --- du/du.rs | 3 +-- uutils/uutils.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/du/du.rs b/du/du.rs index 055e1d211..6bd1ad54d 100644 --- a/du/du.rs +++ b/du/du.rs @@ -14,15 +14,14 @@ extern crate getopts; extern crate libc; -extern crate sync; extern crate time; use std::os; use std::io::{stderr, fs, FileStat, TypeDirectory}; use std::option::Option; use std::path::Path; +use std::sync::{Arc, Future}; use time::Timespec; -use sync::{Arc, Future}; #[path = "../common/util.rs"] mod util; diff --git a/uutils/uutils.rs b/uutils/uutils.rs index 8c708c123..64fa66609 100644 --- a/uutils/uutils.rs +++ b/uutils/uutils.rs @@ -9,7 +9,6 @@ * file that was distributed with this source code. */ -extern crate collections; extern crate getopts; extern crate base64; @@ -54,7 +53,7 @@ extern crate whoami; extern crate yes; use std::os; -use collections::hashmap::HashMap; +use std::collections::hashmap::HashMap; static NAME: &'static str = "uutils"; static VERSION: &'static str = "1.0.0"; From 0ee4fb0576677aec7bbc258f3e3ac85518c4d6e2 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 8 Jun 2014 00:56:37 -0700 Subject: [PATCH 02/10] Handle exit status more consistently. #211 This changes the `uumain` functions to return the exit code as `int`. It does not eliminate all calls to `os::set_exit_status` and `libc::exit`. --- base64/base64.rs | 6 ++++-- basename/basename.rs | 14 ++++++++------ cat/cat.rs | 10 ++++++---- cksum/cksum.rs | 12 +++++++----- comm/comm.rs | 14 ++++++++------ cp/cp.rs | 6 ++++-- dirname/dirname.rs | 11 +++++++---- du/du.rs | 24 +++++++++++++----------- echo/echo.rs | 11 +++++++---- env/env.rs | 24 +++++++++++++----------- fold/fold.rs | 6 ++++-- groups/groups.rs | 8 +++++--- head/head.rs | 12 +++++++----- hostid/hostid.rs | 8 +++++--- hostname/hostname.rs | 14 ++++++++------ id/id.rs | 22 ++++++++++++---------- kill/kill.rs | 8 +++++--- logname/logname.rs | 10 ++++++---- md5sum/md5sum.rs | 21 +++++++++++++++------ mkdir/mkdir.rs | 10 ++++++---- paste/paste.rs | 6 ++++-- printenv/printenv.rs | 10 ++++++---- pwd/pwd.rs | 12 +++++++++--- rm/rm.rs | 8 +++++--- rmdir/rmdir.rs | 8 +++++--- seq/seq.rs | 21 +++++++++++---------- sleep/sleep.rs | 8 +++++--- sum/sum.rs | 10 ++++++---- tac/tac.rs | 6 ++++-- tee/tee.rs | 12 ++++++------ touch/touch.rs | 10 ++++++---- tr/tr.rs | 17 +++++++++-------- truncate/truncate.rs | 6 ++++-- tty/tty.rs | 9 ++++----- uname/uname.rs | 10 ++++++---- unlink/unlink.rs | 10 ++++++---- uptime/uptime.rs | 10 ++++++---- users/users.rs | 10 ++++++---- uutils/uutils.rs | 16 +++++++++------- wc/wc.rs | 10 ++++++---- whoami/whoami.rs | 10 ++++++---- yes/yes.rs | 10 ++++++---- 42 files changed, 285 insertions(+), 195 deletions(-) diff --git a/base64/base64.rs b/base64/base64.rs index fd240f5b4..b42010304 100644 --- a/base64/base64.rs +++ b/base64/base64.rs @@ -35,7 +35,7 @@ mod util; static NAME: &'static str = "base64"; -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let opts = [ optflag("d", "decode", "decode data"), optflag("i", "ignore-garbage", "when decoding, ignore non-alphabetic characters"), @@ -88,10 +88,12 @@ pub fn uumain(args: Vec) { Help => help(progname.as_slice(), usage.as_slice()), Version => version() } + + return 0; } #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } fn decode(input: &mut Reader, ignore_garbage: bool) { let mut to_decode = match input.read_to_str() { diff --git a/basename/basename.rs b/basename/basename.rs index e3c170ba1..8f5b2f3ee 100644 --- a/basename/basename.rs +++ b/basename/basename.rs @@ -24,9 +24,9 @@ static NAME: &'static str = "basename"; static VERSION: &'static str = "1.0.0"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = strip_dir(args.get(0).as_slice()); // @@ -50,25 +50,25 @@ pub fn uumain(args: Vec) { print(getopts::usage("", opts).as_slice()); - return; + return 0; } if matches.opt_present("version") { println!("{} {}", program, VERSION); - return; + return 0; } // too few arguments if args.len() < 2 { println!("{}: {}", program, "missing operand"); println!("Try '{} --help' for more information.", program); - return; + return 0; } // too many arguments else if args.len() > 3 { println!("{}: extra operand '{}'", program, args.get(3)); println!("Try '{} --help' for more information.", program); - return; + return 0; } // @@ -85,6 +85,8 @@ pub fn uumain(args: Vec) { } println(name.as_slice()); + + return 0; } fn strip_dir(fullname: &str) -> String { diff --git a/cat/cat.rs b/cat/cat.rs index 557a9feef..ba8fad3f5 100644 --- a/cat/cat.rs +++ b/cat/cat.rs @@ -20,9 +20,9 @@ use std::io::{IoResult}; use std::ptr::{copy_nonoverlapping_memory}; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).as_slice(); let opts = [ getopts::optflag("A", "show-all", "equivalent to -vET"), @@ -53,11 +53,11 @@ pub fn uumain(args: Vec) { standard output.", opts).as_slice()); println!(""); println!("With no FILE, or when FILE is -, read standard input."); - return; + return 0; } if matches.opt_present("version") { println!("cat 1.0.0"); - return; + return 0; } let mut number_mode = NumberNone; @@ -80,6 +80,8 @@ pub fn uumain(args: Vec) { } exec(files, number_mode, show_nonprint, show_ends, show_tabs, squeeze_blank); + + return 0; } #[deriving(Eq, PartialEq)] diff --git a/cksum/cksum.rs b/cksum/cksum.rs index 6907a2e40..af6799437 100644 --- a/cksum/cksum.rs +++ b/cksum/cksum.rs @@ -78,9 +78,9 @@ fn open_file(name: &str) -> IoResult> { } #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let opts = [ getopts::optflag("h", "help", "display this help and exit"), getopts::optflag("V", "version", "output version information and exit"), @@ -98,12 +98,12 @@ pub fn uumain(args: Vec) { println!(" {} [OPTIONS] [FILE]...", NAME); println!(""); print(getopts::usage("Print CRC and size for each file.", opts.as_slice()).as_slice()); - return; + return 0; } if matches.opt_present("version") { println!("{} {}", NAME, VERSION); - return; + return 0; } let files = matches.free; @@ -113,7 +113,7 @@ pub fn uumain(args: Vec) { Ok((crc, size)) => println!("{} {}", crc, size), Err(err) => show_error!(2, "{}", err), } - return + return 0; } for fname in files.iter() { @@ -122,4 +122,6 @@ pub fn uumain(args: Vec) { Err(err) => show_error!(2, "'{}' {}", fname, err), } } + + return 0; } diff --git a/comm/comm.rs b/comm/comm.rs index 1cc1d2eeb..e2d669777 100644 --- a/comm/comm.rs +++ b/comm/comm.rs @@ -95,9 +95,9 @@ fn open_file(name: &str) -> IoResult> { } #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let opts = [ getopts::optflag("1", "", "suppress column 1 (lines uniq to FILE1)"), getopts::optflag("2", "", "suppress column 2 (lines uniq to FILE2)"), @@ -114,7 +114,7 @@ pub fn uumain(args: Vec) { if matches.opt_present("version") { println!("{} {}", NAME, VERSION); - return; + return 0; } if matches.opt_present("help") || matches.free.len() != 2 { @@ -125,14 +125,16 @@ pub fn uumain(args: Vec) { println!(""); print(getopts::usage("Compare sorted files line by line.", opts.as_slice()).as_slice()); if matches.free.len() != 2 { - os::set_exit_status(1); + return 0; } - return; + return 0; } let mut f1 = open_file(matches.free.get(0).as_slice()).unwrap(); let mut f2 = open_file(matches.free.get(1).as_slice()).unwrap(); - comm(&mut f1, &mut f2, &matches) + comm(&mut f1, &mut f2, &matches); + + return 0; } diff --git a/cp/cp.rs b/cp/cp.rs index 7176d9007..b23eb2c6a 100644 --- a/cp/cp.rs +++ b/cp/cp.rs @@ -32,9 +32,9 @@ pub enum Mode { } #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let opts = [ optflag("h", "help", "display this help and exit"), optflag("", "version", "output version information and exit"), @@ -62,6 +62,8 @@ pub fn uumain(args: Vec) { Help => help(progname.as_slice(), usage.as_slice()), Version => version(), } + + return 0; } fn version() { diff --git a/dirname/dirname.rs b/dirname/dirname.rs index 196d7bef4..65a830793 100644 --- a/dirname/dirname.rs +++ b/dirname/dirname.rs @@ -17,9 +17,9 @@ use std::io::print; static VERSION: &'static str = "1.0.0"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); let opts = [ getopts::optflag("z", "zero", "separate output with NUL rather than newline"), @@ -41,11 +41,12 @@ pub fn uumain(args: Vec) { print(getopts::usage("Output each NAME with its last non-slash component and trailing slashes removed; if NAME contains no /'s, output '.' (meaning the current directory).", opts).as_slice()); - return; + return 0; } if matches.opt_present("version") { - return println!("dirname version: {:s}", VERSION); + println!("dirname version: {:s}", VERSION); + return 0; } let separator = match matches.opt_present("zero") { @@ -66,4 +67,6 @@ directory).", opts).as_slice()); println!("{0:s}: missing operand", program); println!("Try '{0:s} --help' for more information.", program); } + + return 0; } diff --git a/du/du.rs b/du/du.rs index 6bd1ad54d..0b57be8f0 100644 --- a/du/du.rs +++ b/du/du.rs @@ -90,9 +90,9 @@ fn du(path: &Path, mut my_stat: Stat, } #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).as_slice(); let opts = [ // In task @@ -163,7 +163,7 @@ pub fn uumain(args: Vec) { Ok(m) => m, Err(f) => { show_error!(1, "Invalid options\n{}", f.to_err_msg()); - return + return 0; } }; @@ -187,10 +187,10 @@ ers of 1000).", program = program, version = VERSION, usage = getopts::usage("Summarize disk usage of each FILE, recursively for directories.", opts)); - return + return 0; } else if matches.opt_present("version") { println!("{} version: {}", program, VERSION); - return + return 0; } let summarize = matches.opt_present("summarize"); @@ -200,11 +200,11 @@ ers of 1000).", match (max_depth_str, max_depth) { (Some(ref s), _) if summarize => { println!("{}: warning: summarizing conflicts with --max-depth={:s}", program, *s); - return + return 0; } (Some(ref s), None) => { println!("{}: invalid maximum depth '{:s}'", program, *s); - return + return 0; } (Some(_), Some(_)) | (None, _) => { /* valid */ } } @@ -239,7 +239,7 @@ ers of 1000).", for c in s.as_slice().chars() { if found_letter && c.is_digit() || !found_number && !c.is_digit() { println!("{}: invalid --block-size argument '{}'", program, s); - return + return 0; } else if c.is_digit() { found_number = true; numbers.push(c as u8); @@ -261,7 +261,7 @@ ers of 1000).", "ZB" => 1000 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000, "YB" => 1000 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 * 1000, _ => { - println!("{}: invalid --block-size argument '{}'", program, s); return + println!("{}: invalid --block-size argument '{}'", program, s); return 0; } }; number * multiple @@ -300,7 +300,7 @@ Valid arguments are: - 'long-iso' - 'iso' Try '{program} --help' for more information.", s, program = program); - return + return 0; } } }, @@ -339,7 +339,7 @@ Try '{program} --help' for more information.", s, program = program); Valid arguments are: - 'accessed', 'created', 'modified' Try '{program} --help' for more information.", program = program); - return + return 0; } }, None => stat.fstat.modified @@ -366,4 +366,6 @@ Try '{program} --help' for more information.", s, program = program); print!("{:<10} total", convert_size(grand_total)); print!("{}", line_separator); } + + return 0; } diff --git a/echo/echo.rs b/echo/echo.rs index 75e798593..4d57d19a7 100644 --- a/echo/echo.rs +++ b/echo/echo.rs @@ -70,9 +70,9 @@ fn convert_str(string: &str, index: uint, base: uint) -> (char, int) { } #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); let opts = [ getopts::optflag("n", "", "do not output the trailing newline"), @@ -109,11 +109,12 @@ pub fn uumain(args: Vec) { \\v vertical tab \\0NNN byte with octal value NNN (1 to 3 digits) \\xHH byte with hexadecimal value HH (1 to 2 digits)"); - return; + return 0; } if matches.opt_present("version") { - return println!("echo version: {:s}", VERSION); + println!("echo version: {:s}", VERSION); + return 0; } if !matches.free.is_empty() { @@ -185,4 +186,6 @@ pub fn uumain(args: Vec) { if !matches.opt_present("n") { println!("") } + + return 0; } diff --git a/env/env.rs b/env/env.rs index b3d365af5..c02b962f3 100644 --- a/env/env.rs +++ b/env/env.rs @@ -54,9 +54,9 @@ fn print_env(null: bool) { } #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let prog = args.get(0).as_slice(); // to handle arguments the same way than GNU env, we can't use getopts @@ -97,8 +97,8 @@ pub fn uumain(args: Vec) { } } else if opt.as_slice().starts_with("--") { match opt.as_slice() { - "--help" => { usage(prog); return } - "--version" => { version(); return } + "--help" => { usage(prog); return 0; } + "--version" => { version(); return 0; } "--ignore-environment" => opts.ignore_env = true, "--null" => opts.null = true, @@ -114,7 +114,7 @@ pub fn uumain(args: Vec) { _ => { println!("{:s}: invalid option \"{:s}\"", prog, *opt); println!("Type \"{:s} --help\" for detailed informations", prog); - return + return 0; } } } else if opt.as_slice().starts_with("-") { @@ -131,8 +131,8 @@ pub fn uumain(args: Vec) { for c in chars { // short versions of options match c { - 'h' => { usage(prog); return } - 'V' => { version(); return } + 'h' => { usage(prog); return 0; } + 'V' => { version(); return 0; } 'i' => opts.ignore_env = true, '0' => opts.null = true, 'u' => { @@ -146,7 +146,7 @@ pub fn uumain(args: Vec) { _ => { println!("{:s}: illegal option -- {:c}", prog, c); println!("Type \"{:s} --help\" for detailed informations", prog); - return + return 0; } } } @@ -200,14 +200,16 @@ pub fn uumain(args: Vec) { let args = opts.program.slice_from(1); match Command::new(prog).args(args).stdin(InheritFd(0)).stdout(InheritFd(1)).stderr(InheritFd(2)).status() { Ok(exit) => - std::os::set_exit_status(match exit { + return match exit { std::io::process::ExitStatus(s) => s, _ => 1 - }), - Err(_) => std::os::set_exit_status(1) + }, + Err(_) => return 1 } } else { // no program provided print_env(opts.null); } + + return 0; } diff --git a/fold/fold.rs b/fold/fold.rs index e5ccc732b..5818e0fb8 100644 --- a/fold/fold.rs +++ b/fold/fold.rs @@ -27,9 +27,9 @@ static NAME: &'static str = "fold"; static VERSION: &'static str = "1.0.0"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let (args, obs_width) = handle_obsolete(args.as_slice()); let program = args.get(0).clone(); @@ -82,6 +82,8 @@ pub fn uumain(args: Vec) { }; fold(files, bytes, spaces, width); } + + return 0; } fn handle_obsolete(args: &[String]) -> (Vec, Option) { diff --git a/groups/groups.rs b/groups/groups.rs index d344e9583..54abdbc92 100644 --- a/groups/groups.rs +++ b/groups/groups.rs @@ -26,9 +26,9 @@ use c_types::{get_pw_from_args, group}; static NAME: &'static str = "groups"; #[allow(dead_code)] -fn main () { uumain(os::args()); } +fn main () { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let options = [ optflag("h", "", "Help") ]; @@ -37,9 +37,11 @@ pub fn uumain(args: Vec) { Ok(m) => { m }, Err(_) => { show_error!(1, "{}", usage(NAME, options)); - return; + return 0; } }; group(get_pw_from_args(&matches.free), true); + + return 0; } diff --git a/head/head.rs b/head/head.rs index 70fe114df..6840588a4 100644 --- a/head/head.rs +++ b/head/head.rs @@ -23,9 +23,9 @@ use getopts::{optopt, optflag, getopts, usage}; static PROGRAM: &'static str = "head"; #[allow(dead_code)] -fn main () { uumain(os::args()); } +fn main () { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let mut line_count = 10u; // handle obsolete -number syntax @@ -46,15 +46,15 @@ pub fn uumain(args: Vec) { Ok (m) => { m } Err(_) => { println!("{:s}", usage(PROGRAM, possible_options)); - return + return 0; } }; if given_options.opt_present("h") { println!("{:s}", usage(PROGRAM, possible_options)); - return; + return 0; } - if given_options.opt_present("V") { version(); return } + if given_options.opt_present("V") { version(); return 0 } match given_options.opt_str("n") { Some(n) => { @@ -93,6 +93,8 @@ pub fn uumain(args: Vec) { head(&mut buffer, line_count); } } + + return 0; } // It searches for an option in the form of -123123 diff --git a/hostid/hostid.rs b/hostid/hostid.rs index 6ce2d77e0..38aaefd24 100644 --- a/hostid/hostid.rs +++ b/hostid/hostid.rs @@ -50,9 +50,9 @@ extern { } #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let opts = [ optflag("", "help", "display this help and exit"), @@ -66,7 +66,7 @@ pub fn uumain(args: Vec) { Ok(m) => m, Err(e) => { show_error!(EXIT_ERR, "{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice())); - return + return 0; }, }; @@ -83,6 +83,8 @@ pub fn uumain(args: Vec) { Help => help(NAME, usage.as_slice()), Version => version(), } + + return 0; } fn version() { diff --git a/hostname/hostname.rs b/hostname/hostname.rs index f78dd1173..c0b7a3210 100644 --- a/hostname/hostname.rs +++ b/hostname/hostname.rs @@ -24,9 +24,9 @@ extern { } #[allow(dead_code)] -fn main () { uumain(os::args()); } +fn main () { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0); let options = [ @@ -38,14 +38,14 @@ pub fn uumain(args: Vec) { let matches = match getopts(args.tail(), options) { Ok(m) => { m } - _ => { help_menu(program.as_slice(), options); return; } + _ => { help_menu(program.as_slice(), options); return 0; } }; if matches.opt_present("h") { help_menu(program.as_slice(), options); - return + return 0 } - if matches.opt_present("V") { version(); return } + if matches.opt_present("V") { version(); return 0 } match matches.free.len() { 0 => { @@ -55,7 +55,7 @@ pub fn uumain(args: Vec) { let pos = hostname.as_slice().find_str("."); if pos.is_some() { println!("{:s}", hostname.as_slice().slice_to(pos.unwrap())); - return; + return 0; } } @@ -64,6 +64,8 @@ pub fn uumain(args: Vec) { 1 => { xsethostname( matches.free.last().unwrap().as_slice() ) } _ => { help_menu(program.as_slice(), options); } }; + + return 0; } fn version() { diff --git a/id/id.rs b/id/id.rs index cd3c4364d..b61ee9a9d 100644 --- a/id/id.rs +++ b/id/id.rs @@ -88,9 +88,9 @@ extern { static NAME: &'static str = "id"; #[allow(dead_code)] -fn main () { uumain(os::args()); } +fn main () { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let args_t = args.tail(); let options = [ @@ -109,18 +109,18 @@ pub fn uumain(args: Vec) { Ok(m) => { m }, Err(_) => { println!("{:s}", usage(NAME, options)); - return; + return 0; } }; if matches.opt_present("h") { println!("{:s}", usage(NAME, options)); - return; + return 0; } if matches.opt_present("A") { auditid(); - return; + return 0; } @@ -149,7 +149,7 @@ pub fn uumain(args: Vec) { } else { println!("{:u}", id); } - return; + return 0; } if uflag { @@ -171,22 +171,22 @@ pub fn uumain(args: Vec) { println!("{:d}", id); } - return; + return 0; } if matches.opt_present("G") { group(possible_pw, nflag); - return; + return 0; } if matches.opt_present("P") { pline(possible_pw); - return; + return 0; }; if matches.opt_present("p") { pretty(possible_pw); - return; + return 0; } if possible_pw.is_some() { @@ -194,6 +194,8 @@ pub fn uumain(args: Vec) { } else { id_print(possible_pw, false, true, true) } + + return 0; } fn pretty(possible_pw: Option) { diff --git a/kill/kill.rs b/kill/kill.rs index f2dbe8b3e..0e48b6306 100644 --- a/kill/kill.rs +++ b/kill/kill.rs @@ -53,9 +53,9 @@ pub enum Mode { } #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let opts = [ optflag("h", "help", "display this help and exit"), @@ -72,7 +72,7 @@ pub fn uumain(args: Vec) { Ok(m) => m, Err(e) => { show_error!(EXIT_ERR, "{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice())); - return + return 0 }, }; @@ -96,6 +96,8 @@ pub fn uumain(args: Vec) { Help => help(NAME, usage.as_slice()), Version => version(), } + + return 0; } fn version() { diff --git a/logname/logname.rs b/logname/logname.rs index 1e6ea6650..4f34eb40b 100644 --- a/logname/logname.rs +++ b/logname/logname.rs @@ -44,9 +44,9 @@ fn version() { } #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); // @@ -69,14 +69,16 @@ pub fn uumain(args: Vec) { println!(" {:s}", program); println!(""); print(getopts::usage("print user's login name", opts).as_slice()); - return; + return 0; } if matches.opt_present("version") { version(); - return; + return 0; } exec(); + + return 0; } fn exec() { diff --git a/md5sum/md5sum.rs b/md5sum/md5sum.rs index b368e302a..25c0f0b78 100644 --- a/md5sum/md5sum.rs +++ b/md5sum/md5sum.rs @@ -27,8 +27,10 @@ mod util; static NAME: &'static str = "md5sum"; static VERSION: &'static str = "1.0.0"; -fn main() { - let args = os::args(); +#[allow(dead_code)] +fn main() { os::set_exit_status(uumain(os::args())); } + +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); @@ -72,11 +74,16 @@ fn main() { } else { matches.free }; - md5sum(files, binary, check, tag, status, quiet, strict, warn); + match md5sum(files, binary, check, tag, status, quiet, strict, warn) { + Ok(()) => return 0, + Err(e) => return e + } } + + return 0; } -fn md5sum(files: Vec, binary: bool, check: bool, tag: bool, status: bool, quiet: bool, strict: bool, warn: bool) { +fn md5sum(files: Vec, binary: bool, check: bool, tag: bool, status: bool, quiet: bool, strict: bool, warn: bool) -> Result<(), int> { let mut md5 = crypto::md5::Md5::new(); let bytes = md5.output_bits() / 4; let mut bad_format = 0; @@ -102,7 +109,7 @@ fn md5sum(files: Vec, binary: bool, check: bool, tag: bool, status: bool None => { bad_format += 1; if strict { - os::set_exit_status(1); + return Err(1); } if warn { show_warning!("{}: {}: improperly formatted MD5 checksum line", filename, i + 1); @@ -121,7 +128,7 @@ fn md5sum(files: Vec, binary: bool, check: bool, tag: bool, status: bool println!("{}: FAILED", ck_filename); } failed += 1; - os::set_exit_status(1); + return Err(1); } } } else { @@ -143,6 +150,8 @@ fn md5sum(files: Vec, binary: bool, check: bool, tag: bool, status: bool show_warning!("{} computed checksum did NOT match", failed); } } + + return Ok(()); } fn calc_sum(md5: &mut crypto::md5::Md5, file: &mut Reader, binary: bool) -> String { diff --git a/mkdir/mkdir.rs b/mkdir/mkdir.rs index eb88c1942..07a0fb6af 100644 --- a/mkdir/mkdir.rs +++ b/mkdir/mkdir.rs @@ -29,9 +29,9 @@ static VERSION: &'static str = "1.0.0"; * Handles option parsing */ #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let opts = [ // Linux-specific options, not implemented @@ -54,11 +54,11 @@ pub fn uumain(args: Vec) { if args.len() == 1 || matches.opt_present("help") { print_help(opts); - return; + return 0; } if matches.opt_present("version") { println!("mkdir v{}", VERSION); - return; + return 0; } let verbose_flag = matches.opt_present("verbose"); let mk_parents = matches.opt_present("parents"); @@ -85,6 +85,8 @@ pub fn uumain(args: Vec) { crash!(1, "missing operand"); } exec(dirs, mk_parents, mode, verbose_flag); + + return 0; } fn print_help(opts: &[getopts::OptGroup]) { diff --git a/paste/paste.rs b/paste/paste.rs index 31b55d681..9d55185fe 100644 --- a/paste/paste.rs +++ b/paste/paste.rs @@ -24,9 +24,9 @@ static NAME: &'static str = "paste"; static VERSION: &'static str = "1.0.0"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); let opts = [ @@ -56,6 +56,8 @@ pub fn uumain(args: Vec) { }; paste(matches.free, serial, delimiters.as_slice()); } + + return 0; } fn paste(filenames: Vec, serial: bool, delimiters: &str) { diff --git a/printenv/printenv.rs b/printenv/printenv.rs index 1df80e271..f0e928ca4 100644 --- a/printenv/printenv.rs +++ b/printenv/printenv.rs @@ -25,9 +25,9 @@ mod util; static NAME: &'static str = "printenv"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); let opts = [ getopts::optflag("0", "null", "end each output line with 0 byte rather than newline"), @@ -47,11 +47,11 @@ pub fn uumain(args: Vec) { println!(" {0:s} [VARIABLE]... [OPTION]...", program); println!(""); print(getopts::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", opts).as_slice()); - return; + return 0; } if matches.opt_present("version") { println!("printenv 1.0.0"); - return; + return 0; } let mut separator = "\n"; if matches.opt_present("null") { @@ -59,6 +59,8 @@ pub fn uumain(args: Vec) { }; exec(matches.free, separator); + + return 0; } pub fn exec(args: Vec, separator: &str) { diff --git a/pwd/pwd.rs b/pwd/pwd.rs index e8831237c..a89b5b906 100644 --- a/pwd/pwd.rs +++ b/pwd/pwd.rs @@ -24,9 +24,9 @@ static NAME: &'static str = "pwd"; static VERSION: &'static str = "1.0.0"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); let opts = [ getopts::optflag("", "help", "display this help and exit"), @@ -48,9 +48,15 @@ pub fn uumain(args: Vec) { println!(""); print(getopts::usage("Print the full filename of the current working directory.", opts).as_slice()); } else if matches.opt_present("version") { - return println!("pwd version: {}", VERSION); + println!("pwd version: {}", VERSION); + + return 0; } else { let cwd = std::os::getcwd(); println!("{}", cwd.display()); + + return 0; } + + return 0; } diff --git a/rm/rm.rs b/rm/rm.rs index 057013c1b..44f46e5d6 100644 --- a/rm/rm.rs +++ b/rm/rm.rs @@ -30,9 +30,9 @@ enum InteractiveMode { static NAME: &'static str = "rm"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); // TODO: make getopts support -R in addition to -r @@ -113,12 +113,14 @@ pub fn uumain(args: Vec) { "Remove all arguments? " }; if !prompt(msg) { - return; + return 0; } } remove(matches.free, force, interactive, one_fs, preserve_root, recursive, dir, verbose); } + + return 0; } // TODO: implement one-file-system diff --git a/rmdir/rmdir.rs b/rmdir/rmdir.rs index 14052754c..cd9020900 100644 --- a/rmdir/rmdir.rs +++ b/rmdir/rmdir.rs @@ -23,9 +23,9 @@ mod util; static NAME: &'static str = "rmdir"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); let opts = [ @@ -39,7 +39,7 @@ pub fn uumain(args: Vec) { Ok(m) => m, Err(f) => { show_error!(1, "{}", f.to_err_msg()); - return; + return 0; } }; @@ -61,6 +61,8 @@ pub fn uumain(args: Vec) { let verbose = matches.opt_present("verbose"); remove(matches.free, ignore, parents, verbose); } + + return 0; } fn remove(dirs: Vec, ignore: bool, parents: bool, verbose: bool) { diff --git a/seq/seq.rs b/seq/seq.rs index c0c098763..f0d068a87 100644 --- a/seq/seq.rs +++ b/seq/seq.rs @@ -34,9 +34,9 @@ fn escape_sequences(s: &str) -> String { } #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let opts = [ getopts::optopt("s", "separator", "Separator character (defaults to \\n)", ""), getopts::optopt("t", "terminator", "Terminator character (defaults to separator)", ""), @@ -49,26 +49,25 @@ pub fn uumain(args: Vec) { Err(f) => { show_error!(1, "{:s}", f.to_err_msg()); print_usage(opts); - return; + return 0; } }; if matches.opt_present("help") { print_usage(opts); - return; + return 0; } if matches.opt_present("version") { println!("seq 1.0.0"); - return; + return 0; } if matches.free.len() < 1 || matches.free.len() > 3 { - os::set_exit_status(1); print_usage(opts); - return; + return 1; } let first = if matches.free.len() > 1 { match parse_float(matches.free.get(0).as_slice()) { Ok(n) => n, - Err(s) => { show_error!(1, "{:s}", s); return; } + Err(s) => { show_error!(1, "{:s}", s); return 0; } } } else { 1.0 @@ -76,18 +75,20 @@ pub fn uumain(args: Vec) { let step = if matches.free.len() > 2 { match parse_float(matches.free.get(1).as_slice()) { Ok(n) => n, - Err(s) => { show_error!(1, "{:s}", s); return; } + Err(s) => { show_error!(1, "{:s}", s); return 0; } } } else { 1.0 }; let last = match parse_float(matches.free.get(matches.free.len()-1).as_slice()) { Ok(n) => n, - Err(s) => { show_error!(1, "{:s}", s); return; } + Err(s) => { show_error!(1, "{:s}", s); return 0; } }; let separator = escape_sequences(matches.opt_str("s").unwrap_or("\n".to_string()).as_slice()); let terminator = escape_sequences(matches.opt_str("t").unwrap_or(separator.to_string()).as_slice()); print_seq(first, step, last, separator, terminator, matches.opt_present("w")); + + return 0; } fn done_printing(next: f32, step: f32, last: f32) -> bool { diff --git a/sleep/sleep.rs b/sleep/sleep.rs index fe020fa8f..64c3f0828 100644 --- a/sleep/sleep.rs +++ b/sleep/sleep.rs @@ -24,9 +24,9 @@ mod util; static NAME: &'static str = "sleep"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); let opts = [ @@ -37,7 +37,7 @@ pub fn uumain(args: Vec) { Ok(m) => m, Err(f) => { show_error!(1, "{}", f.to_err_msg()); - return + return 0; } }; @@ -62,6 +62,8 @@ specified by the sum of their values.", opts).as_slice()); } else { sleep(matches.free); } + + return 0; } fn sleep(args: Vec) { diff --git a/sum/sum.rs b/sum/sum.rs index 352f1cf44..e8d7ed213 100644 --- a/sum/sum.rs +++ b/sum/sum.rs @@ -77,9 +77,9 @@ fn open(name: &str) -> IoResult> { } #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).as_slice(); let opts = [ getopts::optflag("r", "", "use the BSD compatible algorithm (default)"), @@ -102,11 +102,11 @@ pub fn uumain(args: Vec) { print(getopts::usage("checksum and count the blocks in a file", opts).as_slice()); println!(""); println!("With no FILE, or when FILE is -, read standard input."); - return; + return 0; } if matches.opt_present("version") { println!("{} {}", program, VERSION); - return; + return 0; } let sysv = matches.opt_present("sysv"); @@ -128,4 +128,6 @@ pub fn uumain(args: Vec) { }; println!("{} {}", sum, blocks); + + return 0; } diff --git a/tac/tac.rs b/tac/tac.rs index 90307d040..19c452e4f 100644 --- a/tac/tac.rs +++ b/tac/tac.rs @@ -24,9 +24,9 @@ static NAME: &'static str = "tac"; static VERSION: &'static str = "1.0.0"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); let opts = [ @@ -69,6 +69,8 @@ pub fn uumain(args: Vec) { }; tac(files, before, regex, separator.as_slice()); } + + return 0; } fn tac(filenames: Vec, before: bool, _: bool, separator: &str) { diff --git a/tee/tee.rs b/tee/tee.rs index b4af3a42c..59013076c 100644 --- a/tee/tee.rs +++ b/tee/tee.rs @@ -18,19 +18,19 @@ extern crate getopts; use std::io::{println, stdin, stdout, Append, File, Truncate, Write}; use std::io::{IoResult}; use std::io::util::{copy, NullWriter, MultiWriter}; -use std::os::{args, set_exit_status}; +use std::os; use getopts::{getopts, optflag, usage}; static NAME: &'static str = "tee"; static VERSION: &'static str = "1.0.0"; #[allow(dead_code)] -fn main() { uumain(args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { match options(args.as_slice()).and_then(exec) { - Ok(_) => set_exit_status(0), - Err(_) => set_exit_status(1) + Ok(_) => 0, + Err(_) => 1 } } @@ -153,5 +153,5 @@ fn with_path(path: &Path, cb: || -> IoResult) -> IoResult { } fn warn(message: &str) { - error!("{}: {}", args().get(0), message); + error!("{}: {}", os::args().get(0), message); } diff --git a/touch/touch.rs b/touch/touch.rs index 0886e15a2..8a08f9467 100644 --- a/touch/touch.rs +++ b/touch/touch.rs @@ -23,9 +23,9 @@ static NAME: &'static str = "touch"; static VERSION: &'static str = "1.0.0"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let opts = [ getopts::optflag("a", "", "change only the access time"), getopts::optflag("c", "no-create", "do not create any files"), @@ -49,7 +49,7 @@ pub fn uumain(args: Vec) { if matches.opt_present("version") { println!("{:s} {:s}", NAME, VERSION); - return; + return 0; } if matches.opt_present("help") || matches.free.is_empty() { @@ -59,7 +59,7 @@ pub fn uumain(args: Vec) { println!(""); println!("{:s}", getopts::usage("Update the access and modification times of \ each FILE to the current time.", opts)); - return; + return 0; } if matches.opt_present("date") && matches.opts_present(["reference".to_string(), "t".to_string()]) || @@ -131,6 +131,8 @@ pub fn uumain(args: Vec) { Err(e) => fail!("Unable to modify times\n{}", e.desc) } } + + return 0; } fn stat(path: &Path, follow: bool) -> std::io::FileStat { diff --git a/tr/tr.rs b/tr/tr.rs index 5b906564d..48af9ed4a 100644 --- a/tr/tr.rs +++ b/tr/tr.rs @@ -147,9 +147,9 @@ fn usage(opts: &[OptGroup]) { } #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let opts = [ getopts::optflag("c", "complement", "use the complement of SET1"), getopts::optflag("C", "", "same as -c"), @@ -162,24 +162,23 @@ pub fn uumain(args: Vec) { Ok(m) => m, Err(err) => { show_error!(1, "{}", err.to_err_msg()); - return; + return 0; } }; if matches.opt_present("help") { usage(opts); - return; + return 0; } if matches.opt_present("version") { println!("{} {}", NAME, VERSION); - return; + return 0; } if matches.free.len() == 0 { usage(opts); - os::set_exit_status(1); - return; + return 1; } let dflag = matches.opt_present("d"); @@ -188,7 +187,7 @@ pub fn uumain(args: Vec) { if cflag && !dflag { show_error!(1, "-c is only supported with -d"); - return; + return 0; } if dflag { @@ -199,4 +198,6 @@ pub fn uumain(args: Vec) { let set2 = expand_set(sets.get(1).as_slice()); tr(set1.as_slice(), set2.as_slice()); } + + return 0; } diff --git a/truncate/truncate.rs b/truncate/truncate.rs index aada407e3..fd9f3dbea 100644 --- a/truncate/truncate.rs +++ b/truncate/truncate.rs @@ -47,9 +47,9 @@ enum TruncateMode { static NAME: &'static str = "truncate"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); let opts = [ @@ -108,6 +108,8 @@ file based on its current size: truncate(no_create, io_blocks, reference, size, matches.free); } } + + return 0; } fn truncate(no_create: bool, _: bool, reference: Option, size: Option, filenames: Vec) { diff --git a/tty/tty.rs b/tty/tty.rs index b34ff8565..d715dd968 100644 --- a/tty/tty.rs +++ b/tty/tty.rs @@ -35,9 +35,9 @@ extern { static NAME: &'static str = "tty"; #[allow(dead_code)] -fn main () { uumain(os::args()); } +fn main () { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let options = [ optflag("s", "silent", "print nothing, only return an exit status") ]; @@ -49,7 +49,7 @@ pub fn uumain(args: Vec) { Err(f) => { println(f.to_err_msg().as_slice()); usage(); - return + return 2; } }; @@ -71,10 +71,9 @@ pub fn uumain(args: Vec) { } }; - os::set_exit_status(exit_code as int); + return exit_code as int; } fn usage () { safe_writeln!(&mut stderr() as &mut Writer, "usage: tty [-s]"); - os::set_exit_status(2); } diff --git a/uname/uname.rs b/uname/uname.rs index e9c4cefff..e25334275 100644 --- a/uname/uname.rs +++ b/uname/uname.rs @@ -52,9 +52,9 @@ unsafe fn getuname() -> utsrust { static NAME: &'static str = "uname"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).as_slice(); let opts = [ getopts::optflag("h", "help", "display this help and exit"), @@ -77,7 +77,7 @@ pub fn uumain(args: Vec) { println!(" {:s}", program); println!(""); print(getopts::usage("The uname utility writes symbols representing one or more system characteristics to the standard output.", opts).as_slice()); - return; + return 0; } let uname = unsafe { getuname() }; let mut output = String::new(); @@ -103,5 +103,7 @@ pub fn uumain(args: Vec) { output.push_str(uname.machine.as_slice()); output.push_str(" "); } - println!("{}", output.as_slice().trim_left()) + println!("{}", output.as_slice().trim_left()); + + return 0; } diff --git a/unlink/unlink.rs b/unlink/unlink.rs index fc879bda7..4221eafa7 100644 --- a/unlink/unlink.rs +++ b/unlink/unlink.rs @@ -27,9 +27,9 @@ mod util; static NAME: &'static str = "unlink"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); let opts = [ getopts::optflag("h", "help", "display this help and exit"), @@ -50,12 +50,12 @@ pub fn uumain(args: Vec) { println!(" {0:s} [FILE]... [OPTION]...", program); println!(""); print(getopts::usage("Unlink the file at [FILE].", opts).as_slice()); - return; + return 0; } if matches.opt_present("version") { println!("unlink 1.0.0"); - return; + return 0; } if matches.free.len() == 0 { @@ -86,4 +86,6 @@ pub fn uumain(args: Vec) { crash!(1, "cannot unlink '{0}': {1}", path.display(), e.desc); } } + + return 0; } diff --git a/uptime/uptime.rs b/uptime/uptime.rs index f131fbf05..eac380d0e 100644 --- a/uptime/uptime.rs +++ b/uptime/uptime.rs @@ -48,9 +48,9 @@ extern { } #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); let opts = [ getopts::optflag("v", "version", "output version information and exit"), @@ -62,7 +62,7 @@ pub fn uumain(args: Vec) { }; if matches.opt_present("version") { println!("uptime 1.0.0"); - return; + return 0; } if matches.opt_present("help") || matches.free.len() > 0 { println!("Usage:"); @@ -71,7 +71,7 @@ pub fn uumain(args: Vec) { print(getopts::usage("Print the current time, the length of time the system has been up,\n\ the number of users on the system, and the average number of jobs\n\ in the run queue over the last 1, 5 and 15 minutes.", opts).as_slice()); - return; + return 0; } print_time(); @@ -80,6 +80,8 @@ pub fn uumain(args: Vec) { print_uptime(upsecs); print_nusers(user_count); print_loadavg(); + + return 0; } fn print_loadavg() { diff --git a/users/users.rs b/users/users.rs index fc048153d..4017aad6f 100644 --- a/users/users.rs +++ b/users/users.rs @@ -48,9 +48,9 @@ extern { static NAME: &'static str = "users"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).as_slice(); let opts = [ getopts::optflag("h", "help", "display this help and exit"), @@ -69,12 +69,12 @@ pub fn uumain(args: Vec) { println!(" {:s} [OPTION]... [FILE]", program); println!(""); print(getopts::usage("Output who is currently logged in according to FILE.", opts).as_slice()); - return; + return 0; } if matches.opt_present("version") { println!("users 1.0.0"); - return; + return 0; } let mut filename = DEFAULT_FILE; @@ -83,6 +83,8 @@ pub fn uumain(args: Vec) { } exec(filename); + + return 0; } fn exec(filename: &str) { diff --git a/uutils/uutils.rs b/uutils/uutils.rs index 64fa66609..e7949d92b 100644 --- a/uutils/uutils.rs +++ b/uutils/uutils.rs @@ -58,9 +58,9 @@ use std::collections::hashmap::HashMap; static NAME: &'static str = "uutils"; static VERSION: &'static str = "1.0.0"; -fn util_map() -> HashMap<&str, fn(Vec)> { - fn uutrue(_: Vec) { os::set_exit_status(0); } - fn uufalse(_: Vec) { os::set_exit_status(1); } +fn util_map() -> HashMap<&str, fn(Vec) -> int> { + fn uutrue(_: Vec) -> int { 0 } + fn uufalse(_: Vec) -> int { 1 } let mut map = HashMap::new(); map.insert("base64", base64::uumain); @@ -108,7 +108,7 @@ fn util_map() -> HashMap<&str, fn(Vec)> { map } -fn usage(cmap: &HashMap<&str, fn(Vec)>) { +fn usage(cmap: &HashMap<&str, fn(Vec) -> int>) { println!("{} {}", NAME, VERSION); println!(""); println!("Usage:"); @@ -131,7 +131,7 @@ fn main() { let binary_as_util = binary.filename_str().unwrap(); if umap.contains_key(&binary_as_util) { let &uumain = umap.get(&binary_as_util); - uumain(args); + os::set_exit_status(uumain(args)); return } else if binary_as_util.starts_with("uutils") || binary_as_util.starts_with("busybox") { @@ -150,7 +150,7 @@ fn main() { let util = args.get(0).as_slice(); if umap.contains_key(&util) { let &uumain = umap.get(&util); - uumain(args.clone()); + os::set_exit_status(uumain(args.clone())); return } else if args.get(0).as_slice() == "--help" { // see if they want help on a specific util @@ -158,7 +158,7 @@ fn main() { let util = args.get(1).as_slice(); if umap.contains_key(&util) { let &uumain = umap.get(&util); - uumain(vec!["--help".to_string()]); + os::set_exit_status(uumain(vec!["--help".to_string()])); return } else { println!("{}: applet not found", util); @@ -167,6 +167,7 @@ fn main() { } } usage(&umap); + os::set_exit_status(0); return } else { println!("{}: applet not found", util); @@ -176,6 +177,7 @@ fn main() { } else { // no arguments provided usage(&umap); + os::set_exit_status(0); return } } diff --git a/wc/wc.rs b/wc/wc.rs index 9bf76cde2..bfd4d1597 100644 --- a/wc/wc.rs +++ b/wc/wc.rs @@ -34,9 +34,9 @@ struct Result { static NAME: &'static str = "wc"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); let opts = [ getopts::optflag("c", "bytes", "print the byte counts"), @@ -62,12 +62,12 @@ pub fn uumain(args: Vec) { print(getopts::usage("Print newline, word and byte counts for each FILE", opts).as_slice()); println!(""); println!("With no FILE, or when FILE is -, read standard input."); - return; + return 0; } if matches.opt_present("version") { println!("wc 1.0.0"); - return; + return 0; } let mut files = matches.free.clone(); @@ -76,6 +76,8 @@ pub fn uumain(args: Vec) { } wc(files, &matches); + + return 0; } static CR: u8 = '\r' as u8; diff --git a/whoami/whoami.rs b/whoami/whoami.rs index de5fe345c..65deb2d13 100644 --- a/whoami/whoami.rs +++ b/whoami/whoami.rs @@ -42,9 +42,9 @@ unsafe fn getusername() -> String { static NAME: &'static str = "whoami"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).as_slice(); let opts = [ getopts::optflag("h", "help", "display this help and exit"), @@ -61,14 +61,16 @@ pub fn uumain(args: Vec) { println!(" {:s}", program); println!(""); print(getopts::usage("print effective userid", opts).as_slice()); - return; + return 0; } if matches.opt_present("version") { println!("whoami 1.0.0"); - return; + return 0; } exec(); + + return 0; } pub fn exec() { diff --git a/yes/yes.rs b/yes/yes.rs index b03b9ae5c..38d0276b5 100644 --- a/yes/yes.rs +++ b/yes/yes.rs @@ -25,9 +25,9 @@ mod util; static NAME: &'static str = "yes"; #[allow(dead_code)] -fn main() { uumain(os::args()); } +fn main() { os::set_exit_status(uumain(os::args())); } -pub fn uumain(args: Vec) { +pub fn uumain(args: Vec) -> int { let program = args.get(0).clone(); let opts = [ getopts::optflag("h", "help", "display this help and exit"), @@ -46,11 +46,11 @@ pub fn uumain(args: Vec) { println!(" {0:s} [STRING]... [OPTION]...", program); println!(""); print(getopts::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", opts).as_slice()); - return; + return 0; } if matches.opt_present("version") { println!("yes 1.0.0"); - return; + return 0; } let mut string = "y".to_string(); if !matches.free.is_empty() { @@ -58,6 +58,8 @@ pub fn uumain(args: Vec) { } exec(string.as_slice()); + + return 0; } pub fn exec(string: &str) { From 962a6bbf2fcd32b683bbcfd486428d309888fad6 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 8 Jun 2014 01:37:02 -0700 Subject: [PATCH 03/10] Get test suite passing again by tweaking error handling in mkdir Replace `show_error!` with Result<(), int> and `display_error!` --- common/util.rs | 10 ++++++++++ mkdir/mkdir.rs | 19 +++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/common/util.rs b/common/util.rs index 14ae5d70d..401bad4cc 100644 --- a/common/util.rs +++ b/common/util.rs @@ -20,6 +20,16 @@ macro_rules! show_error( }) ) +// FIXME #211: Transitional until there are no further users of `show_error!`. +// Then this can be renamed. +#[macro_export] +macro_rules! display_error( + ($($args:expr),+) => ({ + safe_write!(&mut ::std::io::stderr(), "{}: error: ", ::NAME); + safe_writeln!(&mut ::std::io::stderr(), $($args),+); + }) +) + #[macro_export] macro_rules! show_warning( ($($args:expr),+) => ({ diff --git a/mkdir/mkdir.rs b/mkdir/mkdir.rs index 07a0fb6af..288591e42 100644 --- a/mkdir/mkdir.rs +++ b/mkdir/mkdir.rs @@ -84,9 +84,10 @@ pub fn uumain(args: Vec) -> int { if dirs.is_empty() { crash!(1, "missing operand"); } - exec(dirs, mk_parents, mode, verbose_flag); - - return 0; + match exec(dirs, mk_parents, mode, verbose_flag) { + Ok(()) => return 0, + Err(e) => return e + } } fn print_help(opts: &[getopts::OptGroup]) { @@ -99,7 +100,7 @@ fn print_help(opts: &[getopts::OptGroup]) { /** * Create the list of new directories */ -fn exec(dirs: Vec, mk_parents: bool, mode: FilePermission, verbose: bool) { +fn exec(dirs: Vec, mk_parents: bool, mode: FilePermission, verbose: bool) -> Result<(), int> { let mut parent_dirs = Vec::new(); if mk_parents { for dir in dirs.iter() { @@ -118,7 +119,10 @@ fn exec(dirs: Vec, mk_parents: bool, mode: FilePermission, verbose: bool } // Recursively build parent dirs that are needed if !parent_dirs.is_empty() { - exec(parent_dirs, mk_parents, mode, verbose); + match exec(parent_dirs, mk_parents, mode, verbose) { + Ok(()) => ( /* keep going */ ), + Err(e) => return Err(e) + } } for dir in dirs.iter() { @@ -140,9 +144,12 @@ fn exec(dirs: Vec, mk_parents: bool, mode: FilePermission, verbose: bool } else { format!("directory '{}' already exists", *dir) }; - show_error!(1, "{}", error_msg); + display_error!("{}", error_msg); + return Err(1); } } + + return Ok(()); } /** From 8fbfe24176df6f8b10b02188786413da9d84c41f Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 8 Jun 2014 18:49:06 -0700 Subject: [PATCH 04/10] Make show_error! not set the exit code. #211 --- cksum/cksum.rs | 10 ++++++-- common/util.rs | 16 +++--------- du/du.rs | 4 +-- groups/groups.rs | 4 +-- hostid/hostid.rs | 6 ++--- kill/kill.rs | 12 ++++----- mkdir/mkdir.rs | 2 +- rm/rm.rs | 60 +++++++++++++++++++++++++++++++------------- rmdir/rmdir.rs | 48 ++++++++++++++++++++++++----------- seq/seq.rs | 10 ++++---- sleep/sleep.rs | 9 ++++--- tr/tr.rs | 8 +++--- truncate/truncate.rs | 46 ++++++++++++++++++--------------- wc/wc.rs | 25 ++++++++++-------- 14 files changed, 156 insertions(+), 104 deletions(-) diff --git a/cksum/cksum.rs b/cksum/cksum.rs index af6799437..e8dbf4aa7 100644 --- a/cksum/cksum.rs +++ b/cksum/cksum.rs @@ -111,7 +111,10 @@ pub fn uumain(args: Vec) -> int { if files.is_empty() { match cksum("-") { Ok((crc, size)) => println!("{} {}", crc, size), - Err(err) => show_error!(2, "{}", err), + Err(err) => { + show_errer!("{}", err); + return 2; + } } return 0; } @@ -119,7 +122,10 @@ pub fn uumain(args: Vec) -> int { for fname in files.iter() { match cksum(fname.as_slice()) { Ok((crc, size)) => println!("{} {} {}", crc, size, fname), - Err(err) => show_error!(2, "'{}' {}", fname, err), + Err(err) => { + show_errer!("'{}' {}", fname, err); + return 2; + } } } diff --git a/common/util.rs b/common/util.rs index 401bad4cc..dc12fd26c 100644 --- a/common/util.rs +++ b/common/util.rs @@ -12,18 +12,7 @@ extern crate libc; #[macro_export] -macro_rules! show_error( - ($exitcode:expr, $($args:expr),+) => ({ - ::std::os::set_exit_status($exitcode as int); - safe_write!(&mut ::std::io::stderr(), "{}: error: ", ::NAME); - safe_writeln!(&mut ::std::io::stderr(), $($args),+); - }) -) - -// FIXME #211: Transitional until there are no further users of `show_error!`. -// Then this can be renamed. -#[macro_export] -macro_rules! display_error( +macro_rules! show_errer( ($($args:expr),+) => ({ safe_write!(&mut ::std::io::stderr(), "{}: error: ", ::NAME); safe_writeln!(&mut ::std::io::stderr(), $($args),+); @@ -41,7 +30,8 @@ macro_rules! show_warning( #[macro_export] macro_rules! crash( ($exitcode:expr, $($args:expr),+) => ({ - show_error!($exitcode, $($args),+); + safe_write!(&mut ::std::io::stderr(), "{}: error: ", ::NAME); + safe_writeln!(&mut ::std::io::stderr(), $($args),+); unsafe { self::libc::exit($exitcode as self::libc::c_int); } }) ) diff --git a/du/du.rs b/du/du.rs index 0b57be8f0..a8cdf00ce 100644 --- a/du/du.rs +++ b/du/du.rs @@ -162,8 +162,8 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, Err(f) => { - show_error!(1, "Invalid options\n{}", f.to_err_msg()); - return 0; + show_errer!("Invalid options\n{}", f.to_err_msg()); + return 1; } }; diff --git a/groups/groups.rs b/groups/groups.rs index 54abdbc92..47181bc32 100644 --- a/groups/groups.rs +++ b/groups/groups.rs @@ -36,8 +36,8 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts(args.tail(), options) { Ok(m) => { m }, Err(_) => { - show_error!(1, "{}", usage(NAME, options)); - return 0; + show_errer!("{}", usage(NAME, options)); + return 1; } }; diff --git a/hostid/hostid.rs b/hostid/hostid.rs index 38aaefd24..e89875051 100644 --- a/hostid/hostid.rs +++ b/hostid/hostid.rs @@ -36,7 +36,7 @@ mod util; static NAME: &'static str = "hostid"; static VERSION: &'static str = "0.0.1"; -static EXIT_ERR: i32 = 1; +static EXIT_ERR: int = 1; pub enum Mode { HostId, @@ -65,8 +65,8 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts(args.tail(), opts) { Ok(m) => m, Err(e) => { - show_error!(EXIT_ERR, "{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice())); - return 0; + show_errer!("{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice())); + return EXIT_ERR; }, }; diff --git a/kill/kill.rs b/kill/kill.rs index 0e48b6306..22d73fc8a 100644 --- a/kill/kill.rs +++ b/kill/kill.rs @@ -41,8 +41,8 @@ mod util; static NAME: &'static str = "kill"; static VERSION: &'static str = "0.0.1"; -static EXIT_OK: i32 = 0; -static EXIT_ERR: i32 = 1; +static EXIT_OK: int = 0; +static EXIT_ERR: int = 1; pub enum Mode { Kill, @@ -71,8 +71,8 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts(args.tail(), opts) { Ok(m) => m, Err(e) => { - show_error!(EXIT_ERR, "{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice())); - return 0 + show_errer!("{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice())); + return EXIT_ERR; }, }; @@ -128,10 +128,10 @@ fn print_signal(signal_name_or_value: &str) { for signal in ALL_SIGNALS.iter() { if signal.name == signal_name_or_value || (format!("SIG{}", signal.name).as_slice()) == signal_name_or_value { println!("{}", signal.value) - exit!(EXIT_OK) + exit!(EXIT_OK as i32) } else if signal_name_or_value == signal.value.to_str().as_slice() { println!("{}", signal.name); - exit!(EXIT_OK) + exit!(EXIT_OK as i32) } } crash!(EXIT_ERR, "unknown signal name {}", signal_name_or_value) diff --git a/mkdir/mkdir.rs b/mkdir/mkdir.rs index 288591e42..1e877c089 100644 --- a/mkdir/mkdir.rs +++ b/mkdir/mkdir.rs @@ -144,7 +144,7 @@ fn exec(dirs: Vec, mk_parents: bool, mode: FilePermission, verbose: bool } else { format!("directory '{}' already exists", *dir) }; - display_error!("{}", error_msg); + show_errer!("{}", error_msg); return Err(1); } } diff --git a/rm/rm.rs b/rm/rm.rs index 44f46e5d6..7f24fe202 100644 --- a/rm/rm.rs +++ b/rm/rm.rs @@ -79,8 +79,9 @@ pub fn uumain(args: Vec) -> int { } else if matches.opt_present("version") { println!("rm 1.0.0"); } else if matches.free.is_empty() { - show_error!(1, "missing an argument"); - show_error!(1, "for help, try '{0:s} --help'", program) + show_errer!("missing an argument"); + show_errer!("for help, try '{0:s} --help'", program); + return 0; } else { let force = matches.opt_present("force"); let interactive = @@ -116,15 +117,18 @@ pub fn uumain(args: Vec) -> int { return 0; } } - remove(matches.free, force, interactive, one_fs, preserve_root, - recursive, dir, verbose); + match remove(matches.free, force, interactive, one_fs, preserve_root, + recursive, dir, verbose) { + Ok(()) => ( /* pass */ ), + Err(e) => return e + } } return 0; } // TODO: implement one-file-system -fn remove(files: Vec, force: bool, interactive: InteractiveMode, one_fs: bool, preserve_root: bool, recursive: bool, dir: bool, verbose: bool) { +fn remove(files: Vec, force: bool, interactive: InteractiveMode, one_fs: bool, preserve_root: bool, recursive: bool, dir: bool, verbose: bool) -> Result<(), int> { for filename in files.iter() { let filename = filename.as_slice(); let file = Path::new(filename); @@ -137,30 +141,46 @@ fn remove(files: Vec, force: bool, interactive: InteractiveMode, one_fs: crash!(1, "{}", f.to_str()); } }; - remove(walk_dir.map(|x| x.as_str().unwrap().to_string()).collect(), force, interactive, one_fs, preserve_root, recursive, dir, verbose); - remove_dir(&file, filename, interactive, verbose); + match remove(walk_dir.map(|x| x.as_str().unwrap().to_string()).collect(), force, interactive, one_fs, preserve_root, recursive, dir, verbose) { + Ok(()) => ( /* pass */ ), + Err(e) => return Err(e) + } + match remove_dir(&file, filename, interactive, verbose) { + Ok(()) => ( /* pass */ ), + Err(e) => return Err(e) + } } else if dir && (filename != "/" || !preserve_root) { - remove_dir(&file, filename, interactive, verbose); + match remove_dir(&file, filename, interactive, verbose) { + Ok(()) => ( /* pass */ ), + Err(e) => return Err(e) + } } else { if recursive { - show_error!(1, "could not remove directory '{}'", + show_errer!("could not remove directory '{}'", filename); + return Err(1); } else { - show_error!(1, - "could not remove directory '{}' (did you mean to pass '-r'?)", + show_errer!("could not remove directory '{}' (did you mean to pass '-r'?)", filename); + return Err(1); } } } else { - remove_file(&file, filename.as_slice(), interactive, verbose); + match remove_file(&file, filename.as_slice(), interactive, verbose) { + Ok(()) => ( /* pass */ ), + Err(e) => return Err(e) + } } } else if !force { - show_error!(1, "no such file or directory '{}'", filename); + show_errer!("no such file or directory '{}'", filename); + return Err(1); } } + + return Ok(()); } -fn remove_dir(path: &Path, name: &str, interactive: InteractiveMode, verbose: bool) { +fn remove_dir(path: &Path, name: &str, interactive: InteractiveMode, verbose: bool) -> Result<(), int> { let response = if interactive == InteractiveAlways { prompt_file(path, name) @@ -171,13 +191,16 @@ fn remove_dir(path: &Path, name: &str, interactive: InteractiveMode, verbose: bo match fs::rmdir(path) { Ok(_) => if verbose { println!("Removed '{}'", name); }, Err(f) => { - show_error!(1, "{}", f.to_str()); + show_errer!("{}", f.to_str()); + return Err(1); } } } + + return Ok(()); } -fn remove_file(path: &Path, name: &str, interactive: InteractiveMode, verbose: bool) { +fn remove_file(path: &Path, name: &str, interactive: InteractiveMode, verbose: bool) -> Result<(), int> { let response = if interactive == InteractiveAlways { prompt_file(path, name) @@ -188,10 +211,13 @@ fn remove_file(path: &Path, name: &str, interactive: InteractiveMode, verbose: b match fs::unlink(path) { Ok(_) => if verbose { println!("Removed '{}'", name); }, Err(f) => { - show_error!(1, "{}", f.to_str()); + show_errer!("{}", f.to_str()); + return Err(1); } } } + + return Ok(()); } fn prompt_file(path: &Path, name: &str) -> bool { diff --git a/rmdir/rmdir.rs b/rmdir/rmdir.rs index cd9020900..05648e3d8 100644 --- a/rmdir/rmdir.rs +++ b/rmdir/rmdir.rs @@ -38,8 +38,8 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, Err(f) => { - show_error!(1, "{}", f.to_err_msg()); - return 0; + show_errer!("{}", f.to_err_msg()); + return 1; } }; @@ -53,39 +53,50 @@ pub fn uumain(args: Vec) -> int { } else if matches.opt_present("version") { println!("rmdir 1.0.0"); } else if matches.free.is_empty() { - show_error!(1, "missing an argument"); - show_error!(1, "for help, try '{0:s} --help'", program); + show_errer!("missing an argument"); + show_errer!("for help, try '{0:s} --help'", program); + return 1; } else { let ignore = matches.opt_present("ignore-fail-on-non-empty"); let parents = matches.opt_present("parents"); let verbose = matches.opt_present("verbose"); - remove(matches.free, ignore, parents, verbose); + match remove(matches.free, ignore, parents, verbose) { + Ok(()) => ( /* pass */ ), + Err(e) => return e + } } return 0; } -fn remove(dirs: Vec, ignore: bool, parents: bool, verbose: bool) { +fn remove(dirs: Vec, ignore: bool, parents: bool, verbose: bool) -> Result<(), int>{ for dir in dirs.iter() { let path = Path::new(dir.as_slice()); if path.exists() { if path.is_dir() { - remove_dir(&path, dir.as_slice(), ignore, parents, verbose); + match remove_dir(&path, dir.as_slice(), ignore, parents, verbose) { + Ok(()) => ( /* pass */ ), + Err(e) => return Err(e) + } } else { - show_error!(1, "failed to remove '{}' (file)", *dir); + show_errer!("failed to remove '{}' (file)", *dir); + return Err(1); } } else { - show_error!(1, "no such file or directory '{}'", *dir); + show_errer!("no such file or directory '{}'", *dir); + return Err(1); } } + + return Ok(()); } -fn remove_dir(path: &Path, dir: &str, ignore: bool, parents: bool, verbose: bool) { +fn remove_dir(path: &Path, dir: &str, ignore: bool, parents: bool, verbose: bool) -> Result<(), int> { let mut walk_dir = match fs::walk_dir(path) { Ok(m) => m, Err(f) => { - show_error!(1, "{}", f.to_str()); - return; + show_errer!("{}", f.to_str()); + return Err(1); } }; if walk_dir.next() == None { @@ -97,16 +108,23 @@ fn remove_dir(path: &Path, dir: &str, ignore: bool, parents: bool, verbose: bool if parents { let dirname = path.dirname_str().unwrap(); if dirname != "." { - remove_dir(&Path::new(dirname), dirname, ignore, parents, verbose); + match remove_dir(&Path::new(dirname), dirname, ignore, parents, verbose) { + Ok(()) => ( /* pass */ ), + Err(e) => return Err(e) + } } } } Err(f) => { - show_error!(1, "{}", f.to_str()); + show_errer!("{}", f.to_str()); + return Err(1); } } } else if !ignore { - show_error!(1, "Failed to remove directory '{}' (non-empty)", dir); + show_errer!("Failed to remove directory '{}' (non-empty)", dir); + return Err(1); } + + return Ok(()); } diff --git a/seq/seq.rs b/seq/seq.rs index f0d068a87..2f3f48c5b 100644 --- a/seq/seq.rs +++ b/seq/seq.rs @@ -47,9 +47,9 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => { m } Err(f) => { - show_error!(1, "{:s}", f.to_err_msg()); + show_errer!("{:s}", f.to_err_msg()); print_usage(opts); - return 0; + return 1; } }; if matches.opt_present("help") { @@ -67,7 +67,7 @@ pub fn uumain(args: Vec) -> int { let first = if matches.free.len() > 1 { match parse_float(matches.free.get(0).as_slice()) { Ok(n) => n, - Err(s) => { show_error!(1, "{:s}", s); return 0; } + Err(s) => { show_errer!("{:s}", s); return 1; } } } else { 1.0 @@ -75,14 +75,14 @@ pub fn uumain(args: Vec) -> int { let step = if matches.free.len() > 2 { match parse_float(matches.free.get(1).as_slice()) { Ok(n) => n, - Err(s) => { show_error!(1, "{:s}", s); return 0; } + Err(s) => { show_errer!("{:s}", s); return 1; } } } else { 1.0 }; let last = match parse_float(matches.free.get(matches.free.len()-1).as_slice()) { Ok(n) => n, - Err(s) => { show_error!(1, "{:s}", s); return 0; } + Err(s) => { show_errer!("{:s}", s); return 1; } }; let separator = escape_sequences(matches.opt_str("s").unwrap_or("\n".to_string()).as_slice()); let terminator = escape_sequences(matches.opt_str("t").unwrap_or(separator.to_string()).as_slice()); diff --git a/sleep/sleep.rs b/sleep/sleep.rs index 64c3f0828..0a5253ecc 100644 --- a/sleep/sleep.rs +++ b/sleep/sleep.rs @@ -36,8 +36,8 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, Err(f) => { - show_error!(1, "{}", f.to_err_msg()); - return 0; + show_errer!("{}", f.to_err_msg()); + return 1; } }; @@ -57,8 +57,9 @@ specified by the sum of their values.", opts).as_slice()); } else if matches.opt_present("version") { println!("sleep 1.0.0"); } else if matches.free.is_empty() { - show_error!(1, "missing an argument"); - show_error!(1, "for help, try '{0:s} --help'", program); + show_errer!("missing an argument"); + show_errer!("for help, try '{0:s} --help'", program); + return 1; } else { sleep(matches.free); } diff --git a/tr/tr.rs b/tr/tr.rs index 48af9ed4a..3cc7a36e1 100644 --- a/tr/tr.rs +++ b/tr/tr.rs @@ -161,8 +161,8 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, Err(err) => { - show_error!(1, "{}", err.to_err_msg()); - return 0; + show_errer!("{}", err.to_err_msg()); + return 1; } }; @@ -186,8 +186,8 @@ pub fn uumain(args: Vec) -> int { let sets = matches.free; if cflag && !dflag { - show_error!(1, "-c is only supported with -d"); - return 0; + show_errer!("-c is only supported with -d"); + return 1; } if dflag { diff --git a/truncate/truncate.rs b/truncate/truncate.rs index fd9f3dbea..4bf395af7 100644 --- a/truncate/truncate.rs +++ b/truncate/truncate.rs @@ -21,18 +21,6 @@ use std::u64; #[path = "../common/util.rs"] mod util; -macro_rules! get_file_size( - ($file:ident, $action:expr) => ({ - match fs::stat($file.path()) { - Ok(stat) => stat.size, - Err(f) => { - show_error!(1, "{}", f.to_str()); - $action - } - } - }) -) - #[deriving(Eq, PartialEq)] enum TruncateMode { Reference, @@ -95,8 +83,8 @@ file based on its current size: } else if matches.opt_present("version") { println!("truncate 1.0.0"); } else if matches.free.is_empty() { - show_error!(1, "missing an argument"); - crash!(1, "for help, try '{0:s} --help'", program); + show_errer!("missing an argument"); + return 1; } else { let no_create = matches.opt_present("no-create"); let io_blocks = matches.opt_present("io-blocks"); @@ -105,14 +93,17 @@ file based on its current size: if reference.is_none() && size.is_none() { crash!(1, "you must specify either --reference or --size"); } else { - truncate(no_create, io_blocks, reference, size, matches.free); + match truncate(no_create, io_blocks, reference, size, matches.free) { + Ok(()) => ( /* pass */ ), + Err(e) => return e + } } } return 0; } -fn truncate(no_create: bool, _: bool, reference: Option, size: Option, filenames: Vec) { +fn truncate(no_create: bool, _: bool, reference: Option, size: Option, filenames: Vec) -> Result<(), int> { let (refsize, mode) = match reference { Some(rfilename) => { let rfile = match File::open(&Path::new(rfilename.clone())) { @@ -121,7 +112,13 @@ fn truncate(no_create: bool, _: bool, reference: Option, size: Option (stat.size, Reference), + Err(f) => { + show_errer!("{}", f.to_str()); + return Err(1); + } + } } None => parse_size(size.unwrap().as_slice()) }; @@ -131,7 +128,13 @@ fn truncate(no_create: bool, _: bool, reference: Option, size: Option { - let fsize = get_file_size!(file, continue); + let fsize = match fs::stat(file.path()) { + Ok(stat) => stat.size, + Err(f) => { + show_warning!("{}", f.to_str()); + continue; + } + }; let tsize = match mode { Reference => refsize, Extend => fsize + refsize, @@ -144,16 +147,19 @@ fn truncate(no_create: bool, _: bool, reference: Option, size: Option {} Err(f) => { - show_error!(1, "{}", f.to_str()); + show_errer!("{}", f.to_str()); + return Err(1); } } } Err(f) => { - show_error!(1, "{}", f.to_str()); + show_errer!("{}", f.to_str()); + return Err(1); } } } } + return Ok(()); } fn parse_size(size: &str) -> (u64, TruncateMode) { diff --git a/wc/wc.rs b/wc/wc.rs index bfd4d1597..2905a9702 100644 --- a/wc/wc.rs +++ b/wc/wc.rs @@ -17,6 +17,7 @@ extern crate libc; use std::os; use std::str::from_utf8; use std::io::{print, stdin, File, BufferedReader}; +use StdResult = std::result::Result; use getopts::Matches; #[path = "../common/util.rs"] @@ -75,7 +76,10 @@ pub fn uumain(args: Vec) -> int { files = vec!("-".to_string()); } - wc(files, &matches); + match wc(files, &matches) { + Ok(()) => ( /* pass */ ), + Err(e) => return e + } return 0; } @@ -91,7 +95,7 @@ fn is_word_seperator(byte: u8) -> bool { byte == SPACE || byte == TAB || byte == CR || byte == SYN || byte == FF } -pub fn wc(files: Vec, matches: &Matches) { +pub fn wc(files: Vec, matches: &Matches) -> StdResult<(), int> { let mut total_line_count: uint = 0; let mut total_word_count: uint = 0; let mut total_char_count: uint = 0; @@ -103,8 +107,8 @@ pub fn wc(files: Vec, matches: &Matches) { for path in files.iter() { let mut reader = match open(path.to_string()) { - Some(f) => f, - None => { continue } + Ok(f) => f, + Err(e) => { return Err(e); } }; let mut line_count: uint = 0; @@ -187,6 +191,8 @@ pub fn wc(files: Vec, matches: &Matches) { if files.len() > 1 { print_stats("total", total_line_count, total_word_count, total_char_count, total_byte_count, total_longest_line_length, matches, max_str_len); } + + return Ok(()); } fn print_stats(filename: &str, line_count: uint, word_count: uint, char_count: uint, @@ -226,21 +232,20 @@ fn print_stats(filename: &str, line_count: uint, word_count: uint, char_count: u } } -fn open(path: String) -> Option>> { +fn open(path: String) -> StdResult>, int> { if "-" == path.as_slice() { let reader = box stdin() as Box; - return Some(BufferedReader::new(reader)); + return Ok(BufferedReader::new(reader)); } match File::open(&std::path::Path::new(path.as_slice())) { Ok(fd) => { let reader = box fd as Box; - return Some(BufferedReader::new(reader)); + return Ok(BufferedReader::new(reader)); }, Err(e) => { - show_error!(1, "wc: {0:s}: {1:s}", path, e.desc.to_str()); + show_errer!("wc: {0:s}: {1:s}", path, e.desc.to_str()); + return Err(1); } } - - None } From 18acfc010375dff64ff4b62582a72576bd83bc06 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 8 Jun 2014 19:03:38 -0700 Subject: [PATCH 05/10] Make busytest stop complaining about missing config file --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3a6bba447..8ef8504e8 100644 --- a/Makefile +++ b/Makefile @@ -145,6 +145,11 @@ build/busybox: build/uutils rm -f build/busybox ln -s $(SRC_DIR)/build/uutils build/busybox +# This is a busybox-specific config file their test suite wants to parse. +# For now it's blank. +build/.config: build/uutils + touch $@ + ifeq ($(BUSYBOX_SRC),) busytest: @echo @@ -153,7 +158,7 @@ busytest: @echo @false else -busytest: build/busybox +busytest: build/busybox build/.config (cd $(BUSYBOX_SRC)/testsuite && bindir=$(SRC_DIR)/build tstdir=$(BUSYBOX_SRC)/testsuite $(BUSYBOX_SRC)/testsuite/runtest $(RUNTEST_ARGS)) endif endif From 4731928558b9482f989f430a910d95f9908dcccf Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Sun, 8 Jun 2014 20:26:51 -0700 Subject: [PATCH 06/10] Fix typo --- cksum/cksum.rs | 4 ++-- common/util.rs | 2 +- du/du.rs | 2 +- groups/groups.rs | 2 +- hostid/hostid.rs | 2 +- kill/kill.rs | 2 +- mkdir/mkdir.rs | 2 +- rm/rm.rs | 14 +++++++------- rmdir/rmdir.rs | 16 ++++++++-------- seq/seq.rs | 8 ++++---- sleep/sleep.rs | 6 +++--- tr/tr.rs | 4 ++-- truncate/truncate.rs | 8 ++++---- wc/wc.rs | 2 +- 14 files changed, 37 insertions(+), 37 deletions(-) diff --git a/cksum/cksum.rs b/cksum/cksum.rs index e8dbf4aa7..dddf6bf7f 100644 --- a/cksum/cksum.rs +++ b/cksum/cksum.rs @@ -112,7 +112,7 @@ pub fn uumain(args: Vec) -> int { match cksum("-") { Ok((crc, size)) => println!("{} {}", crc, size), Err(err) => { - show_errer!("{}", err); + show_error!("{}", err); return 2; } } @@ -123,7 +123,7 @@ pub fn uumain(args: Vec) -> int { match cksum(fname.as_slice()) { Ok((crc, size)) => println!("{} {} {}", crc, size, fname), Err(err) => { - show_errer!("'{}' {}", fname, err); + show_error!("'{}' {}", fname, err); return 2; } } diff --git a/common/util.rs b/common/util.rs index dc12fd26c..d5e65c7f6 100644 --- a/common/util.rs +++ b/common/util.rs @@ -12,7 +12,7 @@ extern crate libc; #[macro_export] -macro_rules! show_errer( +macro_rules! show_error( ($($args:expr),+) => ({ safe_write!(&mut ::std::io::stderr(), "{}: error: ", ::NAME); safe_writeln!(&mut ::std::io::stderr(), $($args),+); diff --git a/du/du.rs b/du/du.rs index a8cdf00ce..eb14aea99 100644 --- a/du/du.rs +++ b/du/du.rs @@ -162,7 +162,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, Err(f) => { - show_errer!("Invalid options\n{}", f.to_err_msg()); + show_error!("Invalid options\n{}", f.to_err_msg()); return 1; } }; diff --git a/groups/groups.rs b/groups/groups.rs index 47181bc32..b678099b2 100644 --- a/groups/groups.rs +++ b/groups/groups.rs @@ -36,7 +36,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts(args.tail(), options) { Ok(m) => { m }, Err(_) => { - show_errer!("{}", usage(NAME, options)); + show_error!("{}", usage(NAME, options)); return 1; } }; diff --git a/hostid/hostid.rs b/hostid/hostid.rs index e89875051..341f0aefc 100644 --- a/hostid/hostid.rs +++ b/hostid/hostid.rs @@ -65,7 +65,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts(args.tail(), opts) { Ok(m) => m, Err(e) => { - show_errer!("{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice())); + show_error!("{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice())); return EXIT_ERR; }, }; diff --git a/kill/kill.rs b/kill/kill.rs index 22d73fc8a..f38f37e8d 100644 --- a/kill/kill.rs +++ b/kill/kill.rs @@ -71,7 +71,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts(args.tail(), opts) { Ok(m) => m, Err(e) => { - show_errer!("{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice())); + show_error!("{}\n{}", e.to_err_msg(), get_help_text(NAME, usage.as_slice())); return EXIT_ERR; }, }; diff --git a/mkdir/mkdir.rs b/mkdir/mkdir.rs index 1e877c089..06f60b5f7 100644 --- a/mkdir/mkdir.rs +++ b/mkdir/mkdir.rs @@ -144,7 +144,7 @@ fn exec(dirs: Vec, mk_parents: bool, mode: FilePermission, verbose: bool } else { format!("directory '{}' already exists", *dir) }; - show_errer!("{}", error_msg); + show_error!("{}", error_msg); return Err(1); } } diff --git a/rm/rm.rs b/rm/rm.rs index 7f24fe202..c3d120eb6 100644 --- a/rm/rm.rs +++ b/rm/rm.rs @@ -79,8 +79,8 @@ pub fn uumain(args: Vec) -> int { } else if matches.opt_present("version") { println!("rm 1.0.0"); } else if matches.free.is_empty() { - show_errer!("missing an argument"); - show_errer!("for help, try '{0:s} --help'", program); + show_error!("missing an argument"); + show_error!("for help, try '{0:s} --help'", program); return 0; } else { let force = matches.opt_present("force"); @@ -156,11 +156,11 @@ fn remove(files: Vec, force: bool, interactive: InteractiveMode, one_fs: } } else { if recursive { - show_errer!("could not remove directory '{}'", + show_error!("could not remove directory '{}'", filename); return Err(1); } else { - show_errer!("could not remove directory '{}' (did you mean to pass '-r'?)", + show_error!("could not remove directory '{}' (did you mean to pass '-r'?)", filename); return Err(1); } @@ -172,7 +172,7 @@ fn remove(files: Vec, force: bool, interactive: InteractiveMode, one_fs: } } } else if !force { - show_errer!("no such file or directory '{}'", filename); + show_error!("no such file or directory '{}'", filename); return Err(1); } } @@ -191,7 +191,7 @@ fn remove_dir(path: &Path, name: &str, interactive: InteractiveMode, verbose: bo match fs::rmdir(path) { Ok(_) => if verbose { println!("Removed '{}'", name); }, Err(f) => { - show_errer!("{}", f.to_str()); + show_error!("{}", f.to_str()); return Err(1); } } @@ -211,7 +211,7 @@ fn remove_file(path: &Path, name: &str, interactive: InteractiveMode, verbose: b match fs::unlink(path) { Ok(_) => if verbose { println!("Removed '{}'", name); }, Err(f) => { - show_errer!("{}", f.to_str()); + show_error!("{}", f.to_str()); return Err(1); } } diff --git a/rmdir/rmdir.rs b/rmdir/rmdir.rs index 05648e3d8..ee6d2a25a 100644 --- a/rmdir/rmdir.rs +++ b/rmdir/rmdir.rs @@ -38,7 +38,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, Err(f) => { - show_errer!("{}", f.to_err_msg()); + show_error!("{}", f.to_err_msg()); return 1; } }; @@ -53,8 +53,8 @@ pub fn uumain(args: Vec) -> int { } else if matches.opt_present("version") { println!("rmdir 1.0.0"); } else if matches.free.is_empty() { - show_errer!("missing an argument"); - show_errer!("for help, try '{0:s} --help'", program); + show_error!("missing an argument"); + show_error!("for help, try '{0:s} --help'", program); return 1; } else { let ignore = matches.opt_present("ignore-fail-on-non-empty"); @@ -79,11 +79,11 @@ fn remove(dirs: Vec, ignore: bool, parents: bool, verbose: bool) -> Resu Err(e) => return Err(e) } } else { - show_errer!("failed to remove '{}' (file)", *dir); + show_error!("failed to remove '{}' (file)", *dir); return Err(1); } } else { - show_errer!("no such file or directory '{}'", *dir); + show_error!("no such file or directory '{}'", *dir); return Err(1); } } @@ -95,7 +95,7 @@ fn remove_dir(path: &Path, dir: &str, ignore: bool, parents: bool, verbose: bool let mut walk_dir = match fs::walk_dir(path) { Ok(m) => m, Err(f) => { - show_errer!("{}", f.to_str()); + show_error!("{}", f.to_str()); return Err(1); } }; @@ -116,12 +116,12 @@ fn remove_dir(path: &Path, dir: &str, ignore: bool, parents: bool, verbose: bool } } Err(f) => { - show_errer!("{}", f.to_str()); + show_error!("{}", f.to_str()); return Err(1); } } } else if !ignore { - show_errer!("Failed to remove directory '{}' (non-empty)", dir); + show_error!("Failed to remove directory '{}' (non-empty)", dir); return Err(1); } diff --git a/seq/seq.rs b/seq/seq.rs index 2f3f48c5b..bc9ddc353 100644 --- a/seq/seq.rs +++ b/seq/seq.rs @@ -47,7 +47,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => { m } Err(f) => { - show_errer!("{:s}", f.to_err_msg()); + show_error!("{:s}", f.to_err_msg()); print_usage(opts); return 1; } @@ -67,7 +67,7 @@ pub fn uumain(args: Vec) -> int { let first = if matches.free.len() > 1 { match parse_float(matches.free.get(0).as_slice()) { Ok(n) => n, - Err(s) => { show_errer!("{:s}", s); return 1; } + Err(s) => { show_error!("{:s}", s); return 1; } } } else { 1.0 @@ -75,14 +75,14 @@ pub fn uumain(args: Vec) -> int { let step = if matches.free.len() > 2 { match parse_float(matches.free.get(1).as_slice()) { Ok(n) => n, - Err(s) => { show_errer!("{:s}", s); return 1; } + Err(s) => { show_error!("{:s}", s); return 1; } } } else { 1.0 }; let last = match parse_float(matches.free.get(matches.free.len()-1).as_slice()) { Ok(n) => n, - Err(s) => { show_errer!("{:s}", s); return 1; } + Err(s) => { show_error!("{:s}", s); return 1; } }; let separator = escape_sequences(matches.opt_str("s").unwrap_or("\n".to_string()).as_slice()); let terminator = escape_sequences(matches.opt_str("t").unwrap_or(separator.to_string()).as_slice()); diff --git a/sleep/sleep.rs b/sleep/sleep.rs index 0a5253ecc..f5b0fb756 100644 --- a/sleep/sleep.rs +++ b/sleep/sleep.rs @@ -36,7 +36,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, Err(f) => { - show_errer!("{}", f.to_err_msg()); + show_error!("{}", f.to_err_msg()); return 1; } }; @@ -57,8 +57,8 @@ specified by the sum of their values.", opts).as_slice()); } else if matches.opt_present("version") { println!("sleep 1.0.0"); } else if matches.free.is_empty() { - show_errer!("missing an argument"); - show_errer!("for help, try '{0:s} --help'", program); + show_error!("missing an argument"); + show_error!("for help, try '{0:s} --help'", program); return 1; } else { sleep(matches.free); diff --git a/tr/tr.rs b/tr/tr.rs index 3cc7a36e1..f52d2a6bc 100644 --- a/tr/tr.rs +++ b/tr/tr.rs @@ -161,7 +161,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, Err(err) => { - show_errer!("{}", err.to_err_msg()); + show_error!("{}", err.to_err_msg()); return 1; } }; @@ -186,7 +186,7 @@ pub fn uumain(args: Vec) -> int { let sets = matches.free; if cflag && !dflag { - show_errer!("-c is only supported with -d"); + show_error!("-c is only supported with -d"); return 1; } diff --git a/truncate/truncate.rs b/truncate/truncate.rs index 4bf395af7..8cf886014 100644 --- a/truncate/truncate.rs +++ b/truncate/truncate.rs @@ -83,7 +83,7 @@ file based on its current size: } else if matches.opt_present("version") { println!("truncate 1.0.0"); } else if matches.free.is_empty() { - show_errer!("missing an argument"); + show_error!("missing an argument"); return 1; } else { let no_create = matches.opt_present("no-create"); @@ -115,7 +115,7 @@ fn truncate(no_create: bool, _: bool, reference: Option, size: Option (stat.size, Reference), Err(f) => { - show_errer!("{}", f.to_str()); + show_error!("{}", f.to_str()); return Err(1); } } @@ -147,13 +147,13 @@ fn truncate(no_create: bool, _: bool, reference: Option, size: Option {} Err(f) => { - show_errer!("{}", f.to_str()); + show_error!("{}", f.to_str()); return Err(1); } } } Err(f) => { - show_errer!("{}", f.to_str()); + show_error!("{}", f.to_str()); return Err(1); } } diff --git a/wc/wc.rs b/wc/wc.rs index 2905a9702..9ab77c68d 100644 --- a/wc/wc.rs +++ b/wc/wc.rs @@ -244,7 +244,7 @@ fn open(path: String) -> StdResult>, int> { return Ok(BufferedReader::new(reader)); }, Err(e) => { - show_errer!("wc: {0:s}: {1:s}", path, e.desc.to_str()); + show_error!("wc: {0:s}: {1:s}", path, e.desc.to_str()); return Err(1); } } From 04fb170c2cd516c11dc6e1e0a6baf2ad81c606a0 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 9 Jun 2014 22:30:54 -0700 Subject: [PATCH 07/10] Restore error recovery behavior in rm, rmdir, etc. These tools continue on error. This patch uses `Result` and the `and` method to collect `Err` values. --- cksum/cksum.rs | 5 +++-- mkdir/mkdir.rs | 8 +++++--- rm/rm.rs | 32 +++++++++++--------------------- rmdir/rmdir.rs | 27 +++++++++++++-------------- 4 files changed, 32 insertions(+), 40 deletions(-) diff --git a/cksum/cksum.rs b/cksum/cksum.rs index dddf6bf7f..e832c2911 100644 --- a/cksum/cksum.rs +++ b/cksum/cksum.rs @@ -119,15 +119,16 @@ pub fn uumain(args: Vec) -> int { return 0; } + let mut exit_code = 0; for fname in files.iter() { match cksum(fname.as_slice()) { Ok((crc, size)) => println!("{} {} {}", crc, size, fname), Err(err) => { show_error!("'{}' {}", fname, err); - return 2; + exit_code = 2; } } } - return 0; + return exit_code; } diff --git a/mkdir/mkdir.rs b/mkdir/mkdir.rs index 06f60b5f7..5fef9b8ad 100644 --- a/mkdir/mkdir.rs +++ b/mkdir/mkdir.rs @@ -101,6 +101,8 @@ fn print_help(opts: &[getopts::OptGroup]) { * Create the list of new directories */ fn exec(dirs: Vec, mk_parents: bool, mode: FilePermission, verbose: bool) -> Result<(), int> { + let mut result = Ok(()); + let mut parent_dirs = Vec::new(); if mk_parents { for dir in dirs.iter() { @@ -121,7 +123,7 @@ fn exec(dirs: Vec, mk_parents: bool, mode: FilePermission, verbose: bool if !parent_dirs.is_empty() { match exec(parent_dirs, mk_parents, mode, verbose) { Ok(()) => ( /* keep going */ ), - Err(e) => return Err(e) + Err(e) => result = Err(e) } } @@ -145,11 +147,11 @@ fn exec(dirs: Vec, mk_parents: bool, mode: FilePermission, verbose: bool format!("directory '{}' already exists", *dir) }; show_error!("{}", error_msg); - return Err(1); + result = Err(1) } } - return Ok(()); + return result; } /** diff --git a/rm/rm.rs b/rm/rm.rs index c3d120eb6..a37511303 100644 --- a/rm/rm.rs +++ b/rm/rm.rs @@ -81,7 +81,7 @@ pub fn uumain(args: Vec) -> int { } else if matches.free.is_empty() { show_error!("missing an argument"); show_error!("for help, try '{0:s} --help'", program); - return 0; + return 1; } else { let force = matches.opt_present("force"); let interactive = @@ -129,6 +129,8 @@ pub fn uumain(args: Vec) -> int { // TODO: implement one-file-system fn remove(files: Vec, force: bool, interactive: InteractiveMode, one_fs: bool, preserve_root: bool, recursive: bool, dir: bool, verbose: bool) -> Result<(), int> { + let mut r = Ok(()); + for filename in files.iter() { let filename = filename.as_slice(); let file = Path::new(filename); @@ -141,43 +143,31 @@ fn remove(files: Vec, force: bool, interactive: InteractiveMode, one_fs: crash!(1, "{}", f.to_str()); } }; - match remove(walk_dir.map(|x| x.as_str().unwrap().to_string()).collect(), force, interactive, one_fs, preserve_root, recursive, dir, verbose) { - Ok(()) => ( /* pass */ ), - Err(e) => return Err(e) - } - match remove_dir(&file, filename, interactive, verbose) { - Ok(()) => ( /* pass */ ), - Err(e) => return Err(e) - } + r = remove(walk_dir.map(|x| x.as_str().unwrap().to_string()).collect(), force, interactive, one_fs, preserve_root, recursive, dir, verbose).and(r); + r = remove_dir(&file, filename, interactive, verbose).and(r); } else if dir && (filename != "/" || !preserve_root) { - match remove_dir(&file, filename, interactive, verbose) { - Ok(()) => ( /* pass */ ), - Err(e) => return Err(e) - } + r = remove_dir(&file, filename, interactive, verbose).and(r); } else { if recursive { show_error!("could not remove directory '{}'", filename); - return Err(1); + r = Err(1); } else { show_error!("could not remove directory '{}' (did you mean to pass '-r'?)", filename); - return Err(1); + r = Err(1); } } } else { - match remove_file(&file, filename.as_slice(), interactive, verbose) { - Ok(()) => ( /* pass */ ), - Err(e) => return Err(e) - } + r = remove_file(&file, filename.as_slice(), interactive, verbose).and(r); } } else if !force { show_error!("no such file or directory '{}'", filename); - return Err(1); + r = Err(1); } } - return Ok(()); + return r; } fn remove_dir(path: &Path, name: &str, interactive: InteractiveMode, verbose: bool) -> Result<(), int> { diff --git a/rmdir/rmdir.rs b/rmdir/rmdir.rs index ee6d2a25a..56a51110e 100644 --- a/rmdir/rmdir.rs +++ b/rmdir/rmdir.rs @@ -70,25 +70,24 @@ pub fn uumain(args: Vec) -> int { } fn remove(dirs: Vec, ignore: bool, parents: bool, verbose: bool) -> Result<(), int>{ + let mut r = Ok(()); + for dir in dirs.iter() { let path = Path::new(dir.as_slice()); if path.exists() { if path.is_dir() { - match remove_dir(&path, dir.as_slice(), ignore, parents, verbose) { - Ok(()) => ( /* pass */ ), - Err(e) => return Err(e) - } + r = remove_dir(&path, dir.as_slice(), ignore, parents, verbose).and(r); } else { show_error!("failed to remove '{}' (file)", *dir); - return Err(1); + r = Err(1); } } else { show_error!("no such file or directory '{}'", *dir); - return Err(1); + r = Err(1); } } - return Ok(()); + return r; } fn remove_dir(path: &Path, dir: &str, ignore: bool, parents: bool, verbose: bool) -> Result<(), int> { @@ -99,6 +98,9 @@ fn remove_dir(path: &Path, dir: &str, ignore: bool, parents: bool, verbose: bool return Err(1); } }; + + let mut r = Ok(()); + if walk_dir.next() == None { match fs::rmdir(path) { Ok(_) => { @@ -108,23 +110,20 @@ fn remove_dir(path: &Path, dir: &str, ignore: bool, parents: bool, verbose: bool if parents { let dirname = path.dirname_str().unwrap(); if dirname != "." { - match remove_dir(&Path::new(dirname), dirname, ignore, parents, verbose) { - Ok(()) => ( /* pass */ ), - Err(e) => return Err(e) - } + r = remove_dir(&Path::new(dirname), dirname, ignore, parents, verbose).and(r); } } } Err(f) => { show_error!("{}", f.to_str()); - return Err(1); + r = Err(1); } } } else if !ignore { show_error!("Failed to remove directory '{}' (non-empty)", dir); - return Err(1); + r = Err(1); } - return Ok(()); + return r; } From 1adc027382fef2c82c6b71e712e4fe27334f0a16 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 11 Jun 2014 21:29:32 -0700 Subject: [PATCH 08/10] Restore error handling to md5sum --- md5sum/md5sum.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/md5sum/md5sum.rs b/md5sum/md5sum.rs index 25c0f0b78..369d1b3ab 100644 --- a/md5sum/md5sum.rs +++ b/md5sum/md5sum.rs @@ -128,7 +128,6 @@ fn md5sum(files: Vec, binary: bool, check: bool, tag: bool, status: bool println!("{}: FAILED", ck_filename); } failed += 1; - return Err(1); } } } else { From bad19f60169d9127ffece94995e1c594debc3593 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 11 Jun 2014 21:41:53 -0700 Subject: [PATCH 09/10] Remove tail return statements. Per review feedback. --- base64/base64.rs | 2 +- basename/basename.rs | 6 +++--- cat/cat.rs | 8 ++++---- cksum/cksum.rs | 2 +- comm/comm.rs | 2 +- cp/cp.rs | 2 +- dirname/dirname.rs | 2 +- du/du.rs | 4 ++-- echo/echo.rs | 5 +++-- env/env.rs | 2 +- fold/fold.rs | 2 +- groups/groups.rs | 2 +- head/head.rs | 2 +- hostid/hostid.rs | 2 +- hostname/hostname.rs | 2 +- id/id.rs | 2 +- kill/kill.rs | 4 ++-- logname/logname.rs | 2 +- md5sum/md5sum.rs | 4 ++-- mkdir/mkdir.rs | 6 +++--- paste/paste.rs | 2 +- printenv/printenv.rs | 2 +- pwd/pwd.rs | 2 +- rm/rm.rs | 8 ++++---- rmdir/rmdir.rs | 6 +++--- seq/seq.rs | 2 +- sleep/sleep.rs | 2 +- sum/sum.rs | 2 +- tac/tac.rs | 2 +- touch/touch.rs | 2 +- tr/tr.rs | 2 +- truncate/truncate.rs | 4 ++-- tty/tty.rs | 2 +- uname/uname.rs | 2 +- unlink/unlink.rs | 2 +- uptime/uptime.rs | 2 +- users/users.rs | 2 +- wc/wc.rs | 8 ++++---- whoami/whoami.rs | 2 +- yes/yes.rs | 2 +- 40 files changed, 61 insertions(+), 60 deletions(-) diff --git a/base64/base64.rs b/base64/base64.rs index b42010304..2098c0471 100644 --- a/base64/base64.rs +++ b/base64/base64.rs @@ -89,7 +89,7 @@ pub fn uumain(args: Vec) -> int { Version => version() } - return 0; + 0 } #[allow(dead_code)] diff --git a/basename/basename.rs b/basename/basename.rs index 8f5b2f3ee..6fdb51e54 100644 --- a/basename/basename.rs +++ b/basename/basename.rs @@ -86,7 +86,7 @@ pub fn uumain(args: Vec) -> int { println(name.as_slice()); - return 0; + 0 } fn strip_dir(fullname: &str) -> String { @@ -99,7 +99,7 @@ fn strip_dir(fullname: &str) -> String { name.push_char(c); } - return name.as_slice().chars().rev().collect(); + name.as_slice().chars().rev().collect() } fn strip_suffix(name: &str, suffix: &str) -> String { @@ -111,5 +111,5 @@ fn strip_suffix(name: &str, suffix: &str) -> String { return name.slice_to(name.len() - suffix.len()).into_string(); } - return name.into_string(); + name.into_string() } diff --git a/cat/cat.rs b/cat/cat.rs index ba8fad3f5..79caf0960 100644 --- a/cat/cat.rs +++ b/cat/cat.rs @@ -81,7 +81,7 @@ pub fn uumain(args: Vec) -> int { exec(files, number_mode, show_nonprint, show_ends, show_tabs, squeeze_blank); - return 0; + 0 } #[deriving(Eq, PartialEq)] @@ -285,12 +285,12 @@ fn open(path: &str) -> Option<(Box, bool)> { } match File::open(&std::path::Path::new(path)) { - Ok(f) => return Some((box f as Box, false)), + Ok(f) => Some((box f as Box, false)), Err(e) => { (writeln!(stderr(), "cat: {0:s}: {1:s}", path, e.to_str())).unwrap(); - return None; + None }, - }; + } } struct UnsafeWriter<'a, W> { diff --git a/cksum/cksum.rs b/cksum/cksum.rs index e832c2911..8d1d5cba0 100644 --- a/cksum/cksum.rs +++ b/cksum/cksum.rs @@ -130,5 +130,5 @@ pub fn uumain(args: Vec) -> int { } } - return exit_code; + exit_code } diff --git a/comm/comm.rs b/comm/comm.rs index e2d669777..df5137516 100644 --- a/comm/comm.rs +++ b/comm/comm.rs @@ -136,5 +136,5 @@ pub fn uumain(args: Vec) -> int { comm(&mut f1, &mut f2, &matches); - return 0; + 0 } diff --git a/cp/cp.rs b/cp/cp.rs index b23eb2c6a..2bdc19fb9 100644 --- a/cp/cp.rs +++ b/cp/cp.rs @@ -63,7 +63,7 @@ pub fn uumain(args: Vec) -> int { Version => version(), } - return 0; + 0 } fn version() { diff --git a/dirname/dirname.rs b/dirname/dirname.rs index 65a830793..3e6714f23 100644 --- a/dirname/dirname.rs +++ b/dirname/dirname.rs @@ -68,5 +68,5 @@ directory).", opts).as_slice()); println!("Try '{0:s} --help' for more information.", program); } - return 0; + 0 } diff --git a/du/du.rs b/du/du.rs index eb14aea99..36abca4df 100644 --- a/du/du.rs +++ b/du/du.rs @@ -86,7 +86,7 @@ fn du(path: &Path, mut my_stat: Stat, stats.push(Arc::new(my_stat)); - return stats; + stats } #[allow(dead_code)] @@ -367,5 +367,5 @@ Try '{program} --help' for more information.", s, program = program); print!("{}", line_separator); } - return 0; + 0 } diff --git a/echo/echo.rs b/echo/echo.rs index 4d57d19a7..f8edf5175 100644 --- a/echo/echo.rs +++ b/echo/echo.rs @@ -66,7 +66,8 @@ fn convert_str(string: &str, index: uint, base: uint) -> (char, int) { } } } - return (to_char(&bytes, base), max_digits) + + (to_char(&bytes, base), max_digits) } #[allow(dead_code)] @@ -187,5 +188,5 @@ pub fn uumain(args: Vec) -> int { println!("") } - return 0; + 0 } diff --git a/env/env.rs b/env/env.rs index c02b962f3..f2434974d 100644 --- a/env/env.rs +++ b/env/env.rs @@ -211,5 +211,5 @@ pub fn uumain(args: Vec) -> int { print_env(opts.null); } - return 0; + 0 } diff --git a/fold/fold.rs b/fold/fold.rs index 5818e0fb8..711bc879e 100644 --- a/fold/fold.rs +++ b/fold/fold.rs @@ -83,7 +83,7 @@ pub fn uumain(args: Vec) -> int { fold(files, bytes, spaces, width); } - return 0; + 0 } fn handle_obsolete(args: &[String]) -> (Vec, Option) { diff --git a/groups/groups.rs b/groups/groups.rs index b678099b2..abb770972 100644 --- a/groups/groups.rs +++ b/groups/groups.rs @@ -43,5 +43,5 @@ pub fn uumain(args: Vec) -> int { group(get_pw_from_args(&matches.free), true); - return 0; + 0 } diff --git a/head/head.rs b/head/head.rs index 6840588a4..37adad266 100644 --- a/head/head.rs +++ b/head/head.rs @@ -94,7 +94,7 @@ pub fn uumain(args: Vec) -> int { } } - return 0; + 0 } // It searches for an option in the form of -123123 diff --git a/hostid/hostid.rs b/hostid/hostid.rs index 341f0aefc..dd6a7f58c 100644 --- a/hostid/hostid.rs +++ b/hostid/hostid.rs @@ -84,7 +84,7 @@ pub fn uumain(args: Vec) -> int { Version => version(), } - return 0; + 0 } fn version() { diff --git a/hostname/hostname.rs b/hostname/hostname.rs index c0b7a3210..ed4f30930 100644 --- a/hostname/hostname.rs +++ b/hostname/hostname.rs @@ -65,7 +65,7 @@ pub fn uumain(args: Vec) -> int { _ => { help_menu(program.as_slice(), options); } }; - return 0; + 0 } fn version() { diff --git a/id/id.rs b/id/id.rs index b61ee9a9d..6952b8d2d 100644 --- a/id/id.rs +++ b/id/id.rs @@ -195,7 +195,7 @@ pub fn uumain(args: Vec) -> int { id_print(possible_pw, false, true, true) } - return 0; + 0 } fn pretty(possible_pw: Option) { diff --git a/kill/kill.rs b/kill/kill.rs index f38f37e8d..0fbe8475f 100644 --- a/kill/kill.rs +++ b/kill/kill.rs @@ -97,7 +97,7 @@ pub fn uumain(args: Vec) -> int { Version => version(), } - return 0; + 0 } fn version() { @@ -177,7 +177,7 @@ fn signal_by_name_or_value(signal_name_or_value: &str) -> Option { return Some(signal.value); } } - return None; + None } fn kill(signalname: &str, pids: std::vec::Vec) { diff --git a/logname/logname.rs b/logname/logname.rs index 4f34eb40b..d28dca8f0 100644 --- a/logname/logname.rs +++ b/logname/logname.rs @@ -78,7 +78,7 @@ pub fn uumain(args: Vec) -> int { exec(); - return 0; + 0 } fn exec() { diff --git a/md5sum/md5sum.rs b/md5sum/md5sum.rs index 369d1b3ab..da4133573 100644 --- a/md5sum/md5sum.rs +++ b/md5sum/md5sum.rs @@ -80,7 +80,7 @@ pub fn uumain(args: Vec) -> int { } } - return 0; + 0 } fn md5sum(files: Vec, binary: bool, check: bool, tag: bool, status: bool, quiet: bool, strict: bool, warn: bool) -> Result<(), int> { @@ -150,7 +150,7 @@ fn md5sum(files: Vec, binary: bool, check: bool, tag: bool, status: bool } } - return Ok(()); + Ok(()) } fn calc_sum(md5: &mut crypto::md5::Md5, file: &mut Reader, binary: bool) -> String { diff --git a/mkdir/mkdir.rs b/mkdir/mkdir.rs index 5fef9b8ad..7dadfa0ce 100644 --- a/mkdir/mkdir.rs +++ b/mkdir/mkdir.rs @@ -85,8 +85,8 @@ pub fn uumain(args: Vec) -> int { crash!(1, "missing operand"); } match exec(dirs, mk_parents, mode, verbose_flag) { - Ok(()) => return 0, - Err(e) => return e + Ok(()) => 0, + Err(e) => e } } @@ -151,7 +151,7 @@ fn exec(dirs: Vec, mk_parents: bool, mode: FilePermission, verbose: bool } } - return result; + result } /** diff --git a/paste/paste.rs b/paste/paste.rs index 9d55185fe..1cc5c3c42 100644 --- a/paste/paste.rs +++ b/paste/paste.rs @@ -57,7 +57,7 @@ pub fn uumain(args: Vec) -> int { paste(matches.free, serial, delimiters.as_slice()); } - return 0; + 0 } fn paste(filenames: Vec, serial: bool, delimiters: &str) { diff --git a/printenv/printenv.rs b/printenv/printenv.rs index f0e928ca4..8eb9cde19 100644 --- a/printenv/printenv.rs +++ b/printenv/printenv.rs @@ -60,7 +60,7 @@ pub fn uumain(args: Vec) -> int { exec(matches.free, separator); - return 0; + 0 } pub fn exec(args: Vec, separator: &str) { diff --git a/pwd/pwd.rs b/pwd/pwd.rs index a89b5b906..7283179c7 100644 --- a/pwd/pwd.rs +++ b/pwd/pwd.rs @@ -58,5 +58,5 @@ pub fn uumain(args: Vec) -> int { return 0; } - return 0; + 0 } diff --git a/rm/rm.rs b/rm/rm.rs index a37511303..f0372391e 100644 --- a/rm/rm.rs +++ b/rm/rm.rs @@ -124,7 +124,7 @@ pub fn uumain(args: Vec) -> int { } } - return 0; + 0 } // TODO: implement one-file-system @@ -167,7 +167,7 @@ fn remove(files: Vec, force: bool, interactive: InteractiveMode, one_fs: } } - return r; + r } fn remove_dir(path: &Path, name: &str, interactive: InteractiveMode, verbose: bool) -> Result<(), int> { @@ -187,7 +187,7 @@ fn remove_dir(path: &Path, name: &str, interactive: InteractiveMode, verbose: bo } } - return Ok(()); + Ok(()) } fn remove_file(path: &Path, name: &str, interactive: InteractiveMode, verbose: bool) -> Result<(), int> { @@ -207,7 +207,7 @@ fn remove_file(path: &Path, name: &str, interactive: InteractiveMode, verbose: b } } - return Ok(()); + Ok(()) } fn prompt_file(path: &Path, name: &str) -> bool { diff --git a/rmdir/rmdir.rs b/rmdir/rmdir.rs index 56a51110e..d2dcba897 100644 --- a/rmdir/rmdir.rs +++ b/rmdir/rmdir.rs @@ -66,7 +66,7 @@ pub fn uumain(args: Vec) -> int { } } - return 0; + 0 } fn remove(dirs: Vec, ignore: bool, parents: bool, verbose: bool) -> Result<(), int>{ @@ -87,7 +87,7 @@ fn remove(dirs: Vec, ignore: bool, parents: bool, verbose: bool) -> Resu } } - return r; + r } fn remove_dir(path: &Path, dir: &str, ignore: bool, parents: bool, verbose: bool) -> Result<(), int> { @@ -124,6 +124,6 @@ fn remove_dir(path: &Path, dir: &str, ignore: bool, parents: bool, verbose: bool r = Err(1); } - return r; + r } diff --git a/seq/seq.rs b/seq/seq.rs index bc9ddc353..392bef040 100644 --- a/seq/seq.rs +++ b/seq/seq.rs @@ -88,7 +88,7 @@ pub fn uumain(args: Vec) -> int { let terminator = escape_sequences(matches.opt_str("t").unwrap_or(separator.to_string()).as_slice()); print_seq(first, step, last, separator, terminator, matches.opt_present("w")); - return 0; + 0 } fn done_printing(next: f32, step: f32, last: f32) -> bool { diff --git a/sleep/sleep.rs b/sleep/sleep.rs index f5b0fb756..5f07ac40f 100644 --- a/sleep/sleep.rs +++ b/sleep/sleep.rs @@ -64,7 +64,7 @@ specified by the sum of their values.", opts).as_slice()); sleep(matches.free); } - return 0; + 0 } fn sleep(args: Vec) { diff --git a/sum/sum.rs b/sum/sum.rs index e8d7ed213..177fe7590 100644 --- a/sum/sum.rs +++ b/sum/sum.rs @@ -129,5 +129,5 @@ pub fn uumain(args: Vec) -> int { println!("{} {}", sum, blocks); - return 0; + 0 } diff --git a/tac/tac.rs b/tac/tac.rs index 19c452e4f..30ddfeb20 100644 --- a/tac/tac.rs +++ b/tac/tac.rs @@ -70,7 +70,7 @@ pub fn uumain(args: Vec) -> int { tac(files, before, regex, separator.as_slice()); } - return 0; + 0 } fn tac(filenames: Vec, before: bool, _: bool, separator: &str) { diff --git a/touch/touch.rs b/touch/touch.rs index 8a08f9467..abe98a39f 100644 --- a/touch/touch.rs +++ b/touch/touch.rs @@ -132,7 +132,7 @@ pub fn uumain(args: Vec) -> int { } } - return 0; + 0 } fn stat(path: &Path, follow: bool) -> std::io::FileStat { diff --git a/tr/tr.rs b/tr/tr.rs index f52d2a6bc..03e78f251 100644 --- a/tr/tr.rs +++ b/tr/tr.rs @@ -199,5 +199,5 @@ pub fn uumain(args: Vec) -> int { tr(set1.as_slice(), set2.as_slice()); } - return 0; + 0 } diff --git a/truncate/truncate.rs b/truncate/truncate.rs index 8cf886014..1f9f54925 100644 --- a/truncate/truncate.rs +++ b/truncate/truncate.rs @@ -100,7 +100,7 @@ file based on its current size: } } - return 0; + 0 } fn truncate(no_create: bool, _: bool, reference: Option, size: Option, filenames: Vec) -> Result<(), int> { @@ -159,7 +159,7 @@ fn truncate(no_create: bool, _: bool, reference: Option, size: Option (u64, TruncateMode) { diff --git a/tty/tty.rs b/tty/tty.rs index d715dd968..1f10b9c34 100644 --- a/tty/tty.rs +++ b/tty/tty.rs @@ -71,7 +71,7 @@ pub fn uumain(args: Vec) -> int { } }; - return exit_code as int; + exit_code as int } fn usage () { diff --git a/uname/uname.rs b/uname/uname.rs index e25334275..fc4cf3c8b 100644 --- a/uname/uname.rs +++ b/uname/uname.rs @@ -105,5 +105,5 @@ pub fn uumain(args: Vec) -> int { } println!("{}", output.as_slice().trim_left()); - return 0; + 0 } diff --git a/unlink/unlink.rs b/unlink/unlink.rs index 4221eafa7..aa07f0930 100644 --- a/unlink/unlink.rs +++ b/unlink/unlink.rs @@ -87,5 +87,5 @@ pub fn uumain(args: Vec) -> int { } } - return 0; + 0 } diff --git a/uptime/uptime.rs b/uptime/uptime.rs index eac380d0e..cdee621ec 100644 --- a/uptime/uptime.rs +++ b/uptime/uptime.rs @@ -81,7 +81,7 @@ pub fn uumain(args: Vec) -> int { print_nusers(user_count); print_loadavg(); - return 0; + 0 } fn print_loadavg() { diff --git a/users/users.rs b/users/users.rs index 4017aad6f..5ff28476b 100644 --- a/users/users.rs +++ b/users/users.rs @@ -84,7 +84,7 @@ pub fn uumain(args: Vec) -> int { exec(filename); - return 0; + 0 } fn exec(filename: &str) { diff --git a/wc/wc.rs b/wc/wc.rs index 9ab77c68d..cdbb7ada5 100644 --- a/wc/wc.rs +++ b/wc/wc.rs @@ -81,7 +81,7 @@ pub fn uumain(args: Vec) -> int { Err(e) => return e } - return 0; + 0 } static CR: u8 = '\r' as u8; @@ -192,7 +192,7 @@ pub fn wc(files: Vec, matches: &Matches) -> StdResult<(), int> { print_stats("total", total_line_count, total_word_count, total_char_count, total_byte_count, total_longest_line_length, matches, max_str_len); } - return Ok(()); + Ok(()) } fn print_stats(filename: &str, line_count: uint, word_count: uint, char_count: uint, @@ -241,11 +241,11 @@ fn open(path: String) -> StdResult>, int> { match File::open(&std::path::Path::new(path.as_slice())) { Ok(fd) => { let reader = box fd as Box; - return Ok(BufferedReader::new(reader)); + Ok(BufferedReader::new(reader)) }, Err(e) => { show_error!("wc: {0:s}: {1:s}", path, e.desc.to_str()); - return Err(1); + Err(1) } } } diff --git a/whoami/whoami.rs b/whoami/whoami.rs index 65deb2d13..1c237060e 100644 --- a/whoami/whoami.rs +++ b/whoami/whoami.rs @@ -70,7 +70,7 @@ pub fn uumain(args: Vec) -> int { exec(); - return 0; + 0 } pub fn exec() { diff --git a/yes/yes.rs b/yes/yes.rs index 38d0276b5..522732fb5 100644 --- a/yes/yes.rs +++ b/yes/yes.rs @@ -59,7 +59,7 @@ pub fn uumain(args: Vec) -> int { exec(string.as_slice()); - return 0; + 0 } pub fn exec(string: &str) { From 107c2d4c62096355496c7130bf132a3a1f008f78 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 11 Jun 2014 21:43:47 -0700 Subject: [PATCH 10/10] phase(syntax) -> phase(plugin) --- base64/base64.rs | 2 +- cp/cp.rs | 2 +- hostid/hostid.rs | 2 +- kill/kill.rs | 2 +- tee/tee.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/base64/base64.rs b/base64/base64.rs index 2098c0471..91ee7bcbc 100644 --- a/base64/base64.rs +++ b/base64/base64.rs @@ -15,7 +15,7 @@ extern crate serialize; extern crate getopts; extern crate libc; -#[phase(syntax, link)] extern crate log; +#[phase(plugin, link)] extern crate log; use std::io::{println, File, stdin, stdout}; use std::os; diff --git a/cp/cp.rs b/cp/cp.rs index 2bdc19fb9..66e7ec79a 100644 --- a/cp/cp.rs +++ b/cp/cp.rs @@ -12,7 +12,7 @@ */ extern crate getopts; -#[phase(syntax, link)] extern crate log; +#[phase(plugin, link)] extern crate log; use std::os; use std::io; diff --git a/hostid/hostid.rs b/hostid/hostid.rs index dd6a7f58c..f1fa4ce72 100644 --- a/hostid/hostid.rs +++ b/hostid/hostid.rs @@ -18,7 +18,7 @@ extern crate serialize; extern crate libc; -#[phase(syntax, link)] extern crate log; +#[phase(plugin, link)] extern crate log; use std::os; diff --git a/kill/kill.rs b/kill/kill.rs index 0fbe8475f..0aa33fd75 100644 --- a/kill/kill.rs +++ b/kill/kill.rs @@ -17,7 +17,7 @@ extern crate libc; extern crate collections; extern crate serialize; -#[phase(syntax, link)] extern crate log; +#[phase(plugin, link)] extern crate log; use std::os; use std::from_str::from_str; diff --git a/tee/tee.rs b/tee/tee.rs index 59013076c..83fc010e9 100644 --- a/tee/tee.rs +++ b/tee/tee.rs @@ -13,7 +13,7 @@ */ extern crate getopts; -#[phase(syntax, link)] extern crate log; +#[phase(plugin, link)] extern crate log; use std::io::{println, stdin, stdout, Append, File, Truncate, Write}; use std::io::{IoResult};