Handle "--" for -l and -s as well in kill(1)

This commit is contained in:
sin 2014-11-11 17:11:58 +00:00
parent c0f540162f
commit e4e47a617e

22
kill.c
View File

@ -47,11 +47,9 @@ main(int argc, char *argv[])
if (argc < 2) if (argc < 2)
usage(); usage();
argc--; argc--, argv++;
argv++;
if (strcmp(argv[0], "--") == 0) { if (strcmp(argv[0], "--") == 0) {
argc--; argc--, argv++;
argv++;
} else if (argv[0][0] == '-' && isdigit(argv[0][1])) { } else if (argv[0][0] == '-' && isdigit(argv[0][1])) {
/* handle XSI extension -signum */ /* handle XSI extension -signum */
errno = 0; errno = 0;
@ -59,11 +57,11 @@ main(int argc, char *argv[])
if (*end != '\0' || errno != 0) if (*end != '\0' || errno != 0)
eprintf("%s: bad signal number\n", &argv[0][1]); eprintf("%s: bad signal number\n", &argv[0][1]);
sig2name(sig); sig2name(sig);
argc--; argc--, argv++;
argv++;
} else if (strcmp(argv[0], "-l") == 0) { } else if (strcmp(argv[0], "-l") == 0) {
argc--; argc--, argv++;
argv++; if (argc > 0 && strcmp(argv[0], "--") == 0)
argc--, argv++;
if (argc == 0) { if (argc == 0) {
for (i = 0; i < LEN(sigs); i++) for (i = 0; i < LEN(sigs); i++)
puts(sigs[i].name); puts(sigs[i].name);
@ -80,8 +78,9 @@ main(int argc, char *argv[])
exit(0); exit(0);
} else { } else {
if (strcmp(argv[0], "-s") == 0) { if (strcmp(argv[0], "-s") == 0) {
argc--; argc--, argv++;
argv++; if (argc > 0 && strcmp(argv[0], "--") == 0)
argc--, argv++;
if (argc == 0) if (argc == 0)
usage(); usage();
name = argv[0]; name = argv[0];
@ -90,8 +89,7 @@ main(int argc, char *argv[])
name = &argv[0][1]; name = &argv[0][1];
} }
sig = strcmp(name, "0") == 0 ? 0 : name2sig(name); sig = strcmp(name, "0") == 0 ? 0 : name2sig(name);
argc--; argc--, argv++;
argv++;
} }
if (argc == 0) if (argc == 0)