summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2014-03-23 12:44:01 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2014-03-23 12:44:01 +0000
commit08c44f701bf55ff1d7e25f33192a9d4ac8588ffe (patch)
treebfc3b66c24a93451674ce592c075df4a1f6ab166
parentc323fe04053ab1622ce33ed44ca539624bd81266 (diff)
kill(1) doesn't use getopt() due to its non-standard option processing.
However, POSIX (really XSI) says it should honor "--" to disambiguate between -signum and -pgid. This adds simple "--" handling such that "kill -- -pgid" is accepted.
-rw-r--r--bin/kill/kill.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/bin/kill/kill.c b/bin/kill/kill.c
index 26c0cd7fa2f..c05c150ddae 100644
--- a/bin/kill/kill.c
+++ b/bin/kill/kill.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kill.c,v 1.11 2013/11/21 15:54:45 deraadt Exp $ */
+/* $OpenBSD: kill.c,v 1.12 2014/03/23 12:44:00 millert Exp $ */
/* $NetBSD: kill.c,v 1.11 1995/09/07 06:30:27 jtc Exp $ */
/*
@@ -59,6 +59,8 @@ main(int argc, char *argv[])
argc--, argv++;
if (!strcmp(*argv, "-l")) {
argc--, argv++;
+ if (argc > 0 && !strcmp(*argv, "--"))
+ argc--, argv++;
if (argc > 1)
usage();
if (argc == 1) {
@@ -80,6 +82,8 @@ main(int argc, char *argv[])
if (!strcmp(*argv, "-s")) {
argc--, argv++;
+ if (argc > 0 && !strcmp(*argv, "--"))
+ argc--, argv++;
if (argc < 1) {
warnx("option requires an argument -- s");
usage();
@@ -91,18 +95,20 @@ main(int argc, char *argv[])
numsig = 0;
argc--, argv++;
} else if (**argv == '-') {
- ++*argv;
- if (isalpha((unsigned char)**argv)) {
- if ((numsig = signame_to_signum(*argv)) < 0)
+ if (strcmp(*argv, "--")) {
+ ++*argv;
+ if (isalpha((unsigned char)**argv)) {
+ if ((numsig = signame_to_signum(*argv)) < 0)
+ nosig(*argv);
+ } else if (isdigit((unsigned char)**argv)) {
+ numsig = strtol(*argv, &ep, 10);
+ if (*ep)
+ errx(1, "illegal signal number: %s", *argv);
+ if (numsig < 0 || numsig >= NSIG)
+ nosig(*argv);
+ } else
nosig(*argv);
- } else if (isdigit((unsigned char)**argv)) {
- numsig = strtol(*argv, &ep, 10);
- if (*ep)
- errx(1, "illegal signal number: %s", *argv);
- if (numsig < 0 || numsig >= NSIG)
- nosig(*argv);
- } else
- nosig(*argv);
+ }
argc--, argv++;
}