Bugfix from Shaun Jackman (check that argv[optind] isn't null before

dereferencing it) plus a bunch of tweaks from me.
This commit is contained in:
Rob Landley 2006-07-09 17:03:07 +00:00
parent 1df45cf8e7
commit acf448d4f6

View File

@ -1498,6 +1498,8 @@ static void free_memory(void)
remove_job(&job_list, job_list.fg); remove_job(&job_list, job_list.fg);
} }
} }
#else
void free_memory(void);
#endif #endif
#ifdef CONFIG_LASH_JOB_CONTROL #ifdef CONFIG_LASH_JOB_CONTROL
@ -1528,7 +1530,7 @@ static void setup_job_control(void)
/* Put ourselves in our own process group. */ /* Put ourselves in our own process group. */
setsid(); setsid();
shell_pgrp = getpid (); shell_pgrp = getpid ();
setpgid (shell_pgrp, shell_pgrp); setpgid(shell_pgrp, shell_pgrp);
/* Grab control of the terminal. */ /* Grab control of the terminal. */
tcsetpgrp(shell_terminal, shell_pgrp); tcsetpgrp(shell_terminal, shell_pgrp);
@ -1577,7 +1579,7 @@ int lash_main(int argc_l, char **argv_l)
argv = argv+optind; argv = argv+optind;
break; break;
case 'i': case 'i':
interactive = TRUE; interactive++;
break; break;
default: default:
bb_show_usage(); bb_show_usage();
@ -1591,18 +1593,18 @@ int lash_main(int argc_l, char **argv_l)
* standard output is a terminal * standard output is a terminal
* Refer to Posix.2, the description of the `sh' utility. */ * Refer to Posix.2, the description of the `sh' utility. */
if (argv[optind]==NULL && input==stdin && if (argv[optind]==NULL && input==stdin &&
isatty(STDIN_FILENO) && isatty(STDOUT_FILENO)) { isatty(STDIN_FILENO) && isatty(STDOUT_FILENO))
interactive=TRUE; {
interactive++;
} }
setup_job_control(); setup_job_control();
if (interactive==TRUE) { if (interactive) {
//printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
/* Looks like they want an interactive shell */ /* Looks like they want an interactive shell */
#ifndef CONFIG_FEATURE_SH_EXTRA_QUIET if (!ENABLE_FEATURE_SH_EXTRA_QUIET) {
printf( "\n\n%s Built-in shell (lash)\n", BB_BANNER); printf( "\n\n%s Built-in shell (lash)\n", BB_BANNER);
printf( "Enter 'help' for a list of built-in commands.\n\n"); printf( "Enter 'help' for a list of built-in commands.\n\n");
#endif }
} else if (local_pending_command==NULL) { } else if (!local_pending_command && argv[optind]) {
//printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]); //printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]);
input = bb_xfopen(argv[optind], "r"); input = bb_xfopen(argv[optind], "r");
/* be lazy, never mark this closed */ /* be lazy, never mark this closed */
@ -1614,15 +1616,10 @@ int lash_main(int argc_l, char **argv_l)
if (!cwd) if (!cwd)
cwd = bb_msg_unknown; cwd = bb_msg_unknown;
#ifdef CONFIG_FEATURE_CLEAN_UP if (ENABLE_FEATURE_CLEAN_UP) atexit(free_memory);
atexit(free_memory);
#endif
#ifdef CONFIG_FEATURE_COMMAND_EDITING if (ENABLE_FEATURE_COMMAND_EDITING) cmdedit_set_initial_prompt();
cmdedit_set_initial_prompt(); else PS1 = NULL;
#else
PS1 = NULL;
#endif
return (busy_loop(input)); return (busy_loop(input));
} }