Usermode - Handled read failures in readline correctly
authorJohn Hodge <[email protected]>
Sat, 27 Jul 2013 11:02:32 +0000 (19:02 +0800)
committerJohn Hodge <[email protected]>
Sat, 27 Jul 2013 11:02:32 +0000 (19:02 +0800)
Usermode/Applications/CLIShell_src/main.c
Usermode/Libraries/libreadline.so_src/main.c

index 501359a..1a501ad 100644 (file)
@@ -8,6 +8,7 @@
 #include <string.h>\r
 #include "header.h"\r
 #include <readline.h>\r
+#include <errno.h>\r
 \r
 #define _stdin 0\r
 #define _stdout        1\r
@@ -80,6 +81,10 @@ int main(int argc, char *argv[], char **envp)
                // Read Command line\r
                sCommandStr = Readline( readline_state );\r
                printf("\n");\r
+               if( !sCommandStr ) {\r
+                       perror("Readline");\r
+                       return 1;\r
+               }\r
                \r
                // Parse Command Line into arguments\r
                iArgCount = Parse_Args(sCommandStr, saArgs);\r
index a12abc5..4566935 100644 (file)
@@ -10,6 +10,7 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <errno.h>
 
 #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;

UCC git Repository :: git.ucc.asn.au