From: John Hodge Date: Sat, 27 Jul 2013 11:02:32 +0000 (+0800) Subject: Usermode - Handled read failures in readline correctly X-Git-Tag: rel0.15~321 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=97e0b1e08f1cebac32835aed6546cacee2d4468a;p=tpg%2Facess2.git Usermode - Handled read failures in readline correctly --- diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index 501359a8..1a501ad1 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -8,6 +8,7 @@ #include #include "header.h" #include +#include #define _stdin 0 #define _stdout 1 @@ -80,6 +81,10 @@ int main(int argc, char *argv[], char **envp) // Read Command line sCommandStr = Readline( readline_state ); printf("\n"); + if( !sCommandStr ) { + perror("Readline"); + return 1; + } // Parse Command Line into arguments iArgCount = Parse_Args(sCommandStr, saArgs); diff --git a/Usermode/Libraries/libreadline.so_src/main.c b/Usermode/Libraries/libreadline.so_src/main.c index a12abc59..45669355 100644 --- a/Usermode/Libraries/libreadline.so_src/main.c +++ b/Usermode/Libraries/libreadline.so_src/main.c @@ -10,6 +10,7 @@ #include #include #include +#include #define STDIN_FD 0 #define STDOUT_FD 1 @@ -105,6 +106,7 @@ char *Readline_NonBlock(tReadline *Info) } // Return NULL when command is still being edited + errno = EAGAIN; return NULL; } @@ -116,7 +118,7 @@ char *Readline(tReadline *Info) struct ptymode mode = {.InputMode = 0, .OutputMode = 0}; _SysIOCtl(STDIN_FD, PTY_IOCTL_SETMODE, &mode); - while( NULL == (ret = Readline_NonBlock(Info)) ); + while( NULL == (ret = Readline_NonBlock(Info)) && errno == EAGAIN ); // stty +echo,canon mode.InputMode = PTYIMODE_CANON|PTYIMODE_ECHO;