[PATCH 08/10] kill: tell what is wrong rather than output usage()

Sami Kerola
2014-03-09T20:30:41Z

Getting usage as error message is not specific enough. As a user I want
to know what is wrong, and if it is unclear after error message how to
recover then I run command with --help.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
misc-utils/kill.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/misc-utils/kill.c b/misc-utils/kill.c
index 34bd00e..30c209f 100644
--- a/misc-utils/kill.c
+++ b/misc-utils/kill.c
@@ -212,7 +212,7 @@ int main(int argc, char **argv)
return EXIT_SUCCESS;
}
if (2 < argc)
- usage(stderr);
+ errx(EXIT_FAILURE, _("too many arguments"));
/* argc == 2, accept "kill -l $?" */
arg = argv[1];
if ((ctl.numsig = arg_to_signum(arg, 1)) < 0)
@@ -236,15 +236,15 @@ int main(int argc, char **argv)
if (!strcmp(arg, "-p") || !strcmp(arg, "--pid")) {
ctl.do_pid = 1;
if (ctl.do_kill)
- usage(stderr);
+ errx(EXIT_FAILURE, _("%s and %s are mutually exclusive"), "--pid", "--signal");
continue;
}
if (!strcmp(arg, "-s") || !strcmp(arg, "--signal")) {
if (argc < 2)
- usage(stderr);
+ errx(EXIT_FAILURE, _("not enough arguments"));
ctl.do_kill = 1;
if (ctl.do_pid)
- usage(stderr);
+ errx(EXIT_FAILURE, _("%s and %s are mutually exclusive"), "--pid", "--signal");
argc--, argv++;
arg = *argv;
if ((ctl.numsig = arg_to_signum(arg, 0)) < 0) {
@@ -255,7 +255,7 @@ int main(int argc, char **argv)
}
if (!strcmp(arg, "-q") || !strcmp(arg, "--queue")) {
if (argc < 2)
- usage(stderr);
+ errx(EXIT_FAILURE, _("option '%s' requires an argument"), arg);
argc--, argv++;
arg = *argv;
#ifdef HAVE_SIGQUEUE
@@ -277,14 +277,14 @@ int main(int argc, char **argv)
break;
arg++;
if ((ctl.numsig = arg_to_signum(arg, 0)) < 0)
- usage(stderr);
+ errx(EXIT_FAILURE, _("invalid sigval argument"));
ctl.do_kill = 1;
if (ctl.do_pid)
- usage(stderr);
+ errx(EXIT_FAILURE, _("%s and %s are mutually exclusive"), "--pid", "--signal");
continue;
}
if (!*argv)
- usage(stderr);
+ errx(EXIT_FAILURE, _("not enough arguments"));
if (ctl.do_pid)
ctl.numsig = -1;

--
1.9.0