diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-29 23:42:54 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-29 23:42:54 +0000 |
commit | f20de5bb42f9a4f2c8417f6a1a2db7e2f2cafd5b (patch) | |
tree | 4fc060596d599d6ac86bc964970c466496f67954 /shell/ash.c | |
parent | d4728145e37dca844dded6f8723ef9fe7f9293b4 (diff) | |
download | busybox-w32-f20de5bb42f9a4f2c8417f6a1a2db7e2f2cafd5b.tar.gz busybox-w32-f20de5bb42f9a4f2c8417f6a1a2db7e2f2cafd5b.tar.bz2 busybox-w32-f20de5bb42f9a4f2c8417f6a1a2db7e2f2cafd5b.zip |
ash,kill: use common code for kill applet/builtin
# make bloatcheck
function old new delta
evaltreenr 644 654 +10
evaltree 644 654 +10
parse_conf 1440 1444 +4
dpkg_deb_main 426 429 +3
ed_main 3319 3321 +2
passwd_main 2093 2091 -2
kill_main 830 826 -4
singlemount 4609 4601 -8
find_command 962 954 -8
get_lcm 123 105 -18
.rodata 132243 132147 -96
killcmd 449 120 -329
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/7 up/down: 29/-465) Total: -436 bytes
# size busybox_old busybox_unstripped
text data bss dec hex filename
723901 2940 27504 754345 b82a9 busybox_old
723457 2940 27504 753901 b80ed busybox_unstripped
Diffstat (limited to '')
-rw-r--r-- | shell/ash.c | 119 |
1 files changed, 27 insertions, 92 deletions
diff --git a/shell/ash.c b/shell/ash.c index 16818cfc9..4b37f403c 100644 --- a/shell/ash.c +++ b/shell/ash.c | |||
@@ -3519,91 +3519,22 @@ setjobctl(int on) | |||
3519 | static int | 3519 | static int |
3520 | killcmd(int argc, char **argv) | 3520 | killcmd(int argc, char **argv) |
3521 | { | 3521 | { |
3522 | int signo = -1; | 3522 | if (argv[1] && strcmp(argv[1], "-l") != 0) { |
3523 | int list = 0; | 3523 | int i = 1; |
3524 | int i; | 3524 | do { |
3525 | pid_t pid; | 3525 | if (argv[i][0] == '%') { |
3526 | struct job *jp; | 3526 | struct job *jp = getjob(argv[i], 0); |
3527 | 3527 | unsigned pid = jp->ps[0].pid; | |
3528 | if (argc <= 1) { | 3528 | /* Enough space for ' -NNN<nul>' */ |
3529 | usage: | 3529 | argv[i] = alloca(sizeof(int)*3 + 3); |
3530 | ash_msg_and_raise_error( | 3530 | /* kill_main has matching code to expect |
3531 | "usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or\n" | 3531 | * leading space. Needed to not confuse |
3532 | "kill -l [exitstatus]" | 3532 | * negative pids with "kill -SIGNAL_NO" syntax */ |
3533 | ); | 3533 | sprintf(argv[i], " -%u", pid); |
3534 | } | ||
3535 | |||
3536 | if (**++argv == '-') { | ||
3537 | signo = get_signum(*argv + 1); | ||
3538 | if (signo < 0) { | ||
3539 | int c; | ||
3540 | |||
3541 | while ((c = nextopt("ls:")) != '\0') { | ||
3542 | switch (c) { | ||
3543 | default: | ||
3544 | #if DEBUG | ||
3545 | abort(); | ||
3546 | #endif | ||
3547 | case 'l': | ||
3548 | list = 1; | ||
3549 | break; | ||
3550 | case 's': | ||
3551 | signo = get_signum(optionarg); | ||
3552 | if (signo < 0) { | ||
3553 | ash_msg_and_raise_error( | ||
3554 | "invalid signal number or name: %s", | ||
3555 | optionarg | ||
3556 | ); | ||
3557 | } | ||
3558 | break; | ||
3559 | } | ||
3560 | } | ||
3561 | argv = argptr; | ||
3562 | } else | ||
3563 | argv++; | ||
3564 | } | ||
3565 | |||
3566 | if (!list && signo < 0) | ||
3567 | signo = SIGTERM; | ||
3568 | |||
3569 | if ((signo < 0 || !*argv) ^ list) { | ||
3570 | goto usage; | ||
3571 | } | ||
3572 | |||
3573 | if (list) { | ||
3574 | const char *name; | ||
3575 | |||
3576 | if (!*argv) { | ||
3577 | for (i = 1; i < NSIG; i++) { | ||
3578 | name = get_signame(i); | ||
3579 | if (!isdigit(*name)) | ||
3580 | out1fmt(snlfmt, name); | ||
3581 | } | 3534 | } |
3582 | return 0; | 3535 | } while (argv[++i]); |
3583 | } | ||
3584 | name = get_signame(signo); | ||
3585 | if (!isdigit(*name)) | ||
3586 | ash_msg_and_raise_error("invalid signal number or exit status: %s", *argptr); | ||
3587 | out1fmt(snlfmt, name); | ||
3588 | return 0; | ||
3589 | } | 3536 | } |
3590 | 3537 | return kill_main(argc, argv); | |
3591 | i = 0; | ||
3592 | do { | ||
3593 | if (**argv == '%') { | ||
3594 | jp = getjob(*argv, 0); | ||
3595 | pid = -jp->ps[0].pid; | ||
3596 | } else { | ||
3597 | pid = **argv == '-' ? | ||
3598 | -number(*argv + 1) : number(*argv); | ||
3599 | } | ||
3600 | if (kill(pid, signo) != 0) { | ||
3601 | ash_msg("(%d) - %m", pid); | ||
3602 | i = 1; | ||
3603 | } | ||
3604 | } while (*++argv); | ||
3605 | |||
3606 | return i; | ||
3607 | } | 3538 | } |
3608 | 3539 | ||
3609 | static void | 3540 | static void |
@@ -3642,7 +3573,8 @@ restartjob(struct job *jp, int mode) | |||
3642 | if (WIFSTOPPED(ps->status)) { | 3573 | if (WIFSTOPPED(ps->status)) { |
3643 | ps->status = -1; | 3574 | ps->status = -1; |
3644 | } | 3575 | } |
3645 | } while (ps++, --i); | 3576 | ps++; |
3577 | } while (--i); | ||
3646 | out: | 3578 | out: |
3647 | status = (mode == FORK_FG) ? waitforjob(jp) : 0; | 3579 | status = (mode == FORK_FG) ? waitforjob(jp) : 0; |
3648 | INT_ON; | 3580 | INT_ON; |
@@ -5070,8 +5002,9 @@ esclen(const char *start, const char *p) | |||
5070 | static char * | 5002 | static char * |
5071 | _rmescapes(char *str, int flag) | 5003 | _rmescapes(char *str, int flag) |
5072 | { | 5004 | { |
5005 | static const char qchars[] = { CTLESC, CTLQUOTEMARK, '\0' }; | ||
5006 | |||
5073 | char *p, *q, *r; | 5007 | char *p, *q, *r; |
5074 | static const char qchars[] = { CTLESC, CTLQUOTEMARK, 0 }; | ||
5075 | unsigned inquotes; | 5008 | unsigned inquotes; |
5076 | int notescaped; | 5009 | int notescaped; |
5077 | int globbing; | 5010 | int globbing; |
@@ -11117,13 +11050,7 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
11117 | return; | 11050 | return; |
11118 | } | 11051 | } |
11119 | 11052 | ||
11120 | #if ENABLE_FEATURE_SH_STANDALONE | 11053 | /* #if ENABLE_FEATURE_SH_STANDALONE... moved after builtin check */ |
11121 | if (find_applet_by_name(name)) { | ||
11122 | entry->cmdtype = CMDNORMAL; | ||
11123 | entry->u.index = -1; | ||
11124 | return; | ||
11125 | } | ||
11126 | #endif | ||
11127 | 11054 | ||
11128 | updatetbl = (path == pathval()); | 11055 | updatetbl = (path == pathval()); |
11129 | if (!updatetbl) { | 11056 | if (!updatetbl) { |
@@ -11173,6 +11100,14 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path) | |||
11173 | } | 11100 | } |
11174 | } | 11101 | } |
11175 | 11102 | ||
11103 | #if ENABLE_FEATURE_SH_STANDALONE | ||
11104 | if (find_applet_by_name(name)) { | ||
11105 | entry->cmdtype = CMDNORMAL; | ||
11106 | entry->u.index = -1; | ||
11107 | return; | ||
11108 | } | ||
11109 | #endif | ||
11110 | |||
11176 | /* We have to search path. */ | 11111 | /* We have to search path. */ |
11177 | prev = -1; /* where to start */ | 11112 | prev = -1; /* where to start */ |
11178 | if (cmdp && cmdp->rehash) { /* doing a rehash */ | 11113 | if (cmdp && cmdp->rehash) { /* doing a rehash */ |