summaryrefslogtreecommitdiff
path: root/sh.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-07-28 17:08:36 +0000
committerEric Andersen <andersen@codepoet.org>2000-07-28 17:08:36 +0000
commit6a4c33c5c0e5d01c1280a0d77439cd9843eee55a (patch)
tree6baab056b5933e45a4b7fc326195114b647257c1 /sh.c
parent6150df320a8aa825d88d6382c51017f362f2aabe (diff)
downloadbusybox-w32-6a4c33c5c0e5d01c1280a0d77439cd9843eee55a.tar.gz
busybox-w32-6a4c33c5c0e5d01c1280a0d77439cd9843eee55a.tar.bz2
busybox-w32-6a4c33c5c0e5d01c1280a0d77439cd9843eee55a.zip
Clean up the nasty blunder I'd made of how different behaviors happen.
-Erik
Diffstat (limited to 'sh.c')
-rw-r--r--sh.c30
1 files changed, 16 insertions, 14 deletions
diff --git a/sh.c b/sh.c
index 4727e9b46..2cec66bff 100644
--- a/sh.c
+++ b/sh.c
@@ -1383,7 +1383,7 @@ void free_memory(void)
1383 1383
1384int shell_main(int argc_l, char **argv_l) 1384int shell_main(int argc_l, char **argv_l)
1385{ 1385{
1386 int opt; 1386 int opt, interactive=FALSE;
1387 FILE *input = stdin; 1387 FILE *input = stdin;
1388 argc = argc_l; 1388 argc = argc_l;
1389 argv = argv_l; 1389 argv = argv_l;
@@ -1407,7 +1407,7 @@ int shell_main(int argc_l, char **argv_l)
1407 local_pending_command = realloc(local_pending_command, 1407 local_pending_command = realloc(local_pending_command,
1408 strlen(local_pending_command) + strlen(argv[optind])); 1408 strlen(local_pending_command) + strlen(argv[optind]));
1409 if (local_pending_command==NULL) 1409 if (local_pending_command==NULL)
1410 fatalError("sh: command too long\n"); 1410 fatalError("command too long\n");
1411 } 1411 }
1412 strcat(local_pending_command, argv[optind]); 1412 strcat(local_pending_command, argv[optind]);
1413 if ( (optind + 1) < argc) 1413 if ( (optind + 1) < argc)
@@ -1419,29 +1419,31 @@ int shell_main(int argc_l, char **argv_l)
1419 showXtrace = TRUE; 1419 showXtrace = TRUE;
1420 break; 1420 break;
1421#endif 1421#endif
1422 case 'i':
1423 interactive = TRUE;
1424 break;
1422 default: 1425 default:
1423 usage(shell_usage); 1426 usage(shell_usage);
1424 } 1427 }
1425 } 1428 }
1426 1429 /* A shell is interactive if the `-i' flag was given, or if all of
1427 1430 * the following conditions are met:
1428 if (optind<1 && input == stdin) { 1431 * no -c command
1432 * no arguments remaining or the -s flag given
1433 * standard input is a terminal
1434 * standard output is a terminal
1435 * Refer to Posix.2, the description of the `sh' utility. */
1436 if (interactive==TRUE || ( argv[optind]==NULL && input==stdin && isatty(fileno(stdin)) && isatty(fileno(stdout)))) {
1437 fprintf(stdout, "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
1429 /* Looks like they want an interactive shell */ 1438 /* Looks like they want an interactive shell */
1430 fprintf(stdout, "\n\nBusyBox v%s (%s) Built-in shell\n", BB_VER, BB_BT); 1439 fprintf(stdout, "\n\nBusyBox v%s (%s) Built-in shell\n", BB_VER, BB_BT);
1431 fprintf(stdout, "Enter 'help' for a list of built-in commands.\n\n"); 1440 fprintf(stdout, "Enter 'help' for a list of built-in commands.\n\n");
1432 } else if (1==(argc-optind)) { 1441 } else if (local_pending_command==NULL) {
1442 fprintf(stdout, "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
1433 input = fopen(argv[optind], "r"); 1443 input = fopen(argv[optind], "r");
1434 if (!input) { 1444 if (!input) {
1435 fatalError("%s: %s\n", argv[optind], strerror(errno)); 1445 fatalError("%s: %s\n", argv[optind], strerror(errno));
1436 } 1446 }
1437 } else {
1438 char *oldpath, *newpath;
1439 oldpath = getenv("PATH");
1440 newpath=(char*)xmalloc(strlen(oldpath)+12);
1441 snprintf(newpath, strlen(oldpath)+9, "PATH=./:%s", oldpath);
1442 putenv(newpath);
1443 execvp(argv[optind], argv+optind);
1444 fatalError("%s: %s\n", argv[optind], strerror(errno));
1445 } 1447 }
1446 1448
1447 /* initialize the cwd -- this is never freed...*/ 1449 /* initialize the cwd -- this is never freed...*/