aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c41
1 files changed, 22 insertions, 19 deletions
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)