]> git.ipfire.org Git - thirdparty/newt.git/commitdiff
return NEWT_EXIT_ERROR from form when stdin disappears
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 10 Nov 2010 17:10:46 +0000 (18:10 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 10 Nov 2010 17:12:32 +0000 (18:12 +0100)
form.c
newt.c
newt.h

diff --git a/form.c b/form.c
index 24542a0c9a92a6957df894250386564be2f11657..5b421fbac4b4e856e93cf48fc97c9d1069395edf 100644 (file)
--- a/form.c
+++ b/form.c
@@ -841,7 +841,8 @@ newtComponent newtRunForm(newtComponent co) {
        } else {
            return NULL;
        }
-    }
+    } else if (es.reason == NEWT_EXIT_ERROR)
+       return NULL;
 
     return es.u.co;
 }
@@ -1072,6 +1073,12 @@ void newtFormRun(newtComponent co, struct newtExitStruct * es) {
                    }
                }
 
+               if (key == NEWT_KEY_ERROR) {
+                   es->u.watch = -1;
+                   es->reason = NEWT_EXIT_ERROR;
+                   done = 1;
+               }
+
                if (!done) {
                    ev.event = EV_KEYPRESS;
                    ev.u.key = key;
diff --git a/newt.c b/newt.c
index 4e37bc1e0a6d91404b64d605c5ac8d5ab205207c..ab41dd80a5a4e5efabb95c2ddc983f2116dfb635 100644 (file)
--- a/newt.c
+++ b/newt.c
@@ -555,29 +555,30 @@ static void kmap_trie_fallback(struct kmap_trie_entry *to,
 }
 
 int newtGetKey(void) {
-    int key;
+    int key, lastcode, errors = 0;
     unsigned char *chptr = keyreader_buf, *lastmatch;
-    int lastcode;
     struct kmap_trie_entry *curr = kmap_trie_root;
 
     do {
        key = getkey();
        if (key == SLANG_GETKEY_ERROR) {
-           /* Either garbage was read, or stdin disappeared
-            * (the parent terminal was proably closed)
-            */
            if (needResize) {
                 needResize = 0;
                return NEWT_KEY_RESIZE;
             }
 
-           /* ignore other signals */
+           /* Ignore other signals, but assume that stdin disappeared (the
+            * parent terminal was proably closed) if the error persists.
+            */
+           if (errors++ > 10)
+               return NEWT_KEY_ERROR;
+
            continue;
        }
 
        if (key == NEWT_KEY_SUSPEND && suspendCallback)
            suspendCallback(suspendCallbackData);
-    } while (key == NEWT_KEY_SUSPEND);
+    } while (key == NEWT_KEY_SUSPEND || key == SLANG_GETKEY_ERROR);
 
     /* Read more characters, matching against the trie as we go */
     lastcode = *chptr = key;
diff --git a/newt.h b/newt.h
index 3111a21a57c7611d2a2cab525c1d6cf1a0904f3d..f71ce1e8fcd8fcb226275dc2a695fcbf8bb793d5 100644 (file)
--- a/newt.h
+++ b/newt.h
@@ -217,7 +217,7 @@ char * newtReflowText(char * text, int width, int flexDown, int flexUp,
 
 struct newtExitStruct {
     enum { NEWT_EXIT_HOTKEY, NEWT_EXIT_COMPONENT, NEWT_EXIT_FDREADY,
-          NEWT_EXIT_TIMER } reason;
+          NEWT_EXIT_TIMER, NEWT_EXIT_ERROR } reason;
     union {
        int watch;
        int key;
@@ -307,6 +307,7 @@ void newtComponentDestroy(newtComponent co);
 
 /* not really a key, but newtGetKey returns it */
 #define NEWT_KEY_RESIZE                        NEWT_KEY_EXTRA_BASE + 113
+#define NEWT_KEY_ERROR                 NEWT_KEY_EXTRA_BASE + 114
 
 #define NEWT_ANCHOR_LEFT               (1 << 0)
 #define NEWT_ANCHOR_RIGHT              (1 << 1)