From 9a301232f3ed2fd9457d5ff9485b96857af08135 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 7 Dec 2022 04:36:52 -0600 Subject: [PATCH] Tighten up option parsing and teach "sleep" to parse multiple args. --- lib/args.c | 2 +- toys/android/runcon.c | 2 +- toys/other/openvt.c | 2 +- toys/other/usleep.c | 2 +- toys/posix/sleep.c | 7 +++++-- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/args.c b/lib/args.c index 9fe320ff..eec86c8e 100644 --- a/lib/args.c +++ b/lib/args.c @@ -74,7 +74,7 @@ // <0 die if less than # leftover arguments (default 0) // >9 die if > # leftover arguments (default MAX_INT) // 0 Include argv[0] in optargs -// ^ stop at first nonoption argument (implied when no flags) +// ^ stop at first nonoption argument // ? Pass unknown arguments through to command (implied when no flags). // & first arg has imaginary dash (ala tar/ps/ar) which sets FLAGS_NODASH // ~ Collate following bare longopts (as if under short opt, repeatable) diff --git a/toys/android/runcon.c b/toys/android/runcon.c index 8831cbfb..5eb8fa62 100644 --- a/toys/android/runcon.c +++ b/toys/android/runcon.c @@ -2,7 +2,7 @@ * * Copyright 2015 The Android Open Source Project -USE_RUNCON(NEWTOY(runcon, "<2", TOYFLAG_USR|TOYFLAG_SBIN)) +USE_RUNCON(NEWTOY(runcon, "^<2", TOYFLAG_USR|TOYFLAG_SBIN)) config RUNCON bool "runcon" diff --git a/toys/other/openvt.c b/toys/other/openvt.c index 8210587d..66d8a360 100644 --- a/toys/other/openvt.c +++ b/toys/other/openvt.c @@ -6,7 +6,7 @@ * No Standard USE_OPENVT(NEWTOY(openvt, "^<1c#<1>63sw", TOYFLAG_BIN|TOYFLAG_NEEDROOT)) -USE_CHVT(NEWTOY(chvt, "<1", TOYFLAG_USR|TOYFLAG_BIN)) +USE_CHVT(NEWTOY(chvt, "<1>1", TOYFLAG_USR|TOYFLAG_BIN)) USE_DEALLOCVT(NEWTOY(deallocvt, ">1", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_NEEDROOT)) config OPENVT diff --git a/toys/other/usleep.c b/toys/other/usleep.c index 6040cc06..e09a17c8 100644 --- a/toys/other/usleep.c +++ b/toys/other/usleep.c @@ -2,7 +2,7 @@ * * Copyright 2012 Elie De Brauwer -USE_USLEEP(NEWTOY(usleep, "<1", TOYFLAG_BIN)) +USE_USLEEP(NEWTOY(usleep, "<1>1", TOYFLAG_BIN)) config USLEEP bool "usleep" diff --git a/toys/posix/sleep.c b/toys/posix/sleep.c index 73f03fb4..d696210f 100644 --- a/toys/posix/sleep.c +++ b/toys/posix/sleep.c @@ -24,7 +24,10 @@ config SLEEP void sleep_main(void) { struct timespec ts; + char **args; - xparsetimespec(*toys.optargs, &ts); - toys.exitval = !!nanosleep(&ts, NULL); + for (args = toys.optargs; !toys.exitval && *args; args++) { + xparsetimespec(*args, &ts); + toys.exitval = !!nanosleep(&ts, NULL); + } } -- 2.39.2