From 97e0b1e08f1cebac32835aed6546cacee2d4468a Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 27 Jul 2013 19:02:32 +0800 Subject: [PATCH] Usermode - Handled read failures in readline correctly --- Usermode/Applications/CLIShell_src/main.c | 5 +++++ Usermode/Libraries/libreadline.so_src/main.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) 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; -- 2.20.1