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.
This commit is contained in:
Rob Landley 2006-07-12 19:17:55 +00:00
parent 801ab14013
commit c9c1a41c58
10 changed files with 102 additions and 339 deletions

View File

@ -16,6 +16,7 @@
#include <ctype.h> #include <ctype.h>
#include <dirent.h> #include <dirent.h>
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <inttypes.h> #include <inttypes.h>
#include <netdb.h> #include <netdb.h>
@ -25,10 +26,12 @@
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <sys/ioctl.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h>
#include <termios.h> #include <termios.h>
#include <unistd.h> #include <unistd.h>
@ -178,6 +181,10 @@ extern void bb_xdaemon(int nochdir, int noclose);
extern void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen); extern void bb_xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen);
extern void bb_xlisten(int s, int backlog); extern void bb_xlisten(int s, int backlog);
extern void bb_xchdir(const char *path); extern void bb_xchdir(const char *path);
extern void utoa_to_buf(unsigned n, char *buf, unsigned buflen);
extern char *utoa(unsigned n);
extern void itoa_to_buf(int n, char *buf, unsigned buflen);
extern char *itoa(int n);
#define BB_GETOPT_ERROR 0x80000000UL #define BB_GETOPT_ERROR 0x80000000UL
extern const char *bb_opt_complementally; extern const char *bb_opt_complementally;
@ -331,7 +338,9 @@ char *dirname (char *path);
int bb_make_directory (char *path, long mode, int flags); int bb_make_directory (char *path, long mode, int flags);
const char *u_signal_names(const char *str_sig, int *signo, int startnum); int get_signum(char *name);
char *get_signame(int number);
char *bb_simplify_path(const char *path); char *bb_simplify_path(const char *path);
enum { /* DO NOT CHANGE THESE VALUES! cp.c depends on them. */ enum { /* DO NOT CHANGE THESE VALUES! cp.c depends on them. */

View File

@ -1,179 +1,59 @@
/* vi: set sw=4 ts=4: */ /* vi: set sw=4 ts=4: */
/* /*
* Utility routines. * Signal name/number conversion routines.
* *
* Copyright (C) many different people. * Copyright 2006 Rob Landley <rob@landley.net>
* If you wrote this, please acknowledge your work.
* *
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/ */
#include <signal.h>
#include <ctype.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <stdio.h>
#include "libbb.h" #include "libbb.h"
struct signal_name { static struct signal_name {
const char *name; char *name;
int number; int number;
} signals[] = {
// SUSv3 says kill must support these, and specifies the numerical values,
// http://www.opengroup.org/onlinepubs/009695399/utilities/kill.html
{"0", 0}, {"HUP", 1}, {"INT", 2}, {"QUIT", 3}, {"ABRT", 6}, {"KILL", 9},
{"ALRM", 14}, {"TERM", 15},
// And Posix adds the following:
{"ILL", SIGILL}, {"TRAP", SIGTRAP}, {"FPE", SIGFPE}, {"USR1", SIGUSR1},
{"SEGV", SIGSEGV}, {"USR2", SIGUSR2}, {"PIPE", SIGPIPE}, {"CHLD", SIGCHLD},
{"CONT", SIGCONT}, {"STOP", SIGSTOP}, {"TSTP", SIGTSTP}, {"TTIN", SIGTTIN},
{"TTOU", SIGTTOU}
}; };
static const struct signal_name signames[] = { // Convert signal name to number.
/* POSIX signals */
{ "EXIT", 0 }, /* 0 */
{ "HUP", SIGHUP }, /* 1 */
{ "INT", SIGINT }, /* 2 */
{ "QUIT", SIGQUIT }, /* 3 */
{ "ILL", SIGILL }, /* 4 */
{ "ABRT", SIGABRT }, /* 6 */
{ "FPE", SIGFPE }, /* 8 */
{ "KILL", SIGKILL }, /* 9 */
{ "SEGV", SIGSEGV }, /* 11 */
{ "PIPE", SIGPIPE }, /* 13 */
{ "ALRM", SIGALRM }, /* 14 */
{ "TERM", SIGTERM }, /* 15 */
{ "USR1", SIGUSR1 }, /* 10 (arm,i386,m68k,ppc), 30 (alpha,sparc*), 16 (mips) */
{ "USR2", SIGUSR2 }, /* 12 (arm,i386,m68k,ppc), 31 (alpha,sparc*), 17 (mips) */
{ "CHLD", SIGCHLD }, /* 17 (arm,i386,m68k,ppc), 20 (alpha,sparc*), 18 (mips) */
{ "CONT", SIGCONT }, /* 18 (arm,i386,m68k,ppc), 19 (alpha,sparc*), 25 (mips) */
{ "STOP", SIGSTOP }, /* 19 (arm,i386,m68k,ppc), 17 (alpha,sparc*), 23 (mips) */
{ "TSTP", SIGTSTP }, /* 20 (arm,i386,m68k,ppc), 18 (alpha,sparc*), 24 (mips) */
{ "TTIN", SIGTTIN }, /* 21 (arm,i386,m68k,ppc,alpha,sparc*), 26 (mips) */
{ "TTOU", SIGTTOU }, /* 22 (arm,i386,m68k,ppc,alpha,sparc*), 27 (mips) */
/* Miscellaneous other signals */
#ifdef SIGTRAP
{ "TRAP", SIGTRAP }, /* 5 */
#endif
#ifdef SIGIOT
{ "IOT", SIGIOT }, /* 6, same as SIGABRT */
#endif
#ifdef SIGEMT
{ "EMT", SIGEMT }, /* 7 (mips,alpha,sparc*) */
#endif
#ifdef SIGBUS
{ "BUS", SIGBUS }, /* 7 (arm,i386,m68k,ppc), 10 (mips,alpha,sparc*) */
#endif
#ifdef SIGSYS
{ "SYS", SIGSYS }, /* 12 (mips,alpha,sparc*) */
#endif
#ifdef SIGSTKFLT
{ "STKFLT", SIGSTKFLT }, /* 16 (arm,i386,m68k,ppc) */
#endif
#ifdef SIGURG
{ "URG", SIGURG }, /* 23 (arm,i386,m68k,ppc), 16 (alpha,sparc*), 21 (mips) */
#endif
#ifdef SIGIO
{ "IO", SIGIO }, /* 29 (arm,i386,m68k,ppc), 23 (alpha,sparc*), 22 (mips) */
#endif
#ifdef SIGPOLL
{ "POLL", SIGPOLL }, /* same as SIGIO */
#endif
#ifdef SIGCLD
{ "CLD", SIGCLD }, /* same as SIGCHLD (mips) */
#endif
#ifdef SIGXCPU
{ "XCPU", SIGXCPU }, /* 24 (arm,i386,m68k,ppc,alpha,sparc*), 30 (mips) */
#endif
#ifdef SIGXFSZ
{ "XFSZ", SIGXFSZ }, /* 25 (arm,i386,m68k,ppc,alpha,sparc*), 31 (mips) */
#endif
#ifdef SIGVTALRM
{ "VTALRM", SIGVTALRM }, /* 26 (arm,i386,m68k,ppc,alpha,sparc*), 28 (mips) */
#endif
#ifdef SIGPROF
{ "PROF", SIGPROF }, /* 27 (arm,i386,m68k,ppc,alpha,sparc*), 29 (mips) */
#endif
#ifdef SIGPWR
{ "PWR", SIGPWR }, /* 30 (arm,i386,m68k,ppc), 29 (alpha,sparc*), 19 (mips) */
#endif
#ifdef SIGINFO
{ "INFO", SIGINFO }, /* 29 (alpha) */
#endif
#ifdef SIGLOST
{ "LOST", SIGLOST }, /* 29 (arm,i386,m68k,ppc,sparc*) */
#endif
#ifdef SIGWINCH
{ "WINCH", SIGWINCH }, /* 28 (arm,i386,m68k,ppc,alpha,sparc*), 20 (mips) */
#endif
#ifdef SIGUNUSED
{ "UNUSED", SIGUNUSED }, /* 31 (arm,i386,m68k,ppc) */
#endif
{0, 0}
};
/* int get_signum(char *name)
if str_sig == NULL returned signal name [*signo],
if str_sig != NULL - set *signo from signal_name,
findings with digit number or with or without SIG-prefix name
if startnum=0 flag for support finding zero signal,
but str_sig="0" always found, (hmm - standart or realize?)
if startnum<0 returned reverse signal_number <-> signal_name
if found error - returned NULL
*/
const char *
u_signal_names(const char *str_sig, int *signo, int startnum)
{ {
static char retstr[16]; int i;
const struct signal_name *s = signames;
static const char prefix[] = "SIG";
const char *sptr;
if(startnum) i = atoi(name);
s++; if(i) return i;
if(str_sig==NULL) { for(i=0; i < sizeof(signals) / sizeof(struct signal_name); i++)
while (s->name != 0) { if (!strcasecmp(signals[i].name, name) ||
if(s->number == *signo) (!strncasecmp(signals[i].name, "SIG", 3)
break; && !strcasecmp(signals[i].name+3, signals[i].name)))
s++; return signals[i].number;
} return -1;
} else { }
if (isdigit(((unsigned char)*str_sig))) {
char *endp; // Convert signal number to name
long int sn = strtol(str_sig, &endp, 10);
/* test correct and overflow */ char *get_signame(int number)
if(*endp == 0 && sn >= 0 && sn < NSIG) { {
*signo = (int)sn; int i;
/* test for unnamed */ static char buf[8];
sptr = u_signal_names(0, signo, 0);
if(sptr==NULL) itoa_to_buf(number, buf, 8);
return NULL; for (i=0; i < sizeof(signals) / sizeof(struct signal_name); i++) {
if(sn!=0) if (number == signals[i].number) {
sptr += 3; sprintf("SIG%s", signals[i].name);
return sptr; break;
}
} else {
sptr = str_sig;
while (s->name != 0) {
if (strcasecmp(s->name, sptr) == 0) {
*signo = s->number;
if(startnum<0) {
sprintf(retstr, "%d", *signo);
return retstr;
}
break;
}
if(s!=signames && sptr == str_sig &&
strncasecmp(sptr, prefix, 3) == 0) {
sptr += 3; /* strlen(prefix) */
continue;
}
sptr = str_sig;
s++;
}
} }
} }
if(s->name==0)
return NULL; return buf;
if(s!=signames)
strcpy(retstr, prefix);
else
retstr[0] = 0;
return strcat(retstr, s->name);
} }

View File

@ -11,18 +11,8 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <signal.h>
#include <errno.h>
#include <sys/stat.h>
#include <dirent.h>
#include <unistd.h>
#include "inet_common.h"
#include "busybox.h" #include "busybox.h"
#include "pwd_.h" #include "inet_common.h"
#ifdef CONFIG_ROUTE #ifdef CONFIG_ROUTE
extern void displayroutes(int noresolve, int netstatfmt); extern void displayroutes(int noresolve, int netstatfmt);
@ -87,19 +77,6 @@ typedef enum {
#define SO_WAITDATA (1<<17) /* wait data to read */ #define SO_WAITDATA (1<<17) /* wait data to read */
#define SO_NOSPACE (1<<18) /* no space to write */ #define SO_NOSPACE (1<<18) /* no space to write */
static char *itoa(unsigned int i)
{
/* 21 digits plus null terminator, good for 64-bit or smaller ints */
static char local[22];
char *p = &local[21];
*p-- = '\0';
do {
*p-- = '0' + i % 10;
i /= 10;
} while (i > 0);
return p + 1;
}
static char *get_sname(int port, const char *proto, int num) static char *get_sname(int port, const char *proto, int num)
{ {
char *str=itoa(ntohs(port)); char *str=itoa(ntohs(port));

View File

@ -548,7 +548,7 @@ static int
wait_for_reply(int sock, struct sockaddr_in *fromp, const struct timeval *tp) wait_for_reply(int sock, struct sockaddr_in *fromp, const struct timeval *tp)
{ {
fd_set fds; fd_set fds;
struct timeval now, wait; struct timeval now, tvwait;
struct timezone tz; struct timezone tz;
int cc = 0; int cc = 0;
socklen_t fromlen = sizeof(*fromp); socklen_t fromlen = sizeof(*fromp);
@ -556,12 +556,12 @@ wait_for_reply(int sock, struct sockaddr_in *fromp, const struct timeval *tp)
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(sock, &fds); FD_SET(sock, &fds);
wait.tv_sec = tp->tv_sec + waittime; tvwait.tv_sec = tp->tv_sec + waittime;
wait.tv_usec = tp->tv_usec; tvwait.tv_usec = tp->tv_usec;
(void)gettimeofday(&now, &tz); (void)gettimeofday(&now, &tz);
tvsub(&wait, &now); tvsub(&tvwait, &now);
if (select(sock + 1, &fds, NULL, NULL, &wait) > 0) if (select(sock + 1, &fds, NULL, NULL, &tvwait) > 0)
cc = recvfrom(sock, (char *)packet, sizeof(packet), 0, cc = recvfrom(sock, (char *)packet, sizeof(packet), 0,
(struct sockaddr *)fromp, &fromlen); (struct sockaddr *)fromp, &fromlen);

View File

@ -697,12 +697,11 @@ updateprogressmeter(int ignore)
errno = save_errno; errno = save_errno;
} }
static void static void alarmtimer(int iwait)
alarmtimer(int wait)
{ {
struct itimerval itv; struct itimerval itv;
itv.it_value.tv_sec = wait; itv.it_value.tv_sec = iwait;
itv.it_value.tv_usec = 0; itv.it_value.tv_usec = 0;
itv.it_interval = itv.it_value; itv.it_interval = itv.it_value;
setitimer(ITIMER_REAL, &itv, NULL); setitimer(ITIMER_REAL, &itv, NULL);
@ -715,7 +714,7 @@ progressmeter(int flag)
static struct timeval lastupdate; static struct timeval lastupdate;
static off_t lastsize, totalsize; static off_t lastsize, totalsize;
struct timeval now, td, wait; struct timeval now, td, tvwait;
off_t abbrevsize; off_t abbrevsize;
int elapsed, ratio, barlength, i; int elapsed, ratio, barlength, i;
char buf[256]; char buf[256];
@ -753,18 +752,18 @@ progressmeter(int flag)
/* See http://en.wikipedia.org/wiki/Tera */ /* See http://en.wikipedia.org/wiki/Tera */
fprintf(stderr, "%6d %c%c ", (int)abbrevsize, " KMGTPEZY"[i], i?'B':' '); fprintf(stderr, "%6d %c%c ", (int)abbrevsize, " KMGTPEZY"[i], i?'B':' ');
timersub(&now, &lastupdate, &wait); timersub(&now, &lastupdate, &tvwait);
if (transferred > lastsize) { if (transferred > lastsize) {
lastupdate = now; lastupdate = now;
lastsize = transferred; lastsize = transferred;
if (wait.tv_sec >= STALLTIME) if (tvwait.tv_sec >= STALLTIME)
timeradd(&start, &wait, &start); timeradd(&start, &tvwait, &start);
wait.tv_sec = 0; tvwait.tv_sec = 0;
} }
timersub(&now, &start, &td); timersub(&now, &start, &td);
elapsed = td.tv_sec; elapsed = td.tv_sec;
if (wait.tv_sec >= STALLTIME) { if (tvwait.tv_sec >= STALLTIME) {
fprintf(stderr, " - stalled -"); fprintf(stderr, " - stalled -");
} else if (transferred <= 0 || elapsed <= 0 || transferred > totalsize || chunked) { } else if (transferred <= 0 || elapsed <= 0 || transferred > totalsize || chunked) {
fprintf(stderr, "--:--:-- ETA"); fprintf(stderr, "--:--:-- ETA");

View File

@ -9,18 +9,6 @@
*/ */
#include "busybox.h" #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_PROC_DIR "/proc"
#define FUSER_MAX_LINE 255 #define FUSER_MAX_LINE 255
@ -335,7 +323,7 @@ int fuser_main(int argc, char **argv)
optn = fuser_option(argv[i]); optn = fuser_option(argv[i]);
if(optn) opt |= optn; if(optn) opt |= optn;
else if(argv[i][0] == '-') { else if(argv[i][0] == '-') {
if(!(u_signal_names(argv[i]+1, &killsig, 0))) if(0>(killsig = get_signum(argv[i]+1)))
killsig = SIGTERM; killsig = SIGTERM;
} }
else { else {
@ -345,7 +333,6 @@ int fuser_main(int argc, char **argv)
} }
if(!fnic) return 1; if(!fnic) return 1;
pids = xmalloc(sizeof(pid_list));
inodes = xmalloc(sizeof(inode_list)); inodes = xmalloc(sizeof(inode_list));
for(i=0;i<fnic;i++) { for(i=0;i<fnic;i++) {
if(fuser_parse_net_arg(argv[fni[i]], &proto, &port)) { if(fuser_parse_net_arg(argv[fni[i]], &proto, &port)) {
@ -354,14 +341,13 @@ int fuser_main(int argc, char **argv)
else { else {
if(!fuser_file_to_dev_inode( if(!fuser_file_to_dev_inode(
argv[fni[i]], &dev, &inode)) { argv[fni[i]], &dev, &inode)) {
free(pids); if (ENABLE_FEATURE_CLEAN_UP) free(inodes);
free(inodes); bb_perror_msg_and_die("Could not open '%s'", argv[fni[i]]);
bb_perror_msg_and_die(
"Could not open '%s'", argv[fni[i]]);
} }
fuser_add_inode(inodes, dev, inode); fuser_add_inode(inodes, dev, inode);
} }
} }
pids = xmalloc(sizeof(pid_list));
success = fuser_scan_proc_pids(opt, inodes, pids); success = fuser_scan_proc_pids(opt, inodes, pids);
/* if the first pid in the list is 0, none have been found */ /* if the first pid in the list is 0, none have been found */
if(pids->pid == 0) success = 0; if(pids->pid == 0) success = 0;

View File

@ -18,22 +18,11 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#define KILL 0
#define KILLALL 1
int kill_main(int argc, char **argv) int kill_main(int argc, char **argv)
{ {
int whichApp, signo = SIGTERM; int killall, signo = SIGTERM, errors = 0, quiet=0;
const char *name;
int errors = 0;
#ifdef CONFIG_KILLALL killall = (ENABLE_KILLALL && bb_applet_name[4]=='a') ? 1 : 0;
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
/* Parse any options */ /* Parse any options */
if (argc < 2) if (argc < 2)
@ -50,32 +39,38 @@ int kill_main(int argc, char **argv)
if(argc==2) { if(argc==2) {
/* Print the whole signal list */ /* Print the whole signal list */
int col = 0; int col = 0;
for(signo=1; signo < NSIG; signo++) {
name = u_signal_names(0, &signo, 1); for(signo = 0;;) {
if(name==NULL) /* unnamed */ char *name = get_signame(++signo);
continue; if (isdigit(*name)) break;
col += printf("%2d) %-16s", signo, name);
if (col > 60) { if (col > 60) {
printf("\n"); printf("\n");
col = 0; col = 0;
} }
col += printf("%2d) %-16s", signo, name);
} }
printf("\n"); printf("\n");
} else { } else {
for(argv++; *argv; argv++) { for(argv++; *argv; argv++) {
name = u_signal_names(*argv, &signo, -1); char *name;
if(name!=NULL)
printf("%s\n", 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 */ /* If they specified -l, were all done */
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
#ifdef CONFIG_KILLALL
/* The -q quiet option */ /* 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++; quiet++;
argv++; argv++;
argc--; argc--;
@ -83,9 +78,8 @@ int kill_main(int argc, char **argv)
goto do_it_now; 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); bb_error_msg_and_die( "bad signal name '%s'", argv[1]+1);
argv+=2; argv+=2;
argc-=2; argc-=2;
@ -96,7 +90,7 @@ do_it_now:
if (argc <= 0) if (argc <= 0)
bb_show_usage(); bb_show_usage();
if (whichApp == KILL) { if (!killall) {
/* Looks like they want to do a kill. Do that */ /* Looks like they want to do a kill. Do that */
while (--argc >= 0) { while (--argc >= 0) {
int pid; int pid;
@ -111,10 +105,9 @@ do_it_now:
argv++; argv++;
} }
} } else {
#ifdef CONFIG_KILLALL
else {
pid_t myPid=getpid(); pid_t myPid=getpid();
/* Looks like they want to do a killall. Do that */ /* Looks like they want to do a killall. Do that */
while (--argc >= 0) { while (--argc >= 0) {
long* pidList; long* pidList;
@ -141,6 +134,6 @@ do_it_now:
argv++; argv++;
} }
} }
#endif
return errors; return errors;
} }

View File

@ -2035,7 +2035,6 @@ static void onsig(int);
static int dotrap(void); static int dotrap(void);
static void setinteractive(int); static void setinteractive(int);
static void exitshell(void) ATTRIBUTE_NORETURN; static void exitshell(void) ATTRIBUTE_NORETURN;
static int decode_signal(const char *, int);
/* /*
* This routine is called when an error or an interrupt occurs in an * This routine is called when an error or an interrupt occurs in an
@ -6548,7 +6547,7 @@ usage:
} }
if (**++argv == '-') { if (**++argv == '-') {
signo = decode_signal(*argv + 1, 1); signo = get_signum(*argv + 1);
if (signo < 0) { if (signo < 0) {
int c; int c;
@ -6562,7 +6561,7 @@ usage:
list = 1; list = 1;
break; break;
case 's': case 's':
signo = decode_signal(optionarg, 1); signo = get_signum(optionarg);
if (signo < 0) { if (signo < 0) {
sh_error( sh_error(
"invalid signal number or name: %s", "invalid signal number or name: %s",
@ -6588,14 +6587,14 @@ usage:
if (!*argv) { if (!*argv) {
for (i = 1; i < NSIG; i++) { for (i = 1; i < NSIG; i++) {
name = u_signal_names(0, &i, 1); name = get_signame(i);
if (name) if (isdigit(*name))
out1fmt(snlfmt, name); out1fmt(snlfmt, name);
} }
return 0; return 0;
} }
name = u_signal_names(*argptr, &signo, -1); name = get_signame(signo);
if (name) if (isdigit(*name))
out1fmt(snlfmt, name); out1fmt(snlfmt, name);
else else
sh_error("invalid signal number or exit status: %s", *argptr); sh_error("invalid signal number or exit status: %s", *argptr);
@ -11617,9 +11616,7 @@ trapcmd(int argc, char **argv)
if (trap[signo] != NULL) { if (trap[signo] != NULL) {
const char *sn; const char *sn;
sn = u_signal_names(0, &signo, 0); sn = get_signame(signo);
if (sn == NULL)
sn = "???";
out1fmt("trap -- %s %s\n", out1fmt("trap -- %s %s\n",
single_quote(trap[signo]), sn); single_quote(trap[signo]), sn);
} }
@ -11631,7 +11628,7 @@ trapcmd(int argc, char **argv)
else else
action = *ap++; action = *ap++;
while (*ap) { while (*ap) {
if ((signo = decode_signal(*ap, 0)) < 0) if ((signo = get_signum(*ap)) < 0)
sh_error("%s: bad trap", *ap); sh_error("%s: bad trap", *ap);
INTOFF; INTOFF;
if (action) { if (action) {
@ -11934,14 +11931,6 @@ out:
/* NOTREACHED */ /* NOTREACHED */
} }
static int decode_signal(const char *string, int minsig)
{
int signo;
const char *name = u_signal_names(string, &signo, minsig);
return name ? signo : -1;
}
/* var.c */ /* var.c */
static struct var *vartab[VTABSIZE]; static struct var *vartab[VTABSIZE];

View File

@ -22,18 +22,7 @@
#include "busybox.h" #include "busybox.h"
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <unistd.h>
#include <getopt.h> #include <getopt.h>
#include <termios.h>
#include "cmdedit.h" #include "cmdedit.h"
#ifdef CONFIG_LOCALE_SUPPORT #ifdef CONFIG_LOCALE_SUPPORT
@ -697,26 +686,6 @@ static int get_command(FILE * source, char *command)
return 0; return 0;
} }
static char* itoa(int i)
{
static char a[7]; /* Max 7 ints */
char *b = a + sizeof(a) - 1;
int sign = (i < 0);
if (sign)
i = -i;
*b = 0;
do
{
*--b = '0' + (i % 10);
i /= 10;
}
while (i);
if (sign)
*--b = '-';
return b;
}
static char * strsep_space( char *string, int * ix) static char * strsep_space( char *string, int * ix)
{ {
char *token; char *token;

View File

@ -10,41 +10,12 @@
* Robert Schwebel <r.schwebel@pengutronix.de> * Robert Schwebel <r.schwebel@pengutronix.de>
* Erik Andersen <andersen@codepoet.org> * Erik Andersen <andersen@codepoet.org>
* *
* This program is free software; you can redistribute it and/or modify * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Original copyright notice is retained at the end of this file.
*/ */
#include "busybox.h" #include "busybox.h"
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <setjmp.h> #include <setjmp.h>
#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/times.h> #include <sys/times.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "cmdedit.h" #include "cmdedit.h"
@ -293,7 +264,6 @@ static char *space(int n);
static char *strsave(char *s, int a); static char *strsave(char *s, int a);
static char *evalstr(char *cp, int f); static char *evalstr(char *cp, int f);
static char *putn(int n); static char *putn(int n);
static char *itoa(int n);
static char *unquote(char *as); static char *unquote(char *as);
static struct var *lookup(char *n); static struct var *lookup(char *n);
static int rlookup(char *n); static int rlookup(char *n);
@ -1252,15 +1222,6 @@ static char *putn(int n)
return (itoa(n)); return (itoa(n));
} }
static char *itoa(int n)
{
static char s[20];
snprintf(s, sizeof(s), "%u", n);
return (s);
}
static void next(int f) static void next(int f)
{ {
PUSHIO(afile, f, filechar); PUSHIO(afile, f, filechar);