[hackers] [sbase] Implement XSI extensions -signal_name and -signal_number for kill(1) || sin

From: <git_AT_suckless.org>
Date: Tue, 11 Nov 2014 16:37:30 +0100

commit a0e90509254c7a8db5f7ff55560f2a8ff37c32d4
Author: sin <sin_AT_2f30.org>
Date: Tue Nov 11 15:35:27 2014 +0000

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

diff --git a/kill.c b/kill.c
index f66c84d..7f30fe4 100644
--- a/kill.c
+++ b/kill.c
_AT_@ -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>
_AT_@ -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) {
_AT_@ -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)
Received on Tue Nov 11 2014 - 16:37:30 CET

This archive was generated by hypermail 2.3.0 : Tue Nov 11 2014 - 16:48:12 CET