comparison toys/posix/kill.c @ 694:786841fdb1e0

Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style. The actual code should be the same afterward, this is just cosmetic refactoring.
author Rob Landley <rob@landley.net>
date Tue, 13 Nov 2012 17:14:08 -0600
parents 7e846e281e38
children 6cc69be43c42
comparison
equal deleted inserted replaced
693:4a5a250e0633 694:786841fdb1e0
1 /* vi: set sw=4 ts=4: 1 /* kill.c - a program to send signals to processes
2 *
3 * kill.c - a program to send signals to processes
4 * 2 *
5 * Copyright 2012 Daniel Walter <d.walter@0x90.at> 3 * Copyright 2012 Daniel Walter <d.walter@0x90.at>
6 * 4 *
7 * See http://opengroup.org/onlinepubs/9699919799/utilities/kill.html 5 * See http://opengroup.org/onlinepubs/9699919799/utilities/kill.html
8 6
9 USE_KILL(NEWTOY(kill, "?s: l", TOYFLAG_BIN)) 7 USE_KILL(NEWTOY(kill, "?s: l", TOYFLAG_BIN))
10 8
11 config KILL 9 config KILL
12 bool "kill" 10 bool "kill"
13 default y 11 default y
14 help 12 help
15 usage: kill [-l [SIGNAL] | -s SIGNAL | -SIGNAL] pid... 13 usage: kill [-l [SIGNAL] | -s SIGNAL | -SIGNAL] pid...
16 14
17 Send a signal to a process 15 Send a signal to a process
18
19 */ 16 */
20 17
21 #define FOR_kill 18 #define FOR_kill
22 #include "toys.h" 19 #include "toys.h"
23 20
24 GLOBALS( 21 GLOBALS(
25 char *signame; 22 char *signame;
26 ) 23 )
27 24
28 void kill_main(void) 25 void kill_main(void)
29 { 26 {
30 int signum; 27 int signum;
31 char *tmp, **args = toys.optargs; 28 char *tmp, **args = toys.optargs;
32 pid_t pid; 29 pid_t pid;
33 30
34 // list signal(s) 31 // list signal(s)
35 if (toys.optflags & FLAG_l) { 32 if (toys.optflags & FLAG_l) {
36 if (*args) { 33 if (*args) {
37 int signum = sig_to_num(*args); 34 int signum = sig_to_num(*args);
38 char *s = NULL; 35 char *s = NULL;
39 36
40 if (signum>=0) s = num_to_sig(signum&127); 37 if (signum>=0) s = num_to_sig(signum&127);
41 puts(s ? s : "UNKNOWN"); 38 puts(s ? s : "UNKNOWN");
42 } else sig_to_num(NULL); 39 } else sig_to_num(NULL);
43 return; 40 return;
44 } 41 }
45 42
46 // signal must come before pids, so "kill -9 -1" isn't confusing. 43 // signal must come before pids, so "kill -9 -1" isn't confusing.
47 44
48 if (!TT.signame && *args && **args=='-') TT.signame=*(args++)+1; 45 if (!TT.signame && *args && **args=='-') TT.signame=*(args++)+1;
49 if (TT.signame) { 46 if (TT.signame) {
50 char *arg; 47 char *arg;
51 int i = strtol(TT.signame, &arg, 10); 48 int i = strtol(TT.signame, &arg, 10);
52 if (!*arg) arg = num_to_sig(i); 49 if (!*arg) arg = num_to_sig(i);
53 else arg = TT.signame; 50 else arg = TT.signame;
54 51
55 if (!arg || -1 == (signum = sig_to_num(arg))) 52 if (!arg || -1 == (signum = sig_to_num(arg)))
56 error_exit("Unknown signal '%s'", arg); 53 error_exit("Unknown signal '%s'", arg);
57 } else signum = SIGTERM; 54 } else signum = SIGTERM;
58 55
59 if (!*args) { 56 if (!*args) {
60 toys.exithelp++; 57 toys.exithelp++;
61 error_exit("missing argument"); 58 error_exit("missing argument");
62 } 59 }
63 60
64 while (*args) { 61 while (*args) {
65 char *arg = *(args++); 62 char *arg = *(args++);
66 63
67 pid = strtol(arg, &tmp, 10); 64 pid = strtol(arg, &tmp, 10);
68 if (*tmp || kill(pid, signum) < 0) { 65 if (*tmp || kill(pid, signum) < 0) {
69 error_msg("unknown pid '%s'", arg); 66 error_msg("unknown pid '%s'", arg);
70 toys.exitval = EXIT_FAILURE; 67 toys.exitval = EXIT_FAILURE;
71 } 68 }
72 } 69 }
73 } 70 }