aboutsummaryrefslogtreecommitdiff
path: root/procps
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
parent801ab140132a111e9524371c9b8d425579692389 (diff)
downloadbusybox-c9c1a41c581101f53cc36efae53cd8ebb568962f.tar.gz
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')
-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 @@
*/
#include "busybox.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <limits.h>
-#include <dirent.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <sys/socket.h>
-#include <sys/sysmacros.h>
#define FUSER_PROC_DIR "/proc"
#define FUSER_MAX_LINE 255
@@ -335,7 +323,7 @@ int fuser_main(int argc, char **argv)
optn = fuser_option(argv[i]);
if(optn) opt |= optn;
else if(argv[i][0] == '-') {
- if(!(u_signal_names(argv[i]+1, &killsig, 0)))
+ if(0>(killsig = get_signum(argv[i]+1)))
killsig = SIGTERM;
}
else {
@@ -345,7 +333,6 @@ int fuser_main(int argc, char **argv)
}
if(!fnic) return 1;
- pids = xmalloc(sizeof(pid_list));
inodes = xmalloc(sizeof(inode_list));
for(i=0;i<fnic;i++) {
if(fuser_parse_net_arg(argv[fni[i]], &proto, &port)) {
@@ -354,14 +341,13 @@ int fuser_main(int argc, char **argv)
else {
if(!fuser_file_to_dev_inode(
argv[fni[i]], &dev, &inode)) {
- free(pids);
- free(inodes);
- bb_perror_msg_and_die(
- "Could not open '%s'", argv[fni[i]]);
+ if (ENABLE_FEATURE_CLEAN_UP) free(inodes);
+ bb_perror_msg_and_die("Could not open '%s'", argv[fni[i]]);
}
fuser_add_inode(inodes, dev, inode);
}
}
+ pids = xmalloc(sizeof(pid_list));
success = fuser_scan_proc_pids(opt, inodes, pids);
/* if the first pid in the list is 0, none have been found */
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 @@
#include <string.h>
#include <unistd.h>
-#define KILL 0
-#define KILLALL 1
-
int kill_main(int argc, char **argv)
{
- int whichApp, signo = SIGTERM;
- const char *name;
- int errors = 0;
-
-#ifdef CONFIG_KILLALL
- int quiet=0;
- /* Figure out what we are trying to do here */
- whichApp = (strcmp(bb_applet_name, "killall") == 0)? KILLALL : KILL;
-#else
- whichApp = KILL;
-#endif
+ int killall, signo = SIGTERM, errors = 0, quiet=0;
+
+ killall = (ENABLE_KILLALL && bb_applet_name[4]=='a') ? 1 : 0;
/* Parse any options */
if (argc < 2)
@@ -50,32 +39,38 @@ int kill_main(int argc, char **argv)
if(argc==2) {
/* Print the whole signal list */
int col = 0;
- for(signo=1; signo < NSIG; signo++) {
- name = u_signal_names(0, &signo, 1);
- if(name==NULL) /* unnamed */
- continue;
- col += printf("%2d) %-16s", signo, name);
+
+ for(signo = 0;;) {
+ char *name = get_signame(++signo);
+ if (isdigit(*name)) break;
+
if (col > 60) {
printf("\n");
col = 0;
}
+ col += printf("%2d) %-16s", signo, name);
}
printf("\n");
-
} else {
for(argv++; *argv; argv++) {
- name = u_signal_names(*argv, &signo, -1);
- if(name!=NULL)
- printf("%s\n", name);
+ char *name;
+
+ if (isdigit(**argv)) name = get_signame(atoi(*argv));
+ else {
+ int temp = get_signum(*argv);
+ if (temp<0)
+ bb_error_msg_and_die("unknown signal %s", *argv);
+ name = get_signame(temp);
+ }
+ puts(name);
}
}
/* If they specified -l, were all done */
return EXIT_SUCCESS;
}
-#ifdef CONFIG_KILLALL
/* The -q quiet option */
- if(whichApp != KILL && argv[1][1]=='q' && argv[1][2]=='\0'){
+ if(killall && argv[1][1]=='q' && argv[1][2]=='\0'){
quiet++;
argv++;
argc--;
@@ -83,9 +78,8 @@ int kill_main(int argc, char **argv)
goto do_it_now;
}
}
-#endif
- if(!u_signal_names(argv[1]+1, &signo, 0))
+ if(0>(signo = get_signum(argv[1]+1)))
bb_error_msg_and_die( "bad signal name '%s'", argv[1]+1);
argv+=2;
argc-=2;
@@ -96,7 +90,7 @@ do_it_now:
if (argc <= 0)
bb_show_usage();
- if (whichApp == KILL) {
+ if (!killall) {
/* Looks like they want to do a kill. Do that */
while (--argc >= 0) {
int pid;
@@ -111,10 +105,9 @@ do_it_now:
argv++;
}
- }
-#ifdef CONFIG_KILLALL
- else {
+ } else {
pid_t myPid=getpid();
+
/* Looks like they want to do a killall. Do that */
while (--argc >= 0) {
long* pidList;
@@ -141,6 +134,6 @@ do_it_now:
argv++;
}
}
-#endif
+
return errors;
}