summaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-28 16:47:08 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-28 16:47:08 +0000
commit0937be5fa64e9dc0f2dc525225c34ab7c52f256c (patch)
tree44a4fa6eb07c4449bc11416ce92ccb9a7d895c84 /shell/hush.c
parentb5eaabb32221ece5d3a149cb3b49c439fa3647d5 (diff)
downloadbusybox-w32-0937be5fa64e9dc0f2dc525225c34ab7c52f256c.tar.gz
busybox-w32-0937be5fa64e9dc0f2dc525225c34ab7c52f256c.tar.bz2
busybox-w32-0937be5fa64e9dc0f2dc525225c34ab7c52f256c.zip
hush: make hush properly detect EOF on stdin (even interactive one -
think about pty being destroyed) and exit.
Diffstat (limited to '')
-rw-r--r--shell/hush.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 9e13e4a2e..25eb78f4e 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1023,8 +1023,9 @@ static const char* setup_prompt_string(int promptmode)
1023static line_input_t *line_input_state; 1023static line_input_t *line_input_state;
1024#endif 1024#endif
1025 1025
1026static void get_user_input(struct in_str *i) 1026static int get_user_input(struct in_str *i)
1027{ 1027{
1028 int r;
1028 const char *prompt_str; 1029 const char *prompt_str;
1029 static char the_command[BUFSIZ]; 1030 static char the_command[BUFSIZ];
1030 1031
@@ -1036,15 +1037,16 @@ static void get_user_input(struct in_str *i)
1036 ** atexit() handlers and other unwanted stuff to our 1037 ** atexit() handlers and other unwanted stuff to our
1037 ** child processes (rob@sysgo.de) 1038 ** child processes (rob@sysgo.de)
1038 */ 1039 */
1039 read_line_input(prompt_str, the_command, BUFSIZ, line_input_state); 1040 r = read_line_input(prompt_str, the_command, BUFSIZ, line_input_state);
1040#else 1041#else
1041 fputs(prompt_str, stdout); 1042 fputs(prompt_str, stdout);
1042 fflush(stdout); 1043 fflush(stdout);
1043 the_command[0] = fgetc(i->file); 1044 the_command[0] = r = fgetc(i->file);
1044 the_command[1] = '\0'; 1045 the_command[1] = '\0';
1045#endif 1046#endif
1046 fflush(stdout); 1047 fflush(stdout);
1047 i->p = the_command; 1048 i->p = the_command;
1049 return r; /* < 0 == EOF. Not meaningful otherwise */
1048} 1050}
1049 1051
1050/* This is the magic location that prints prompts 1052/* This is the magic location that prints prompts
@@ -1061,8 +1063,9 @@ static int file_get(struct in_str *i)
1061 /* need to double check i->file because we might be doing something 1063 /* need to double check i->file because we might be doing something
1062 * more complicated by now, like sourcing or substituting. */ 1064 * more complicated by now, like sourcing or substituting. */
1063 if (i->__promptme && interactive_fd && i->file == stdin) { 1065 if (i->__promptme && interactive_fd && i->file == stdin) {
1064 while (!i->p || !(interactive_fd && strlen(i->p))) { 1066 while (!i->p || !(interactive_fd && i->p[0])) {
1065 get_user_input(i); 1067 if (get_user_input(i) < 0)
1068 return EOF;
1066 } 1069 }
1067 i->promptmode = 2; 1070 i->promptmode = 2;
1068 i->__promptme = 0; 1071 i->__promptme = 0;