aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-14 10:09:57 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-14 10:09:57 +0000
commitf5294e1f4c56afb377ada95a7757b28ad3c89086 (patch)
tree95a0c3632c8c2b20fa6b60f1e1a33e4fc4b24d4f /shell
parent16abcd90aefae8bdb9f7d80a555982dba6ca59b5 (diff)
downloadbusybox-w32-f5294e1f4c56afb377ada95a7757b28ad3c89086.tar.gz
busybox-w32-f5294e1f4c56afb377ada95a7757b28ad3c89086.tar.bz2
busybox-w32-f5294e1f4c56afb377ada95a7757b28ad3c89086.zip
hush: use NOFORK applets as appropriate. Net reduction of code size.
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c4
-rw-r--r--shell/hush.c41
-rw-r--r--shell/lash.c7
3 files changed, 24 insertions, 28 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 63f039df4..90936fcc0 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -6539,10 +6539,8 @@ tryexec(char *cmd, char **argv, char **envp)
6539 a = find_applet_by_name(cmd); 6539 a = find_applet_by_name(cmd);
6540 if (a) { 6540 if (a) {
6541 if (a->noexec) { 6541 if (a->noexec) {
6542 char **c = argv;
6543 while (*c) c++;
6544 current_applet = a; 6542 current_applet = a;
6545 run_current_applet_and_exit(c - argv, argv); 6543 run_current_applet_and_exit(argv);
6546 } 6544 }
6547 /* re-exec ourselves with the new arguments */ 6545 /* re-exec ourselves with the new arguments */
6548 execve(CONFIG_BUSYBOX_EXEC_PATH, argv, envp); 6546 execve(CONFIG_BUSYBOX_EXEC_PATH, argv, envp);
diff --git a/shell/hush.c b/shell/hush.c
index 035919500..9362e5916 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -765,7 +765,7 @@ static int b_check_space(o_string *o, int len)
765 * in here, such as setting a maximum string length */ 765 * in here, such as setting a maximum string length */
766 if (o->length + len > o->maxlen) { 766 if (o->length + len > o->maxlen) {
767 char *old_data = o->data; 767 char *old_data = o->data;
768 /* assert (data == NULL || o->maxlen != 0); */ 768 /* assert(data == NULL || o->maxlen != 0); */
769 o->maxlen += max(2*len, B_CHUNK); 769 o->maxlen += max(2*len, B_CHUNK);
770 o->data = realloc(o->data, 1 + o->maxlen); 770 o->data = realloc(o->data, 1 + o->maxlen);
771 if (o->data == NULL) { 771 if (o->data == NULL) {
@@ -1113,17 +1113,10 @@ static void pseudo_exec(struct child_prog *child)
1113 * from global_argv[0], but if we are in a chroot, we may not be able 1113 * from global_argv[0], but if we are in a chroot, we may not be able
1114 * to find ourself... */ 1114 * to find ourself... */
1115#if ENABLE_FEATURE_SH_STANDALONE 1115#if ENABLE_FEATURE_SH_STANDALONE
1116 { 1116 debug_printf("running applet %s\n", child->argv[0]);
1117 int argc_l; 1117 run_applet_and_exit(child->argv[0], child->argv);
1118 char** argv_l = child->argv; 1118// is it ok that run_applet_and_exit() does exit(), not _exit()?
1119 char *name = child->argv[0]; 1119// NB: IIRC on NOMMU we are after _vfork_, not fork!
1120
1121 /* Count argc for use in a second... */
1122 for (argc_l = 0; *argv_l; argv_l++, argc_l++)
1123 continue;
1124 debug_printf("running applet %s\n", name);
1125 run_applet_and_exit(name, argc_l, child->argv);
1126 }
1127#endif 1120#endif
1128 debug_printf("exec of %s\n", child->argv[0]); 1121 debug_printf("exec of %s\n", child->argv[0]);
1129 execvp(child->argv[0], child->argv); 1122 execvp(child->argv[0], child->argv);
@@ -1304,6 +1297,9 @@ static int run_pipe_real(struct pipe *pi)
1304 struct child_prog *child; 1297 struct child_prog *child;
1305 const struct built_in_command *x; 1298 const struct built_in_command *x;
1306 char *p; 1299 char *p;
1300 /* it is not always needed, but we aim to smaller code */
1301 int squirrel[] = { -1, -1, -1 };
1302 int rcode;
1307 1303
1308 nextin = 0; 1304 nextin = 0;
1309 pi->pgrp = -1; 1305 pi->pgrp = -1;
@@ -1314,8 +1310,6 @@ static int run_pipe_real(struct pipe *pi)
1314 */ 1310 */
1315 child = &(pi->progs[0]); 1311 child = &(pi->progs[0]);
1316 if (pi->num_progs == 1 && child->group && child->subshell == 0) { 1312 if (pi->num_progs == 1 && child->group && child->subshell == 0) {
1317 int squirrel[] = { -1, -1, -1 };
1318 int rcode;
1319 debug_printf("non-subshell grouping\n"); 1313 debug_printf("non-subshell grouping\n");
1320 setup_redirects(child, squirrel); 1314 setup_redirects(child, squirrel);
1321 /* XXX could we merge code with following builtin case, 1315 /* XXX could we merge code with following builtin case,
@@ -1366,15 +1360,13 @@ static int run_pipe_real(struct pipe *pi)
1366 if (child->sp) { 1360 if (child->sp) {
1367 char *str; 1361 char *str;
1368 1362
1369 str = make_string((child->argv + i)); 1363 str = make_string(child->argv + i);
1370 parse_string_outer(str, FLAG_EXIT_FROM_LOOP | FLAG_REPARSING); 1364 parse_string_outer(str, FLAG_EXIT_FROM_LOOP | FLAG_REPARSING);
1371 free(str); 1365 free(str);
1372 return last_return_code; 1366 return last_return_code;
1373 } 1367 }
1374 for (x = bltins; x->cmd; x++) { 1368 for (x = bltins; x->cmd; x++) {
1375 if (strcmp(child->argv[i], x->cmd) == 0) { 1369 if (strcmp(child->argv[i], x->cmd) == 0) {
1376 int squirrel[] = { -1, -1, -1 };
1377 int rcode;
1378 if (x->function == builtin_exec && child->argv[i+1] == NULL) { 1370 if (x->function == builtin_exec && child->argv[i+1] == NULL) {
1379 debug_printf("magic exec\n"); 1371 debug_printf("magic exec\n");
1380 setup_redirects(child, NULL); 1372 setup_redirects(child, NULL);
@@ -1393,6 +1385,17 @@ static int run_pipe_real(struct pipe *pi)
1393 return rcode; 1385 return rcode;
1394 } 1386 }
1395 } 1387 }
1388#if ENABLE_FEATURE_SH_STANDALONE
1389 {
1390 const struct bb_applet *a = find_applet_by_name(child->argv[i]);
1391 if (a && a->nofork) {
1392 setup_redirects(child, squirrel);
1393 rcode = run_nofork_applet(a, child->argv + i);
1394 restore_redirects(squirrel);
1395 return rcode;
1396 }
1397 }
1398#endif
1396 } 1399 }
1397 1400
1398 for (i = 0; i < pi->num_progs; i++) { 1401 for (i = 0; i < pi->num_progs; i++) {
@@ -2587,8 +2590,8 @@ int parse_stream(o_string *dest, struct p_context *ctx,
2587 2590
2588static void mapset(const char *set, int code) 2591static void mapset(const char *set, int code)
2589{ 2592{
2590 while (*s) 2593 while (*set)
2591 map[(unsigned char)*s++] = code; 2594 map[(unsigned char)*set++] = code;
2592} 2595}
2593 2596
2594static void update_ifs_map(void) 2597static void update_ifs_map(void)
diff --git a/shell/lash.c b/shell/lash.c
index c74684bf7..6fe2ddc76 100644
--- a/shell/lash.c
+++ b/shell/lash.c
@@ -1158,12 +1158,7 @@ static int pseudo_exec(struct child_prog *child)
1158 * /bin/foo is a symlink to busybox. 1158 * /bin/foo is a symlink to busybox.
1159 */ 1159 */
1160 if (ENABLE_FEATURE_SH_STANDALONE) { 1160 if (ENABLE_FEATURE_SH_STANDALONE) {
1161 char **argv_l = child->argv; 1161 run_applet_and_exit(child->argv[0], child->argv);
1162 int argc_l;
1163
1164 for (argc_l = 0; *argv_l; argv_l++, argc_l++)
1165 continue;
1166 run_applet_and_exit(child->argv[0], argc_l, child->argv);
1167 } 1162 }
1168 1163
1169 execvp(child->argv[0], child->argv); 1164 execvp(child->argv[0], child->argv);