summaryrefslogtreecommitdiff
path: root/shell/ash.c
diff options
context:
space:
mode:
authorDenis Vlasenko2007-04-29 23:42:54 +0000
committerDenis Vlasenko2007-04-29 23:42:54 +0000
commitf20de5bb42f9a4f2c8417f6a1a2db7e2f2cafd5b (patch)
tree4fc060596d599d6ac86bc964970c466496f67954 /shell/ash.c
parentd4728145e37dca844dded6f8723ef9fe7f9293b4 (diff)
downloadbusybox-f20de5bb42f9a4f2c8417f6a1a2db7e2f2cafd5b.zip
busybox-f20de5bb42f9a4f2c8417f6a1a2db7e2f2cafd5b.tar.gz
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 'shell/ash.c')
-rw-r--r--shell/ash.c119
1 files changed, 27 insertions, 92 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 16818cf..4b37f40 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -3519,91 +3519,22 @@ setjobctl(int on)
static int
killcmd(int argc, char **argv)
{
- int signo = -1;
- int list = 0;
- int i;
- pid_t pid;
- struct job *jp;
-
- if (argc <= 1) {
- usage:
- ash_msg_and_raise_error(
-"usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or\n"
-"kill -l [exitstatus]"
- );
- }
-
- if (**++argv == '-') {
- signo = get_signum(*argv + 1);
- if (signo < 0) {
- int c;
-
- while ((c = nextopt("ls:")) != '\0') {
- switch (c) {
- default:
-#if DEBUG
- abort();
-#endif
- case 'l':
- list = 1;
- break;
- case 's':
- signo = get_signum(optionarg);
- if (signo < 0) {
- ash_msg_and_raise_error(
- "invalid signal number or name: %s",
- optionarg
- );
- }
- break;
- }
- }
- argv = argptr;
- } else
- argv++;
- }
-
- if (!list && signo < 0)
- signo = SIGTERM;
-
- if ((signo < 0 || !*argv) ^ list) {
- goto usage;
- }
-
- if (list) {
- const char *name;
-
- if (!*argv) {
- for (i = 1; i < NSIG; i++) {
- name = get_signame(i);
- if (!isdigit(*name))
- out1fmt(snlfmt, name);
+ if (argv[1] && strcmp(argv[1], "-l") != 0) {
+ int i = 1;
+ do {
+ if (argv[i][0] == '%') {
+ struct job *jp = getjob(argv[i], 0);
+ unsigned pid = jp->ps[0].pid;
+ /* Enough space for ' -NNN<nul>' */
+ argv[i] = alloca(sizeof(int)*3 + 3);
+ /* kill_main has matching code to expect
+ * leading space. Needed to not confuse
+ * negative pids with "kill -SIGNAL_NO" syntax */
+ sprintf(argv[i], " -%u", pid);
}
- return 0;
- }
- name = get_signame(signo);
- if (!isdigit(*name))
- ash_msg_and_raise_error("invalid signal number or exit status: %s", *argptr);
- out1fmt(snlfmt, name);
- return 0;
+ } while (argv[++i]);
}
-
- i = 0;
- do {
- if (**argv == '%') {
- jp = getjob(*argv, 0);
- pid = -jp->ps[0].pid;
- } else {
- pid = **argv == '-' ?
- -number(*argv + 1) : number(*argv);
- }
- if (kill(pid, signo) != 0) {
- ash_msg("(%d) - %m", pid);
- i = 1;
- }
- } while (*++argv);
-
- return i;
+ return kill_main(argc, argv);
}
static void
@@ -3642,7 +3573,8 @@ restartjob(struct job *jp, int mode)
if (WIFSTOPPED(ps->status)) {
ps->status = -1;
}
- } while (ps++, --i);
+ ps++;
+ } while (--i);
out:
status = (mode == FORK_FG) ? waitforjob(jp) : 0;
INT_ON;
@@ -5070,8 +5002,9 @@ esclen(const char *start, const char *p)
static char *
_rmescapes(char *str, int flag)
{
+ static const char qchars[] = { CTLESC, CTLQUOTEMARK, '\0' };
+
char *p, *q, *r;
- static const char qchars[] = { CTLESC, CTLQUOTEMARK, 0 };
unsigned inquotes;
int notescaped;
int globbing;
@@ -11117,13 +11050,7 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
return;
}
-#if ENABLE_FEATURE_SH_STANDALONE
- if (find_applet_by_name(name)) {
- entry->cmdtype = CMDNORMAL;
- entry->u.index = -1;
- return;
- }
-#endif
+/* #if ENABLE_FEATURE_SH_STANDALONE... moved after builtin check */
updatetbl = (path == pathval());
if (!updatetbl) {
@@ -11173,6 +11100,14 @@ find_command(char *name, struct cmdentry *entry, int act, const char *path)
}
}
+#if ENABLE_FEATURE_SH_STANDALONE
+ if (find_applet_by_name(name)) {
+ entry->cmdtype = CMDNORMAL;
+ entry->u.index = -1;
+ return;
+ }
+#endif
+
/* We have to search path. */
prev = -1; /* where to start */
if (cmdp && cmdp->rehash) { /* doing a rehash */