summaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-10-01 09:59:47 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-10-01 09:59:47 +0000
commit8412d7959a26bf697faf15aee4df8f91df444022 (patch)
treea37a2dc6d6183db8df3d8d6c3e0ff2d5199b0838 /shell/hush.c
parenta0898170d876aeeea19eb144556afd05819db450 (diff)
downloadbusybox-w32-8412d7959a26bf697faf15aee4df8f91df444022.tar.gz
busybox-w32-8412d7959a26bf697faf15aee4df8f91df444022.tar.bz2
busybox-w32-8412d7959a26bf697faf15aee4df8f91df444022.zip
hush: feeble attempt at making it more NOMMU-friendly
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c38
1 files changed, 22 insertions, 16 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 9181641b9..19d516dff 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -86,6 +86,15 @@ extern char **environ; /* This is in <unistd.h>, but protected with __USE_GNU */
86#include "busybox.h" /* for struct bb_applet */ 86#include "busybox.h" /* for struct bb_applet */
87 87
88 88
89#if !BB_MMU
90/* A bit drastic. Can allow some simpler commands
91 * by analysing command in generate_stream_from_list()
92 */
93#undef ENABLE_HUSH_TICK
94#define ENABLE_HUSH_TICK 0
95#endif
96
97
89/* If you comment out one of these below, it will be #defined later 98/* If you comment out one of these below, it will be #defined later
90 * to perform debug printfs to stderr: */ 99 * to perform debug printfs to stderr: */
91#define debug_printf(...) do {} while (0) 100#define debug_printf(...) do {} while (0)
@@ -1268,7 +1277,7 @@ static int setup_redirects(struct child_prog *prog, int squirrel[])
1268 squirrel[redir->fd] = dup(redir->fd); 1277 squirrel[redir->fd] = dup(redir->fd);
1269 } 1278 }
1270 if (openfd == -3) { 1279 if (openfd == -3) {
1271 close(openfd); 1280 //close(openfd); // close(-3) ??!
1272 } else { 1281 } else {
1273 dup2(openfd, redir->fd); 1282 dup2(openfd, redir->fd);
1274 if (redir->dup == -1) 1283 if (redir->dup == -1)
@@ -1291,8 +1300,9 @@ static void restore_redirects(int squirrel[])
1291 } 1300 }
1292} 1301}
1293 1302
1294/* never returns */ 1303/* Called after [v]fork() in run_pipe_real(), or from builtin_exec().
1295/* XXX no exit() here. If you don't exec, use _exit instead. 1304 * Never returns.
1305 * XXX no exit() here. If you don't exec, use _exit instead.
1296 * The at_exit handlers apparently confuse the calling process, 1306 * The at_exit handlers apparently confuse the calling process,
1297 * in particular stdin handling. Not sure why? -- because of vfork! (vda) */ 1307 * in particular stdin handling. Not sure why? -- because of vfork! (vda) */
1298static void pseudo_exec_argv(char **argv) 1308static void pseudo_exec_argv(char **argv)
@@ -1359,6 +1369,8 @@ static void pseudo_exec_argv(char **argv)
1359 _exit(1); 1369 _exit(1);
1360} 1370}
1361 1371
1372/* Called after [v]fork() in run_pipe_real()
1373 */
1362static void pseudo_exec(struct child_prog *child) 1374static void pseudo_exec(struct child_prog *child)
1363{ 1375{
1364// FIXME: buggy wrt NOMMU! Must not modify any global data 1376// FIXME: buggy wrt NOMMU! Must not modify any global data
@@ -1370,7 +1382,9 @@ static void pseudo_exec(struct child_prog *child)
1370 } 1382 }
1371 1383
1372 if (child->group) { 1384 if (child->group) {
1373 // FIXME: do not modify globals! Think vfork! 1385#if !BB_MMU
1386 bb_error_msg_and_exit("nested lists are not supported on NOMMU");
1387#else
1374#if ENABLE_HUSH_INTERACTIVE 1388#if ENABLE_HUSH_INTERACTIVE
1375 debug_printf_exec("pseudo_exec: setting interactive_fd=0\n"); 1389 debug_printf_exec("pseudo_exec: setting interactive_fd=0\n");
1376 interactive_fd = 0; /* crucial!!!! */ 1390 interactive_fd = 0; /* crucial!!!! */
@@ -1380,6 +1394,7 @@ static void pseudo_exec(struct child_prog *child)
1380 /* OK to leak memory by not calling free_pipe_list, 1394 /* OK to leak memory by not calling free_pipe_list,
1381 * since this process is about to exit */ 1395 * since this process is about to exit */
1382 _exit(rcode); 1396 _exit(rcode);
1397#endif
1383 } 1398 }
1384 1399
1385 /* Can happen. See what bash does with ">foo" by itself. */ 1400 /* Can happen. See what bash does with ">foo" by itself. */
@@ -1787,14 +1802,8 @@ static int run_pipe_real(struct pipe *pi)
1787 } 1802 }
1788#endif 1803#endif
1789 /* in non-interactive case fatal sigs are already SIG_DFL */ 1804 /* in non-interactive case fatal sigs are already SIG_DFL */
1790 if (nextin != 0) { 1805 xmove_fd(nextin, 0);
1791 dup2(nextin, 0); 1806 xmove_fd(nextout, 1);
1792 close(nextin);
1793 }
1794 if (nextout != 1) {
1795 dup2(nextout, 1);
1796 close(nextout);
1797 }
1798 if (pipefds[0] != -1) { 1807 if (pipefds[0] != -1) {
1799 close(pipefds[0]); /* opposite end of our output pipe */ 1808 close(pipefds[0]); /* opposite end of our output pipe */
1800 } 1809 }
@@ -3084,17 +3093,14 @@ static int redirect_opt_num(o_string *o)
3084} 3093}
3085 3094
3086#if ENABLE_HUSH_TICK 3095#if ENABLE_HUSH_TICK
3096/* NB: currently disabled on NOMMU */
3087static FILE *generate_stream_from_list(struct pipe *head) 3097static FILE *generate_stream_from_list(struct pipe *head)
3088{ 3098{
3089 FILE *pf; 3099 FILE *pf;
3090 int pid, channel[2]; 3100 int pid, channel[2];
3091 3101
3092 xpipe(channel); 3102 xpipe(channel);
3093#if BB_MMU
3094 pid = fork(); 3103 pid = fork();
3095#else
3096 pid = vfork();
3097#endif
3098 if (pid < 0) { 3104 if (pid < 0) {
3099 bb_perror_msg_and_die("fork"); 3105 bb_perror_msg_and_die("fork");
3100 } else if (pid == 0) { 3106 } else if (pid == 0) {