[hackers] [sbase] Simplify logic in kill(1) || sin
commit f06ada45922a7f58ddc53bfbea14388750930d0a
Author: sin <sin_AT_2f30.org>
Date: Tue Nov 11 17:28:27 2014 +0000
Simplify logic in kill(1)
diff --git a/kill.c b/kill.c
index e9a643f..f7f30b7 100644
--- a/kill.c
+++ b/kill.c
_AT_@ -37,7 +37,6 @@ int
main(int argc, char *argv[])
{
char *end;
- const char *name;
int ret = 0;
int sig = SIGTERM;
pid_t pid;
_AT_@ -48,20 +47,8 @@ main(int argc, char *argv[])
usage();
argc--, argv++;
- if (strcmp(argv[0], "--") == 0) {
- argc--, argv++;
- } else if (argv[0][0] == '-' && isdigit(argv[0][1])) {
- /* handle XSI extension -signum */
- errno = 0;
- sig = strtol(&argv[0][1], &end, 10);
- if (*end != '\0' || errno != 0)
- eprintf("%s: bad signal number\n", &argv[0][1]);
- sig2name(sig);
+ if (strcmp(argv[0], "-l") == 0) {
argc--, argv++;
- } else if (strcmp(argv[0], "-l") == 0) {
- argc--, argv++;
- if (argc > 0 && strcmp(argv[0], "--") == 0)
- argc--, argv++;
if (argc == 0) {
for (i = 0; i < LEN(sigs); i++)
puts(sigs[i].name);
_AT_@ -76,22 +63,33 @@ main(int argc, char *argv[])
sig = WTERMSIG(sig);
puts(sig2name(sig));
exit(0);
- } else {
- if (strcmp(argv[0], "-s") == 0) {
+ }
+
+ if (strcmp(argv[0], "-s") == 0) {
+ argc--, argv++;
+ if (argc == 0)
+ usage();
+ sig = strcmp(argv[0], "0") == 0 ? 0 : name2sig(argv[0]);
+ argc--, argv++;
+ } else if (argv[0][0] == '-') {
+ if (isdigit(argv[0][1])) {
+ /* handle XSI extension -signum */
+ errno = 0;
+ sig = strtol(&argv[0][1], &end, 10);
+ if (*end != '\0' || errno != 0)
+ eprintf("%s: bad signal number\n", &argv[0][1]);
+ sig2name(sig);
+ argc--, argv++;
+ } else if (argv[0][1] != '-') {
+ /* handle XSI extension -signame */
+ sig = strcmp(&argv[0][1], "0") == 0 ? 0 : name2sig(&argv[0][1]);
argc--, argv++;
- if (argc > 0 && strcmp(argv[0], "--") == 0)
- argc--, argv++;
- if (argc == 0)
- usage();
- name = argv[0];
- } else {
- /* assume XSI extension -signame */
- name = &argv[0][1];
}
- sig = strcmp(name, "0") == 0 ? 0 : name2sig(name);
- argc--, argv++;
}
+ if (argc > 0 && strcmp(argv[0], "--") == 0)
+ argc--, argv++;
+
if (argc == 0)
usage();
Received on Tue Nov 11 2014 - 18:32:17 CET
This archive was generated by hypermail 2.3.0
: Tue Nov 11 2014 - 18:36:09 CET