diff options
-rw-r--r-- | include/libbb.h | 11 | ||||
-rw-r--r-- | libbb/u_signal_names.c | 200 | ||||
-rw-r--r-- | networking/netstat.c | 25 | ||||
-rw-r--r-- | networking/traceroute.c | 10 | ||||
-rw-r--r-- | networking/wget.c | 17 | ||||
-rw-r--r-- | procps/fuser.c | 22 | ||||
-rw-r--r-- | procps/kill.c | 57 | ||||
-rw-r--r-- | shell/ash.c | 27 | ||||
-rw-r--r-- | shell/lash.c | 31 | ||||
-rw-r--r-- | shell/msh.c | 41 |
10 files changed, 102 insertions, 339 deletions
diff --git a/include/libbb.h b/include/libbb.h index 0a52b6421..2f9041273 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -16,6 +16,7 @@ | |||
16 | 16 | ||
17 | #include <ctype.h> | 17 | #include <ctype.h> |
18 | #include <dirent.h> | 18 | #include <dirent.h> |
19 | #include <errno.h> | ||
19 | #include <fcntl.h> | 20 | #include <fcntl.h> |
20 | #include <inttypes.h> | 21 | #include <inttypes.h> |
21 | #include <netdb.h> | 22 | #include <netdb.h> |
@@ -25,10 +26,12 @@ | |||
25 | #include <stdarg.h> | 26 | #include <stdarg.h> |
26 | #include <string.h> | 27 | #include <string.h> |
27 | #include <strings.h> | 28 | #include <strings.h> |
29 | #include <sys/ioctl.h> | ||
28 | #include <sys/socket.h> | 30 | #include <sys/socket.h> |
29 | #include <sys/stat.h> | 31 | #include <sys/stat.h> |
30 | #include <sys/time.h> | 32 | #include <sys/time.h> |
31 | #include <sys/types.h> | 33 | #include <sys/types.h> |
34 | #include <sys/wait.h> | ||
32 | #include <termios.h> | 35 | #include <termios.h> |
33 | #include <unistd.h> | 36 | #include <unistd.h> |
34 | 37 | ||
@@ -178,6 +181,10 @@ extern void bb_xdaemon(int nochdir, int noclose); | |||
178 | extern void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); | 181 | extern void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); |
179 | extern void bb_xlisten(int s, int backlog); | 182 | extern void bb_xlisten(int s, int backlog); |
180 | extern void bb_xchdir(const char *path); | 183 | extern void bb_xchdir(const char *path); |
184 | extern void utoa_to_buf(unsigned n, char *buf, unsigned buflen); | ||
185 | extern char *utoa(unsigned n); | ||
186 | extern void itoa_to_buf(int n, char *buf, unsigned buflen); | ||
187 | extern char *itoa(int n); | ||
181 | 188 | ||
182 | #define BB_GETOPT_ERROR 0x80000000UL | 189 | #define BB_GETOPT_ERROR 0x80000000UL |
183 | extern const char *bb_opt_complementally; | 190 | extern const char *bb_opt_complementally; |
@@ -331,7 +338,9 @@ char *dirname (char *path); | |||
331 | 338 | ||
332 | int bb_make_directory (char *path, long mode, int flags); | 339 | int bb_make_directory (char *path, long mode, int flags); |
333 | 340 | ||
334 | const char *u_signal_names(const char *str_sig, int *signo, int startnum); | 341 | int get_signum(char *name); |
342 | char *get_signame(int number); | ||
343 | |||
335 | char *bb_simplify_path(const char *path); | 344 | char *bb_simplify_path(const char *path); |
336 | 345 | ||
337 | enum { /* DO NOT CHANGE THESE VALUES! cp.c depends on them. */ | 346 | enum { /* DO NOT CHANGE THESE VALUES! cp.c depends on them. */ |
diff --git a/libbb/u_signal_names.c b/libbb/u_signal_names.c index bf65fa3e9..62fab810d 100644 --- a/libbb/u_signal_names.c +++ b/libbb/u_signal_names.c | |||
@@ -1,179 +1,59 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * Utility routines. | 3 | * Signal name/number conversion routines. |
4 | * | 4 | * |
5 | * Copyright (C) many different people. | 5 | * Copyright 2006 Rob Landley <rob@landley.net> |
6 | * If you wrote this, please acknowledge your work. | ||
7 | * | 6 | * |
8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
9 | */ | 8 | */ |
10 | 9 | ||
11 | #include <signal.h> | ||
12 | #include <ctype.h> | ||
13 | #include <string.h> | ||
14 | #include <strings.h> | ||
15 | #include <stdlib.h> | ||
16 | #include <stdio.h> | ||
17 | |||
18 | #include "libbb.h" | 10 | #include "libbb.h" |
19 | 11 | ||
20 | struct signal_name { | 12 | static struct signal_name { |
21 | const char *name; | 13 | char *name; |
22 | int number; | 14 | int number; |
15 | } signals[] = { | ||
16 | // SUSv3 says kill must support these, and specifies the numerical values, | ||
17 | // http://www.opengroup.org/onlinepubs/009695399/utilities/kill.html | ||
18 | {"0", 0}, {"HUP", 1}, {"INT", 2}, {"QUIT", 3}, {"ABRT", 6}, {"KILL", 9}, | ||
19 | {"ALRM", 14}, {"TERM", 15}, | ||
20 | // And Posix adds the following: | ||
21 | {"ILL", SIGILL}, {"TRAP", SIGTRAP}, {"FPE", SIGFPE}, {"USR1", SIGUSR1}, | ||
22 | {"SEGV", SIGSEGV}, {"USR2", SIGUSR2}, {"PIPE", SIGPIPE}, {"CHLD", SIGCHLD}, | ||
23 | {"CONT", SIGCONT}, {"STOP", SIGSTOP}, {"TSTP", SIGTSTP}, {"TTIN", SIGTTIN}, | ||
24 | {"TTOU", SIGTTOU} | ||
23 | }; | 25 | }; |
24 | 26 | ||
25 | static const struct signal_name signames[] = { | 27 | // Convert signal name to number. |
26 | /* POSIX signals */ | ||
27 | { "EXIT", 0 }, /* 0 */ | ||
28 | { "HUP", SIGHUP }, /* 1 */ | ||
29 | { "INT", SIGINT }, /* 2 */ | ||
30 | { "QUIT", SIGQUIT }, /* 3 */ | ||
31 | { "ILL", SIGILL }, /* 4 */ | ||
32 | { "ABRT", SIGABRT }, /* 6 */ | ||
33 | { "FPE", SIGFPE }, /* 8 */ | ||
34 | { "KILL", SIGKILL }, /* 9 */ | ||
35 | { "SEGV", SIGSEGV }, /* 11 */ | ||
36 | { "PIPE", SIGPIPE }, /* 13 */ | ||
37 | { "ALRM", SIGALRM }, /* 14 */ | ||
38 | { "TERM", SIGTERM }, /* 15 */ | ||
39 | { "USR1", SIGUSR1 }, /* 10 (arm,i386,m68k,ppc), 30 (alpha,sparc*), 16 (mips) */ | ||
40 | { "USR2", SIGUSR2 }, /* 12 (arm,i386,m68k,ppc), 31 (alpha,sparc*), 17 (mips) */ | ||
41 | { "CHLD", SIGCHLD }, /* 17 (arm,i386,m68k,ppc), 20 (alpha,sparc*), 18 (mips) */ | ||
42 | { "CONT", SIGCONT }, /* 18 (arm,i386,m68k,ppc), 19 (alpha,sparc*), 25 (mips) */ | ||
43 | { "STOP", SIGSTOP }, /* 19 (arm,i386,m68k,ppc), 17 (alpha,sparc*), 23 (mips) */ | ||
44 | { "TSTP", SIGTSTP }, /* 20 (arm,i386,m68k,ppc), 18 (alpha,sparc*), 24 (mips) */ | ||
45 | { "TTIN", SIGTTIN }, /* 21 (arm,i386,m68k,ppc,alpha,sparc*), 26 (mips) */ | ||
46 | { "TTOU", SIGTTOU }, /* 22 (arm,i386,m68k,ppc,alpha,sparc*), 27 (mips) */ | ||
47 | /* Miscellaneous other signals */ | ||
48 | #ifdef SIGTRAP | ||
49 | { "TRAP", SIGTRAP }, /* 5 */ | ||
50 | #endif | ||
51 | #ifdef SIGIOT | ||
52 | { "IOT", SIGIOT }, /* 6, same as SIGABRT */ | ||
53 | #endif | ||
54 | #ifdef SIGEMT | ||
55 | { "EMT", SIGEMT }, /* 7 (mips,alpha,sparc*) */ | ||
56 | #endif | ||
57 | #ifdef SIGBUS | ||
58 | { "BUS", SIGBUS }, /* 7 (arm,i386,m68k,ppc), 10 (mips,alpha,sparc*) */ | ||
59 | #endif | ||
60 | #ifdef SIGSYS | ||
61 | { "SYS", SIGSYS }, /* 12 (mips,alpha,sparc*) */ | ||
62 | #endif | ||
63 | #ifdef SIGSTKFLT | ||
64 | { "STKFLT", SIGSTKFLT }, /* 16 (arm,i386,m68k,ppc) */ | ||
65 | #endif | ||
66 | #ifdef SIGURG | ||
67 | { "URG", SIGURG }, /* 23 (arm,i386,m68k,ppc), 16 (alpha,sparc*), 21 (mips) */ | ||
68 | #endif | ||
69 | #ifdef SIGIO | ||
70 | { "IO", SIGIO }, /* 29 (arm,i386,m68k,ppc), 23 (alpha,sparc*), 22 (mips) */ | ||
71 | #endif | ||
72 | #ifdef SIGPOLL | ||
73 | { "POLL", SIGPOLL }, /* same as SIGIO */ | ||
74 | #endif | ||
75 | #ifdef SIGCLD | ||
76 | { "CLD", SIGCLD }, /* same as SIGCHLD (mips) */ | ||
77 | #endif | ||
78 | #ifdef SIGXCPU | ||
79 | { "XCPU", SIGXCPU }, /* 24 (arm,i386,m68k,ppc,alpha,sparc*), 30 (mips) */ | ||
80 | #endif | ||
81 | #ifdef SIGXFSZ | ||
82 | { "XFSZ", SIGXFSZ }, /* 25 (arm,i386,m68k,ppc,alpha,sparc*), 31 (mips) */ | ||
83 | #endif | ||
84 | #ifdef SIGVTALRM | ||
85 | { "VTALRM", SIGVTALRM }, /* 26 (arm,i386,m68k,ppc,alpha,sparc*), 28 (mips) */ | ||
86 | #endif | ||
87 | #ifdef SIGPROF | ||
88 | { "PROF", SIGPROF }, /* 27 (arm,i386,m68k,ppc,alpha,sparc*), 29 (mips) */ | ||
89 | #endif | ||
90 | #ifdef SIGPWR | ||
91 | { "PWR", SIGPWR }, /* 30 (arm,i386,m68k,ppc), 29 (alpha,sparc*), 19 (mips) */ | ||
92 | #endif | ||
93 | #ifdef SIGINFO | ||
94 | { "INFO", SIGINFO }, /* 29 (alpha) */ | ||
95 | #endif | ||
96 | #ifdef SIGLOST | ||
97 | { "LOST", SIGLOST }, /* 29 (arm,i386,m68k,ppc,sparc*) */ | ||
98 | #endif | ||
99 | #ifdef SIGWINCH | ||
100 | { "WINCH", SIGWINCH }, /* 28 (arm,i386,m68k,ppc,alpha,sparc*), 20 (mips) */ | ||
101 | #endif | ||
102 | #ifdef SIGUNUSED | ||
103 | { "UNUSED", SIGUNUSED }, /* 31 (arm,i386,m68k,ppc) */ | ||
104 | #endif | ||
105 | {0, 0} | ||
106 | }; | ||
107 | 28 | ||
108 | /* | 29 | int get_signum(char *name) |
109 | if str_sig == NULL returned signal name [*signo], | 30 | { |
110 | if str_sig != NULL - set *signo from signal_name, | 31 | int i; |
111 | findings with digit number or with or without SIG-prefix name | 32 | |
112 | 33 | i = atoi(name); | |
113 | if startnum=0 flag for support finding zero signal, | 34 | if(i) return i; |
114 | but str_sig="0" always found, (hmm - standart or realize?) | 35 | for(i=0; i < sizeof(signals) / sizeof(struct signal_name); i++) |
115 | if startnum<0 returned reverse signal_number <-> signal_name | 36 | if (!strcasecmp(signals[i].name, name) || |
116 | if found error - returned NULL | 37 | (!strncasecmp(signals[i].name, "SIG", 3) |
38 | && !strcasecmp(signals[i].name+3, signals[i].name))) | ||
39 | return signals[i].number; | ||
40 | return -1; | ||
41 | } | ||
117 | 42 | ||
118 | */ | 43 | // Convert signal number to name |
119 | 44 | ||
120 | const char * | 45 | char *get_signame(int number) |
121 | u_signal_names(const char *str_sig, int *signo, int startnum) | ||
122 | { | 46 | { |
123 | static char retstr[16]; | 47 | int i; |
124 | const struct signal_name *s = signames; | 48 | static char buf[8]; |
125 | static const char prefix[] = "SIG"; | 49 | |
126 | const char *sptr; | 50 | itoa_to_buf(number, buf, 8); |
127 | 51 | for (i=0; i < sizeof(signals) / sizeof(struct signal_name); i++) { | |
128 | if(startnum) | 52 | if (number == signals[i].number) { |
129 | s++; | 53 | sprintf("SIG%s", signals[i].name); |
130 | if(str_sig==NULL) { | 54 | break; |
131 | while (s->name != 0) { | ||
132 | if(s->number == *signo) | ||
133 | break; | ||
134 | s++; | ||
135 | } | ||
136 | } else { | ||
137 | if (isdigit(((unsigned char)*str_sig))) { | ||
138 | char *endp; | ||
139 | long int sn = strtol(str_sig, &endp, 10); | ||
140 | /* test correct and overflow */ | ||
141 | if(*endp == 0 && sn >= 0 && sn < NSIG) { | ||
142 | *signo = (int)sn; | ||
143 | /* test for unnamed */ | ||
144 | sptr = u_signal_names(0, signo, 0); | ||
145 | if(sptr==NULL) | ||
146 | return NULL; | ||
147 | if(sn!=0) | ||
148 | sptr += 3; | ||
149 | return sptr; | ||
150 | } | ||
151 | } else { | ||
152 | sptr = str_sig; | ||
153 | while (s->name != 0) { | ||
154 | if (strcasecmp(s->name, sptr) == 0) { | ||
155 | *signo = s->number; | ||
156 | if(startnum<0) { | ||
157 | sprintf(retstr, "%d", *signo); | ||
158 | return retstr; | ||
159 | } | ||
160 | break; | ||
161 | } | ||
162 | if(s!=signames && sptr == str_sig && | ||
163 | strncasecmp(sptr, prefix, 3) == 0) { | ||
164 | sptr += 3; /* strlen(prefix) */ | ||
165 | continue; | ||
166 | } | ||
167 | sptr = str_sig; | ||
168 | s++; | ||
169 | } | ||
170 | } | 55 | } |
171 | } | 56 | } |
172 | if(s->name==0) | 57 | |
173 | return NULL; | 58 | return buf; |
174 | if(s!=signames) | ||
175 | strcpy(retstr, prefix); | ||
176 | else | ||
177 | retstr[0] = 0; | ||
178 | return strcat(retstr, s->name); | ||
179 | } | 59 | } |
diff --git a/networking/netstat.c b/networking/netstat.c index 4faa40cd4..6d91bb3f4 100644 --- a/networking/netstat.c +++ b/networking/netstat.c | |||
@@ -11,18 +11,8 @@ | |||
11 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 11 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <stdio.h> | ||
15 | #include <stdlib.h> | ||
16 | #include <string.h> | ||
17 | #include <stdarg.h> | ||
18 | #include <signal.h> | ||
19 | #include <errno.h> | ||
20 | #include <sys/stat.h> | ||
21 | #include <dirent.h> | ||
22 | #include <unistd.h> | ||
23 | #include "inet_common.h" | ||
24 | #include "busybox.h" | 14 | #include "busybox.h" |
25 | #include "pwd_.h" | 15 | #include "inet_common.h" |
26 | 16 | ||
27 | #ifdef CONFIG_ROUTE | 17 | #ifdef CONFIG_ROUTE |
28 | extern void displayroutes(int noresolve, int netstatfmt); | 18 | extern void displayroutes(int noresolve, int netstatfmt); |
@@ -87,19 +77,6 @@ typedef enum { | |||
87 | #define SO_WAITDATA (1<<17) /* wait data to read */ | 77 | #define SO_WAITDATA (1<<17) /* wait data to read */ |
88 | #define SO_NOSPACE (1<<18) /* no space to write */ | 78 | #define SO_NOSPACE (1<<18) /* no space to write */ |
89 | 79 | ||
90 | static char *itoa(unsigned int i) | ||
91 | { | ||
92 | /* 21 digits plus null terminator, good for 64-bit or smaller ints */ | ||
93 | static char local[22]; | ||
94 | char *p = &local[21]; | ||
95 | *p-- = '\0'; | ||
96 | do { | ||
97 | *p-- = '0' + i % 10; | ||
98 | i /= 10; | ||
99 | } while (i > 0); | ||
100 | return p + 1; | ||
101 | } | ||
102 | |||
103 | static char *get_sname(int port, const char *proto, int num) | 80 | static char *get_sname(int port, const char *proto, int num) |
104 | { | 81 | { |
105 | char *str=itoa(ntohs(port)); | 82 | char *str=itoa(ntohs(port)); |
diff --git a/networking/traceroute.c b/networking/traceroute.c index 190f19ddc..79f3957a6 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c | |||
@@ -548,7 +548,7 @@ static int | |||
548 | wait_for_reply(int sock, struct sockaddr_in *fromp, const struct timeval *tp) | 548 | wait_for_reply(int sock, struct sockaddr_in *fromp, const struct timeval *tp) |
549 | { | 549 | { |
550 | fd_set fds; | 550 | fd_set fds; |
551 | struct timeval now, wait; | 551 | struct timeval now, tvwait; |
552 | struct timezone tz; | 552 | struct timezone tz; |
553 | int cc = 0; | 553 | int cc = 0; |
554 | socklen_t fromlen = sizeof(*fromp); | 554 | socklen_t fromlen = sizeof(*fromp); |
@@ -556,12 +556,12 @@ wait_for_reply(int sock, struct sockaddr_in *fromp, const struct timeval *tp) | |||
556 | FD_ZERO(&fds); | 556 | FD_ZERO(&fds); |
557 | FD_SET(sock, &fds); | 557 | FD_SET(sock, &fds); |
558 | 558 | ||
559 | wait.tv_sec = tp->tv_sec + waittime; | 559 | tvwait.tv_sec = tp->tv_sec + waittime; |
560 | wait.tv_usec = tp->tv_usec; | 560 | tvwait.tv_usec = tp->tv_usec; |
561 | (void)gettimeofday(&now, &tz); | 561 | (void)gettimeofday(&now, &tz); |
562 | tvsub(&wait, &now); | 562 | tvsub(&tvwait, &now); |
563 | 563 | ||
564 | if (select(sock + 1, &fds, NULL, NULL, &wait) > 0) | 564 | if (select(sock + 1, &fds, NULL, NULL, &tvwait) > 0) |
565 | cc = recvfrom(sock, (char *)packet, sizeof(packet), 0, | 565 | cc = recvfrom(sock, (char *)packet, sizeof(packet), 0, |
566 | (struct sockaddr *)fromp, &fromlen); | 566 | (struct sockaddr *)fromp, &fromlen); |
567 | 567 | ||
diff --git a/networking/wget.c b/networking/wget.c index 64cdf6220..6565bb1f3 100644 --- a/networking/wget.c +++ b/networking/wget.c | |||
@@ -697,12 +697,11 @@ updateprogressmeter(int ignore) | |||
697 | errno = save_errno; | 697 | errno = save_errno; |
698 | } | 698 | } |
699 | 699 | ||
700 | static void | 700 | static void alarmtimer(int iwait) |
701 | alarmtimer(int wait) | ||
702 | { | 701 | { |
703 | struct itimerval itv; | 702 | struct itimerval itv; |
704 | 703 | ||
705 | itv.it_value.tv_sec = wait; | 704 | itv.it_value.tv_sec = iwait; |
706 | itv.it_value.tv_usec = 0; | 705 | itv.it_value.tv_usec = 0; |
707 | itv.it_interval = itv.it_value; | 706 | itv.it_interval = itv.it_value; |
708 | setitimer(ITIMER_REAL, &itv, NULL); | 707 | setitimer(ITIMER_REAL, &itv, NULL); |
@@ -715,7 +714,7 @@ progressmeter(int flag) | |||
715 | static struct timeval lastupdate; | 714 | static struct timeval lastupdate; |
716 | static off_t lastsize, totalsize; | 715 | static off_t lastsize, totalsize; |
717 | 716 | ||
718 | struct timeval now, td, wait; | 717 | struct timeval now, td, tvwait; |
719 | off_t abbrevsize; | 718 | off_t abbrevsize; |
720 | int elapsed, ratio, barlength, i; | 719 | int elapsed, ratio, barlength, i; |
721 | char buf[256]; | 720 | char buf[256]; |
@@ -753,18 +752,18 @@ progressmeter(int flag) | |||
753 | /* See http://en.wikipedia.org/wiki/Tera */ | 752 | /* See http://en.wikipedia.org/wiki/Tera */ |
754 | fprintf(stderr, "%6d %c%c ", (int)abbrevsize, " KMGTPEZY"[i], i?'B':' '); | 753 | fprintf(stderr, "%6d %c%c ", (int)abbrevsize, " KMGTPEZY"[i], i?'B':' '); |
755 | 754 | ||
756 | timersub(&now, &lastupdate, &wait); | 755 | timersub(&now, &lastupdate, &tvwait); |
757 | if (transferred > lastsize) { | 756 | if (transferred > lastsize) { |
758 | lastupdate = now; | 757 | lastupdate = now; |
759 | lastsize = transferred; | 758 | lastsize = transferred; |
760 | if (wait.tv_sec >= STALLTIME) | 759 | if (tvwait.tv_sec >= STALLTIME) |
761 | timeradd(&start, &wait, &start); | 760 | timeradd(&start, &tvwait, &start); |
762 | wait.tv_sec = 0; | 761 | tvwait.tv_sec = 0; |
763 | } | 762 | } |
764 | timersub(&now, &start, &td); | 763 | timersub(&now, &start, &td); |
765 | elapsed = td.tv_sec; | 764 | elapsed = td.tv_sec; |
766 | 765 | ||
767 | if (wait.tv_sec >= STALLTIME) { | 766 | if (tvwait.tv_sec >= STALLTIME) { |
768 | fprintf(stderr, " - stalled -"); | 767 | fprintf(stderr, " - stalled -"); |
769 | } else if (transferred <= 0 || elapsed <= 0 || transferred > totalsize || chunked) { | 768 | } else if (transferred <= 0 || elapsed <= 0 || transferred > totalsize || chunked) { |
770 | fprintf(stderr, "--:--:-- ETA"); | 769 | fprintf(stderr, "--:--:-- ETA"); |
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 | |||
24 | int kill_main(int argc, char **argv) | 21 | int 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 | } |
diff --git a/shell/ash.c b/shell/ash.c index ba99381a2..de8d06e90 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -2035,7 +2035,6 @@ static void onsig(int); | |||
2035 | static int dotrap(void); | 2035 | static int dotrap(void); |
2036 | static void setinteractive(int); | 2036 | static void setinteractive(int); |
2037 | static void exitshell(void) ATTRIBUTE_NORETURN; | 2037 | static void exitshell(void) ATTRIBUTE_NORETURN; |
2038 | static int decode_signal(const char *, int); | ||
2039 | 2038 | ||
2040 | /* | 2039 | /* |
2041 | * This routine is called when an error or an interrupt occurs in an | 2040 | * This routine is called when an error or an interrupt occurs in an |
@@ -6548,7 +6547,7 @@ usage: | |||
6548 | } | 6547 | } |
6549 | 6548 | ||
6550 | if (**++argv == '-') { | 6549 | if (**++argv == '-') { |
6551 | signo = decode_signal(*argv + 1, 1); | 6550 | signo = get_signum(*argv + 1); |
6552 | if (signo < 0) { | 6551 | if (signo < 0) { |
6553 | int c; | 6552 | int c; |
6554 | 6553 | ||
@@ -6562,7 +6561,7 @@ usage: | |||
6562 | list = 1; | 6561 | list = 1; |
6563 | break; | 6562 | break; |
6564 | case 's': | 6563 | case 's': |
6565 | signo = decode_signal(optionarg, 1); | 6564 | signo = get_signum(optionarg); |
6566 | if (signo < 0) { | 6565 | if (signo < 0) { |
6567 | sh_error( | 6566 | sh_error( |
6568 | "invalid signal number or name: %s", | 6567 | "invalid signal number or name: %s", |
@@ -6588,14 +6587,14 @@ usage: | |||
6588 | 6587 | ||
6589 | if (!*argv) { | 6588 | if (!*argv) { |
6590 | for (i = 1; i < NSIG; i++) { | 6589 | for (i = 1; i < NSIG; i++) { |
6591 | name = u_signal_names(0, &i, 1); | 6590 | name = get_signame(i); |
6592 | if (name) | 6591 | if (isdigit(*name)) |
6593 | out1fmt(snlfmt, name); | 6592 | out1fmt(snlfmt, name); |
6594 | } | 6593 | } |
6595 | return 0; | 6594 | return 0; |
6596 | } | 6595 | } |
6597 | name = u_signal_names(*argptr, &signo, -1); | 6596 | name = get_signame(signo); |
6598 | if (name) | 6597 | if (isdigit(*name)) |
6599 | out1fmt(snlfmt, name); | 6598 | out1fmt(snlfmt, name); |
6600 | else | 6599 | else |
6601 | sh_error("invalid signal number or exit status: %s", *argptr); | 6600 | sh_error("invalid signal number or exit status: %s", *argptr); |
@@ -11617,9 +11616,7 @@ trapcmd(int argc, char **argv) | |||
11617 | if (trap[signo] != NULL) { | 11616 | if (trap[signo] != NULL) { |
11618 | const char *sn; | 11617 | const char *sn; |
11619 | 11618 | ||
11620 | sn = u_signal_names(0, &signo, 0); | 11619 | sn = get_signame(signo); |
11621 | if (sn == NULL) | ||
11622 | sn = "???"; | ||
11623 | out1fmt("trap -- %s %s\n", | 11620 | out1fmt("trap -- %s %s\n", |
11624 | single_quote(trap[signo]), sn); | 11621 | single_quote(trap[signo]), sn); |
11625 | } | 11622 | } |
@@ -11631,7 +11628,7 @@ trapcmd(int argc, char **argv) | |||
11631 | else | 11628 | else |
11632 | action = *ap++; | 11629 | action = *ap++; |
11633 | while (*ap) { | 11630 | while (*ap) { |
11634 | if ((signo = decode_signal(*ap, 0)) < 0) | 11631 | if ((signo = get_signum(*ap)) < 0) |
11635 | sh_error("%s: bad trap", *ap); | 11632 | sh_error("%s: bad trap", *ap); |
11636 | INTOFF; | 11633 | INTOFF; |
11637 | if (action) { | 11634 | if (action) { |
@@ -11934,14 +11931,6 @@ out: | |||
11934 | /* NOTREACHED */ | 11931 | /* NOTREACHED */ |
11935 | } | 11932 | } |
11936 | 11933 | ||
11937 | static int decode_signal(const char *string, int minsig) | ||
11938 | { | ||
11939 | int signo; | ||
11940 | const char *name = u_signal_names(string, &signo, minsig); | ||
11941 | |||
11942 | return name ? signo : -1; | ||
11943 | } | ||
11944 | |||
11945 | /* var.c */ | 11934 | /* var.c */ |
11946 | 11935 | ||
11947 | static struct var *vartab[VTABSIZE]; | 11936 | static struct var *vartab[VTABSIZE]; |
diff --git a/shell/lash.c b/shell/lash.c index c5aaf1d1f..92c24d1c2 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
@@ -22,18 +22,7 @@ | |||
22 | 22 | ||
23 | 23 | ||
24 | #include "busybox.h" | 24 | #include "busybox.h" |
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | #include <ctype.h> | ||
28 | #include <errno.h> | ||
29 | #include <fcntl.h> | ||
30 | #include <signal.h> | ||
31 | #include <string.h> | ||
32 | #include <sys/ioctl.h> | ||
33 | #include <sys/wait.h> | ||
34 | #include <unistd.h> | ||
35 | #include <getopt.h> | 25 | #include <getopt.h> |
36 | #include <termios.h> | ||
37 | #include "cmdedit.h" | 26 | #include "cmdedit.h" |
38 | 27 | ||
39 | #ifdef CONFIG_LOCALE_SUPPORT | 28 | #ifdef CONFIG_LOCALE_SUPPORT |
@@ -697,26 +686,6 @@ static int get_command(FILE * source, char *command) | |||
697 | return 0; | 686 | return 0; |
698 | } | 687 | } |
699 | 688 | ||
700 | static char* itoa(int i) | ||
701 | { | ||
702 | static char a[7]; /* Max 7 ints */ | ||
703 | char *b = a + sizeof(a) - 1; | ||
704 | int sign = (i < 0); | ||
705 | |||
706 | if (sign) | ||
707 | i = -i; | ||
708 | *b = 0; | ||
709 | do | ||
710 | { | ||
711 | *--b = '0' + (i % 10); | ||
712 | i /= 10; | ||
713 | } | ||
714 | while (i); | ||
715 | if (sign) | ||
716 | *--b = '-'; | ||
717 | return b; | ||
718 | } | ||
719 | |||
720 | static char * strsep_space( char *string, int * ix) | 689 | static char * strsep_space( char *string, int * ix) |
721 | { | 690 | { |
722 | char *token; | 691 | char *token; |
diff --git a/shell/msh.c b/shell/msh.c index 633070112..b491a08a4 100644 --- a/shell/msh.c +++ b/shell/msh.c | |||
@@ -10,41 +10,12 @@ | |||
10 | * Robert Schwebel <r.schwebel@pengutronix.de> | 10 | * Robert Schwebel <r.schwebel@pengutronix.de> |
11 | * Erik Andersen <andersen@codepoet.org> | 11 | * Erik Andersen <andersen@codepoet.org> |
12 | * | 12 | * |
13 | * This program is free software; you can redistribute it and/or modify | 13 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
14 | * it under the terms of the GNU General Public License as published by | ||
15 | * the Free Software Foundation; either version 2 of the License, or | ||
16 | * (at your option) any later version. | ||
17 | * | ||
18 | * This program is distributed in the hope that it will be useful, | ||
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
21 | * General Public License for more details. | ||
22 | * | ||
23 | * You should have received a copy of the GNU General Public License | ||
24 | * along with this program; if not, write to the Free Software | ||
25 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
26 | * | ||
27 | * Original copyright notice is retained at the end of this file. | ||
28 | */ | 14 | */ |
29 | 15 | ||
30 | #include "busybox.h" | 16 | #include "busybox.h" |
31 | #include <ctype.h> | ||
32 | #include <dirent.h> | ||
33 | #include <errno.h> | ||
34 | #include <fcntl.h> | ||
35 | #include <limits.h> | ||
36 | #include <setjmp.h> | 17 | #include <setjmp.h> |
37 | #include <signal.h> | ||
38 | #include <stddef.h> | ||
39 | #include <stdio.h> | ||
40 | #include <stdlib.h> | ||
41 | #include <string.h> | ||
42 | #include <time.h> | ||
43 | #include <unistd.h> | ||
44 | #include <sys/stat.h> | ||
45 | #include <sys/times.h> | 18 | #include <sys/times.h> |
46 | #include <sys/types.h> | ||
47 | #include <sys/wait.h> | ||
48 | 19 | ||
49 | #include "cmdedit.h" | 20 | #include "cmdedit.h" |
50 | 21 | ||
@@ -293,7 +264,6 @@ static char *space(int n); | |||
293 | static char *strsave(char *s, int a); | 264 | static char *strsave(char *s, int a); |
294 | static char *evalstr(char *cp, int f); | 265 | static char *evalstr(char *cp, int f); |
295 | static char *putn(int n); | 266 | static char *putn(int n); |
296 | static char *itoa(int n); | ||
297 | static char *unquote(char *as); | 267 | static char *unquote(char *as); |
298 | static struct var *lookup(char *n); | 268 | static struct var *lookup(char *n); |
299 | static int rlookup(char *n); | 269 | static int rlookup(char *n); |
@@ -1252,15 +1222,6 @@ static char *putn(int n) | |||
1252 | return (itoa(n)); | 1222 | return (itoa(n)); |
1253 | } | 1223 | } |
1254 | 1224 | ||
1255 | static char *itoa(int n) | ||
1256 | { | ||
1257 | static char s[20]; | ||
1258 | |||
1259 | snprintf(s, sizeof(s), "%u", n); | ||
1260 | return (s); | ||
1261 | } | ||
1262 | |||
1263 | |||
1264 | static void next(int f) | 1225 | static void next(int f) |
1265 | { | 1226 | { |
1266 | PUSHIO(afile, f, filechar); | 1227 | PUSHIO(afile, f, filechar); |