From 8a68b60f57ee47d7f40c655394bbb8f532c1f41f Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 23 Nov 2009 21:55:36 +0000 Subject: [PATCH] 2009-11-23 Joel Sherrill * libmisc/shell/login_prompt.c: Properly process EOF and do not depend on ungetc() to propagate the status back. --- cpukit/ChangeLog | 5 +++++ cpukit/libmisc/shell/login_prompt.c | 25 ++++++++----------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index ef61588634..8c6836242a 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,8 @@ +2009-11-23 Joel Sherrill + + * libmisc/shell/login_prompt.c: Properly process EOF and do not depend + on ungetc() to propagate the status back. + 2009-11-23 Joel Sherrill * score/inline/rtems/score/thread.inl: Eliminate unused variable and diff --git a/cpukit/libmisc/shell/login_prompt.c b/cpukit/libmisc/shell/login_prompt.c index 0e754f7120..46b0aa5e0c 100644 --- a/cpukit/libmisc/shell/login_prompt.c +++ b/cpukit/libmisc/shell/login_prompt.c @@ -78,7 +78,7 @@ static int rtems_shell_discard( int c, FILE *stream) return c; } -static void rtems_shell_get_text( +static bool rtems_shell_get_text( FILE *in, FILE *out, char *line, @@ -93,7 +93,7 @@ static void rtems_shell_get_text( size_t i = 0; if (size < 1) { - return; + return false; } tcdrain( fd_in); @@ -106,23 +106,12 @@ static void rtems_shell_get_text( switch (c) { case EOF: - /* Here comes an ugly hack: The Termios driver's read() handler returns - * 0 to the C library's fgets() if it times out. fgets() interprets - * this (correctly) as EOF, a condition we want to undo since it's not - * really true since we really have a read error (Termios bug?). - * - * As a workaround we push something back and read it again. This - * should simply reset the EOF condition. - */ - if (ungetc( '?', in) == '?') { - fgetc( in); - } - break; + return false; case '\n': case '\r': put( '\n', out); line [i] = '\0'; - return; + return true; case 127: case '\b': if (i > 0) { @@ -181,12 +170,14 @@ bool rtems_shell_login_prompt( fprintf( out, "%s login: ", device); fflush( out); - rtems_shell_get_text( in, out, user, sizeof( user)); + if ( !rtems_shell_get_text( in, out, user, sizeof( user)) ) + break; fflush( in); fprintf( out, "Password: "); fflush( out); - rtems_shell_get_text( in, NULL, passphrase, sizeof( passphrase)); + if ( !rtems_shell_get_text( in, NULL, passphrase, sizeof( passphrase)) ) + break; fputc( '\n', out); result = check( user, passphrase);