aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
authorlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-07-12 19:17:55 +0000
committerlandley <landley@69ca8d6d-28ef-0310-b511-8ec308f3f277>2006-07-12 19:17:55 +0000
commit4c90819a28a6ff368dc8ec867714cf856e6b58f3 (patch)
tree0aa4024f33e22567444f78d83d7d4b7986abe795 /procps
parentf09cc3b1b53e74ebe0f5733f73d55846d25194ec (diff)
downloadbusybox-w32-4c90819a28a6ff368dc8ec867714cf856e6b58f3.tar.gz
busybox-w32-4c90819a28a6ff368dc8ec867714cf856e6b58f3.tar.bz2
busybox-w32-4c90819a28a6ff368dc8ec867714cf856e6b58f3.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. git-svn-id: svn://busybox.net/trunk/busybox@15687 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'procps')
-rw-r--r--procps/fuser.c22
-rw-r--r--procps/kill.c57
2 files changed, 29 insertions, 50 deletions
diff --git a/procps/fuser.c b/procps/fuser.c
index 1a4f612f1..2965fc34b 100644
--- a/procps/fuser.c
+++ b/procps/fuser.c
@@ -9,18 +9,6 @@
9 */ 9 */
10 10
11#include "busybox.h" 11#include "busybox.h"
12#include <stdio.h>
13#include <stdlib.h>
14#include <unistd.h>
15#include <string.h>
16#include <limits.h>
17#include <dirent.h>
18#include <signal.h>
19#include <sys/types.h>
20#include <sys/ioctl.h>
21#include <sys/stat.h>
22#include <sys/socket.h>
23#include <sys/sysmacros.h>
24 12
25#define FUSER_PROC_DIR "/proc" 13#define FUSER_PROC_DIR "/proc"
26#define FUSER_MAX_LINE 255 14#define FUSER_MAX_LINE 255
@@ -335,7 +323,7 @@ int fuser_main(int argc, char **argv)
335 optn = fuser_option(argv[i]); 323 optn = fuser_option(argv[i]);
336 if(optn) opt |= optn; 324 if(optn) opt |= optn;
337 else if(argv[i][0] == '-') { 325 else if(argv[i][0] == '-') {
338 if(!(u_signal_names(argv[i]+1, &killsig, 0))) 326 if(0>(killsig = get_signum(argv[i]+1)))
339 killsig = SIGTERM; 327 killsig = SIGTERM;
340 } 328 }
341 else { 329 else {
@@ -345,7 +333,6 @@ int fuser_main(int argc, char **argv)
345 } 333 }
346 if(!fnic) return 1; 334 if(!fnic) return 1;
347 335
348 pids = xmalloc(sizeof(pid_list));
349 inodes = xmalloc(sizeof(inode_list)); 336 inodes = xmalloc(sizeof(inode_list));
350 for(i=0;i<fnic;i++) { 337 for(i=0;i<fnic;i++) {
351 if(fuser_parse_net_arg(argv[fni[i]], &proto, &port)) { 338 if(fuser_parse_net_arg(argv[fni[i]], &proto, &port)) {
@@ -354,14 +341,13 @@ int fuser_main(int argc, char **argv)
354 else { 341 else {
355 if(!fuser_file_to_dev_inode( 342 if(!fuser_file_to_dev_inode(
356 argv[fni[i]], &dev, &inode)) { 343 argv[fni[i]], &dev, &inode)) {
357 free(pids); 344 if (ENABLE_FEATURE_CLEAN_UP) free(inodes);
358 free(inodes); 345 bb_perror_msg_and_die("Could not open '%s'", argv[fni[i]]);
359 bb_perror_msg_and_die(
360 "Could not open '%s'", argv[fni[i]]);
361 } 346 }
362 fuser_add_inode(inodes, dev, inode); 347 fuser_add_inode(inodes, dev, inode);
363 } 348 }
364 } 349 }
350 pids = xmalloc(sizeof(pid_list));
365 success = fuser_scan_proc_pids(opt, inodes, pids); 351 success = fuser_scan_proc_pids(opt, inodes, pids);
366 /* if the first pid in the list is 0, none have been found */ 352 /* if the first pid in the list is 0, none have been found */
367 if(pids->pid == 0) success = 0; 353 if(pids->pid == 0) success = 0;
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}