mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-17 18:02:09 +03:00
timeout: use more standard option parsing
* src/timeout.c (main): Don't use parse_long_options() which is a helper for commands that don't have any long options specific to them. * tests/misc/timeout-parameters: Remove a case that now passes due to us accepting multiple instances of the --help and --version options. * THANKS: Add the author. Signed-off-by: Pádraig Brady <P@draigBrady.com>
This commit is contained in:
1 parent
4c38625ef3
commit
88d4b3461e
3 files changed
+9
-8
No files matched your search
@@ -337,6 +337,7 @@ Keith Owens kaos@audio.apana.org.au
|
|||||||
Keith Thompson kst@cts.com
|
Keith Thompson kst@cts.com
|
||||||
Ken Pizzini kenp@halcyon.com
|
Ken Pizzini kenp@halcyon.com
|
||||||
Kevin Mudrick kmudrick@healthmarketscience.com
|
Kevin Mudrick kmudrick@healthmarketscience.com
|
||||||
|
Kim Hansen kim@i9.dk
|
||||||
Kirk Kelsey kirk.kelsey@0x4b.net
|
Kirk Kelsey kirk.kelsey@0x4b.net
|
||||||
Kristin E Thomas kristint@us.ibm.com
|
Kristin E Thomas kristint@us.ibm.com
|
||||||
Kjetil Torgrim Homme kjetilho@ifi.uio.no
|
Kjetil Torgrim Homme kjetilho@ifi.uio.no
|
||||||
|
|||||||
+8
-4
@@ -66,7 +66,6 @@
|
|||||||
#include "operand2sig.h"
|
#include "operand2sig.h"
|
||||||
#include "cloexec.h"
|
#include "cloexec.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "long-options.h"
|
|
||||||
#include "quote.h"
|
#include "quote.h"
|
||||||
|
|
||||||
#define PROGRAM_NAME "timeout"
|
#define PROGRAM_NAME "timeout"
|
||||||
@@ -83,6 +82,8 @@ static struct option const long_options[] =
|
|||||||
{
|
{
|
||||||
{"kill-after", required_argument, NULL, 'k'},
|
{"kill-after", required_argument, NULL, 'k'},
|
||||||
{"signal", required_argument, NULL, 's'},
|
{"signal", required_argument, NULL, 's'},
|
||||||
|
{GETOPT_HELP_OPTION_DECL},
|
||||||
|
{GETOPT_VERSION_OPTION_DECL},
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -261,9 +262,6 @@ main (int argc, char **argv)
|
|||||||
initialize_exit_failure (EXIT_CANCELED);
|
initialize_exit_failure (EXIT_CANCELED);
|
||||||
atexit (close_stdout);
|
atexit (close_stdout);
|
||||||
|
|
||||||
parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version,
|
|
||||||
usage, AUTHORS, (char const *) NULL);
|
|
||||||
|
|
||||||
while ((c = getopt_long (argc, argv, "+k:s:", long_options, NULL)) != -1)
|
while ((c = getopt_long (argc, argv, "+k:s:", long_options, NULL)) != -1)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
@@ -271,11 +269,17 @@ main (int argc, char **argv)
|
|||||||
case 'k':
|
case 'k':
|
||||||
kill_after = parse_duration (optarg);
|
kill_after = parse_duration (optarg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
term_signal = operand2sig (optarg, signame);
|
term_signal = operand2sig (optarg, signame);
|
||||||
if (term_signal == -1)
|
if (term_signal == -1)
|
||||||
usage (EXIT_CANCELED);
|
usage (EXIT_CANCELED);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case_GETOPT_HELP_CHAR;
|
||||||
|
|
||||||
|
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
usage (EXIT_CANCELED);
|
usage (EXIT_CANCELED);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -27,10 +27,6 @@ getlimits_
|
|||||||
|
|
||||||
# internal errors are 125, distinct from execution failure
|
# internal errors are 125, distinct from execution failure
|
||||||
|
|
||||||
# --help and --version must be specified alone
|
|
||||||
timeout --help --version
|
|
||||||
test $? = 125 || fail=1
|
|
||||||
|
|
||||||
# invalid timeout
|
# invalid timeout
|
||||||
timeout invalid sleep 0
|
timeout invalid sleep 0
|
||||||
test $? = 125 || fail=1
|
test $? = 125 || fail=1
|
||||||
|
|||||||
Reference in new issue
Block a user