diff options
author | Elliott Hughes <enh@google.com> | 2019-03-18 20:37:53 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-03-18 23:37:05 -0500 |
commit | 95574e3f2a47291651f7c78c873318344565e80e (patch) | |
tree | e3ff1282473f9f0724770fec64b2a4b3457364e2 | |
parent | 7709875b443fcd155e1737f18d3fff75c4b2753a (diff) | |
download | toybox-95574e3f2a47291651f7c78c873318344565e80e.tar.gz |
cmp/env/nice/nohup/sort: use TOYFLAG_ARGFAIL.
Also be a bit more consistent about `COMMAND [ARG...]` in usage text.
-rwxr-xr-x | tests/cmp.test | 6 | ||||
-rwxr-xr-x | tests/env.test | 2 | ||||
-rwxr-xr-x | tests/sort.test | 1 | ||||
-rw-r--r-- | toys/other/chroot.c | 9 | ||||
-rw-r--r-- | toys/posix/cmp.c | 3 | ||||
-rw-r--r-- | toys/posix/env.c | 4 | ||||
-rw-r--r-- | toys/posix/nice.c | 8 | ||||
-rw-r--r-- | toys/posix/nohup.c | 6 | ||||
-rw-r--r-- | toys/posix/sort.c | 3 |
9 files changed, 27 insertions, 15 deletions
diff --git a/tests/cmp.test b/tests/cmp.test index 3b2dd1b2..62d4b89d 100755 --- a/tests/cmp.test +++ b/tests/cmp.test @@ -2,8 +2,10 @@ [ -f testing.sh ] && . testing.sh -testing "not enough arguments [fail]" "cmp input 2>/dev/null || echo yes" "yes\n" "foo" "" -testing "missing file1 [fail]" "cmp file1 input 2>/dev/null || echo yes" "yes\n" "foo" "" +# TODO: coreutils cmp uses stdin if only one file is given +SKIP_HOST=1 testing "not enough arguments [fail]" 'cmp input 2>/dev/null || echo $?' "2\n" "foo" "" + +testing "missing file1 [fail]" 'cmp file1 input 2>/dev/null || echo $?' "2\n" "foo" "" #mkdir dir #testing "directory [fail]" "cmp dir dir 2>/dev/null || echo yes" \ diff --git a/tests/env.test b/tests/env.test index e92164c5..286fb36c 100755 --- a/tests/env.test +++ b/tests/env.test @@ -16,3 +16,5 @@ testcmd "-i =" "-i one=two three=four env | sort" \ "one=two\nthree=four\n" "" "" testcmd "-0" "-i five=six seven=eight env -0 | sort -z" "five=six\0seven=eight\0" "" "" unset WALRUS BANANA LETTERS FILTER + +testcmd "early fail" '--oops 2> /dev/null ; echo $?' "125\n" "" "" diff --git a/tests/sort.test b/tests/sort.test index a40d1b0f..dd2b8263 100755 --- a/tests/sort.test +++ b/tests/sort.test @@ -7,6 +7,7 @@ # The basic tests. These should work even with the small config. +testing "unknown argument" 'sort --oops 2>/dev/null ; echo $?' "2\n" "" "" testing "sort" "sort input" "a\nb\nc\n" "c\na\nb\n" "" testing "#2" "sort input" "010\n1\n3\n" "3\n1\n010\n" "" testing "stdin" "sort" "a\nb\nc\n" "" "b\na\nc\n" diff --git a/toys/other/chroot.c b/toys/other/chroot.c index b6ef17d6..d791f34a 100644 --- a/toys/other/chroot.c +++ b/toys/other/chroot.c @@ -7,13 +7,13 @@ * The container guys use pivot_root() to deal with this, which does actually * edit mount tree. (New option? Kernel patch?) -USE_CHROOT(NEWTOY(chroot, "^<1", TOYFLAG_USR|TOYFLAG_SBIN)) +USE_CHROOT(NEWTOY(chroot, "^<1", TOYFLAG_USR|TOYFLAG_SBIN|TOYFLAG_ARGFAIL(125))) config CHROOT bool "chroot" default y help - usage: chroot NEWPATH [commandline...] + usage: chroot NEWROOT [COMMAND [ARG...]] Run command within a new root directory. If no command, run /bin/sh. */ @@ -24,7 +24,10 @@ void chroot_main(void) { char *binsh[] = {"/bin/sh", "-i", 0}; - if (chdir(*toys.optargs) || chroot(".")) perror_exit_raw(*toys.optargs); + if (chdir(*toys.optargs) || chroot(".")) { + toys.exitval = 125; + perror_exit_raw(*toys.optargs); + } if (toys.optargs[1]) xexec(toys.optargs+1); else xexec(binsh); } diff --git a/toys/posix/cmp.c b/toys/posix/cmp.c index 6cd410fc..c573f02e 100644 --- a/toys/posix/cmp.c +++ b/toys/posix/cmp.c @@ -4,7 +4,7 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/cmp.html -USE_CMP(NEWTOY(cmp, "<2>2ls(silent)(quiet)[!ls]", TOYFLAG_USR|TOYFLAG_BIN)) +USE_CMP(NEWTOY(cmp, "<2>2ls(silent)(quiet)[!ls]", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_ARGFAIL(2))) config CMP bool "cmp" @@ -81,4 +81,3 @@ void cmp_main(void) loopfiles_rw(toys.optargs, O_CLOEXEC|(WARN_ONLY*!(toys.optflags&FLAG_s)), 0, do_cmp); } - diff --git a/toys/posix/env.c b/toys/posix/env.c index 2de8f690..5c7bb789 100644 --- a/toys/posix/env.c +++ b/toys/posix/env.c @@ -6,13 +6,13 @@ * * Deviations from posix: "-" argument and -0 -USE_ENV(NEWTOY(env, "^0iu*", TOYFLAG_USR|TOYFLAG_BIN)) +USE_ENV(NEWTOY(env, "^0iu*", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_ARGFAIL(125))) config ENV bool "env" default y help - usage: env [-i] [-u NAME] [NAME=VALUE...] [command [option...]] + usage: env [-i] [-u NAME] [NAME=VALUE...] [COMMAND [ARG...]] Set the environment for command invocation, or list environment variables. diff --git a/toys/posix/nice.c b/toys/posix/nice.c index ca5e2224..c26f66d3 100644 --- a/toys/posix/nice.c +++ b/toys/posix/nice.c @@ -10,7 +10,7 @@ config NICE bool "nice" default y help - usage: nice [-n PRIORITY] command [args...] + usage: nice [-n PRIORITY] COMMAND [ARG...] Run a command line at an increased or decreased scheduling priority. @@ -32,7 +32,9 @@ void nice_main(void) if (!toys.optflags) TT.n = 10; errno = 0; - if (nice(TT.n)==-1 && errno) perror_exit("Can't set priority"); - + if (nice(TT.n)==-1 && errno) { + toys.exitval = 125; + perror_exit("Can't set priority"); + } xexec(toys.optargs); } diff --git a/toys/posix/nohup.c b/toys/posix/nohup.c index b302cbe4..e5b526f7 100644 --- a/toys/posix/nohup.c +++ b/toys/posix/nohup.c @@ -4,13 +4,13 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/nohup.html -USE_NOHUP(NEWTOY(nohup, "<1^", TOYFLAG_USR|TOYFLAG_BIN)) +USE_NOHUP(NEWTOY(nohup, "<1^", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_ARGFAIL(125))) config NOHUP bool "nohup" default y help - usage: nohup COMMAND [ARGS...] + usage: nohup COMMAND [ARG...] Run a command that survives the end of its terminal. @@ -21,6 +21,7 @@ config NOHUP void nohup_main(void) { + toys.exitval = 125; xsignal(SIGHUP, SIG_IGN); if (isatty(1)) { close(1); @@ -38,5 +39,6 @@ void nohup_main(void) close(0); xopen_stdio("/dev/null", O_RDONLY); } + toys.exitval = 0; xexec(toys.optargs); } diff --git a/toys/posix/sort.c b/toys/posix/sort.c index 9bf81ebc..9d2f2276 100644 --- a/toys/posix/sort.c +++ b/toys/posix/sort.c @@ -7,7 +7,7 @@ * Deviations from POSIX: Lots. * We invented -x -USE_SORT(NEWTOY(sort, USE_SORT_FLOAT("g")"S:T:m" "o:k*t:" "xVbMcszdfirun", TOYFLAG_USR|TOYFLAG_BIN)) +USE_SORT(NEWTOY(sort, USE_SORT_FLOAT("g")"S:T:m" "o:k*t:" "xVbMcszdfirun", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_ARGFAIL(2))) config SORT bool "sort" @@ -345,6 +345,7 @@ void sort_main(void) if (!temp2 || flag>FLAG_x || (flag&(FLAG_u|FLAG_c|FLAG_s|FLAG_z))) { + toys.exitval = 2; error_exit("Unknown key option."); } // b after , means strip _trailing_ space, not leading. |