hush: make hush properly detect EOF on stdin (even interactive one -
think about pty being destroyed) and exit.
This commit is contained in:
parent
b5eaabb322
commit
0937be5fa6
13
shell/hush.c
13
shell/hush.c
@ -1023,8 +1023,9 @@ static const char* setup_prompt_string(int promptmode)
|
|||||||
static line_input_t *line_input_state;
|
static line_input_t *line_input_state;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void get_user_input(struct in_str *i)
|
static int get_user_input(struct in_str *i)
|
||||||
{
|
{
|
||||||
|
int r;
|
||||||
const char *prompt_str;
|
const char *prompt_str;
|
||||||
static char the_command[BUFSIZ];
|
static char the_command[BUFSIZ];
|
||||||
|
|
||||||
@ -1036,15 +1037,16 @@ static void get_user_input(struct in_str *i)
|
|||||||
** atexit() handlers and other unwanted stuff to our
|
** atexit() handlers and other unwanted stuff to our
|
||||||
** child processes (rob@sysgo.de)
|
** child processes (rob@sysgo.de)
|
||||||
*/
|
*/
|
||||||
read_line_input(prompt_str, the_command, BUFSIZ, line_input_state);
|
r = read_line_input(prompt_str, the_command, BUFSIZ, line_input_state);
|
||||||
#else
|
#else
|
||||||
fputs(prompt_str, stdout);
|
fputs(prompt_str, stdout);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
the_command[0] = fgetc(i->file);
|
the_command[0] = r = fgetc(i->file);
|
||||||
the_command[1] = '\0';
|
the_command[1] = '\0';
|
||||||
#endif
|
#endif
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
i->p = the_command;
|
i->p = the_command;
|
||||||
|
return r; /* < 0 == EOF. Not meaningful otherwise */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is the magic location that prints prompts
|
/* This is the magic location that prints prompts
|
||||||
@ -1061,8 +1063,9 @@ static int file_get(struct in_str *i)
|
|||||||
/* need to double check i->file because we might be doing something
|
/* need to double check i->file because we might be doing something
|
||||||
* more complicated by now, like sourcing or substituting. */
|
* more complicated by now, like sourcing or substituting. */
|
||||||
if (i->__promptme && interactive_fd && i->file == stdin) {
|
if (i->__promptme && interactive_fd && i->file == stdin) {
|
||||||
while (!i->p || !(interactive_fd && strlen(i->p))) {
|
while (!i->p || !(interactive_fd && i->p[0])) {
|
||||||
get_user_input(i);
|
if (get_user_input(i) < 0)
|
||||||
|
return EOF;
|
||||||
}
|
}
|
||||||
i->promptmode = 2;
|
i->promptmode = 2;
|
||||||
i->__promptme = 0;
|
i->__promptme = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user