sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit a0e90509254c7a8db5f7ff55560f2a8ff37c32d4
parent 237673302d5f3454e6c7b1873281b99d3e3ed3a2
Author: sin <sin@2f30.org>
Date:   Tue, 11 Nov 2014 15:35:27 +0000

Implement XSI extensions -signal_name and -signal_number for kill(1)

Diffstat:
Mkill.c | 48++++++++++++++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 14 deletions(-)

diff --git a/kill.c b/kill.c @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include <sys/wait.h> +#include <ctype.h> #include <errno.h> #include <signal.h> #include <stdbool.h> @@ -47,7 +48,25 @@ main(int argc, char *argv[]) argc--; argv++; - if (strcmp(argv[0], "-l") == 0) { + if (strcmp(argv[0], "--") == 0) { + argc--; + argv++; + if (argc == 0) + usage(); + } else if (argv[0][0] == '-' && isdigit(argv[0][1])) { + /* handle XSI extension -signal_number */ + errno = 0; + sig = strtol(&argv[0][1], &end, 0); + if (*end != '\0' || errno != 0) + eprintf("%d: bad signal number\n", sig); + for (i = 0; i < LEN(sigs); i++) + if (sigs[i].sig == sig || sig == 0) + break; + if (i == LEN(sigs)) + eprintf("%d: bad signal number\n", sig); + argc--; + argv++; + } else if (strcmp(argv[0], "-l") == 0) { argc--; argv++; if (argc == 0) { @@ -70,30 +89,31 @@ main(int argc, char *argv[]) } } exit(0); - } else if (strcmp(argv[0], "-s") == 0) { - argc--; - argv++; - if (argc == 0) - usage(); - if (strcmp(argv[0], "0") == 0) { + } else { + if (strcmp(argv[0], "-s") == 0) { + argc--; + argv++; + if (argc == 0) + usage(); + name = argv[0]; + } else { + /* assume XSI extension -signal_name */ + name = &argv[0][1]; + } + if (strcmp(name, "0") == 0) { sig = 0; } else { for (i = 0; i < LEN(sigs); i++) { - if (strcasecmp(sigs[i].name, argv[0]) == 0) { + if (strcasecmp(sigs[i].name, name) == 0) { sig = sigs[i].sig; break; } } if (i == LEN(sigs)) - eprintf("%s: bad signal number\n", argv[0]); + eprintf("%s: bad signal number\n", name); } argc--; argv++; - } else if (strcmp(argv[0], "--") == 0) { - argc--; - argv++; - if (argc == 0) - usage(); } if (argc == 0)