aboutsummaryrefslogtreecommitdiff
path: root/procps/kill.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2006-07-12 19:17:55 +0000
committerRob Landley <rob@landley.net>2006-07-12 19:17:55 +0000
commitc9c1a41c581101f53cc36efae53cd8ebb568962f (patch)
tree0aa4024f33e22567444f78d83d7d4b7986abe795 /procps/kill.c
parent801ab140132a111e9524371c9b8d425579692389 (diff)
downloadbusybox-w32-c9c1a41c581101f53cc36efae53cd8ebb568962f.tar.gz
busybox-w32-c9c1a41c581101f53cc36efae53cd8ebb568962f.tar.bz2
busybox-w32-c9c1a41c581101f53cc36efae53cd8ebb568962f.zip
A couple things that got tangled up in my tree, easier to check in both than
untangle them: Rewrite u_signal_names() into get_signum() and get_signame(), plus trim the signal list to that required by posix (they can specify the numbers for the rest if they really need them). (This is preparatory cleanup for adding a timeout applet like Roberto Foglietta wants.) Export the itoa (added due to Denis Vlasenko, although it's not quite his preferred implementation) from xfuncs.c so it's actually used, and remove several other redundant implementations of itoa and utoa() in the tree.
Diffstat (limited to 'procps/kill.c')
-rw-r--r--procps/kill.c57
1 files changed, 25 insertions, 32 deletions
diff --git a/procps/kill.c b/procps/kill.c
index ca6f4203a..1814e1963 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -18,22 +18,11 @@
18#include <string.h> 18#include <string.h>
19#include <unistd.h> 19#include <unistd.h>
20 20
21#define KILL 0
22#define KILLALL 1
23
24int kill_main(int argc, char **argv) 21int kill_main(int argc, char **argv)
25{ 22{
26 int whichApp, signo = SIGTERM; 23 int killall, signo = SIGTERM, errors = 0, quiet=0;
27 const char *name; 24
28 int errors = 0; 25 killall = (ENABLE_KILLALL && bb_applet_name[4]=='a') ? 1 : 0;
29
30#ifdef CONFIG_KILLALL
31 int quiet=0;
32 /* Figure out what we are trying to do here */
33 whichApp = (strcmp(bb_applet_name, "killall") == 0)? KILLALL : KILL;
34#else
35 whichApp = KILL;
36#endif
37 26
38 /* Parse any options */ 27 /* Parse any options */
39 if (argc < 2) 28 if (argc < 2)
@@ -50,32 +39,38 @@ int kill_main(int argc, char **argv)
50 if(argc==2) { 39 if(argc==2) {
51 /* Print the whole signal list */ 40 /* Print the whole signal list */
52 int col = 0; 41 int col = 0;
53 for(signo=1; signo < NSIG; signo++) { 42
54 name = u_signal_names(0, &signo, 1); 43 for(signo = 0;;) {
55 if(name==NULL) /* unnamed */ 44 char *name = get_signame(++signo);
56 continue; 45 if (isdigit(*name)) break;
57 col += printf("%2d) %-16s", signo, name); 46
58 if (col > 60) { 47 if (col > 60) {
59 printf("\n"); 48 printf("\n");
60 col = 0; 49 col = 0;
61 } 50 }
51 col += printf("%2d) %-16s", signo, name);
62 } 52 }
63 printf("\n"); 53 printf("\n");
64
65 } else { 54 } else {
66 for(argv++; *argv; argv++) { 55 for(argv++; *argv; argv++) {
67 name = u_signal_names(*argv, &signo, -1); 56 char *name;
68 if(name!=NULL) 57
69 printf("%s\n", name); 58 if (isdigit(**argv)) name = get_signame(atoi(*argv));
59 else {
60 int temp = get_signum(*argv);
61 if (temp<0)
62 bb_error_msg_and_die("unknown signal %s", *argv);
63 name = get_signame(temp);
64 }
65 puts(name);
70 } 66 }
71 } 67 }
72 /* If they specified -l, were all done */ 68 /* If they specified -l, were all done */
73 return EXIT_SUCCESS; 69 return EXIT_SUCCESS;
74 } 70 }
75 71
76#ifdef CONFIG_KILLALL
77 /* The -q quiet option */ 72 /* The -q quiet option */
78 if(whichApp != KILL && argv[1][1]=='q' && argv[1][2]=='\0'){ 73 if(killall && argv[1][1]=='q' && argv[1][2]=='\0'){
79 quiet++; 74 quiet++;
80 argv++; 75 argv++;
81 argc--; 76 argc--;
@@ -83,9 +78,8 @@ int kill_main(int argc, char **argv)
83 goto do_it_now; 78 goto do_it_now;
84 } 79 }
85 } 80 }
86#endif
87 81
88 if(!u_signal_names(argv[1]+1, &signo, 0)) 82 if(0>(signo = get_signum(argv[1]+1)))
89 bb_error_msg_and_die( "bad signal name '%s'", argv[1]+1); 83 bb_error_msg_and_die( "bad signal name '%s'", argv[1]+1);
90 argv+=2; 84 argv+=2;
91 argc-=2; 85 argc-=2;
@@ -96,7 +90,7 @@ do_it_now:
96 if (argc <= 0) 90 if (argc <= 0)
97 bb_show_usage(); 91 bb_show_usage();
98 92
99 if (whichApp == KILL) { 93 if (!killall) {
100 /* Looks like they want to do a kill. Do that */ 94 /* Looks like they want to do a kill. Do that */
101 while (--argc >= 0) { 95 while (--argc >= 0) {
102 int pid; 96 int pid;
@@ -111,10 +105,9 @@ do_it_now:
111 argv++; 105 argv++;
112 } 106 }
113 107
114 } 108 } else {
115#ifdef CONFIG_KILLALL
116 else {
117 pid_t myPid=getpid(); 109 pid_t myPid=getpid();
110
118 /* Looks like they want to do a killall. Do that */ 111 /* Looks like they want to do a killall. Do that */
119 while (--argc >= 0) { 112 while (--argc >= 0) {
120 long* pidList; 113 long* pidList;
@@ -141,6 +134,6 @@ do_it_now:
141 argv++; 134 argv++;
142 } 135 }
143 } 136 }
144#endif 137
145 return errors; 138 return errors;
146} 139}