From: Miroslav Lichvar Date: Wed, 10 Nov 2010 17:10:46 +0000 (+0100) Subject: return NEWT_EXIT_ERROR from form when stdin disappears X-Git-Tag: r0-52-13~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b8b8a86f22d08216328dffb8d70b3ae67629a905;p=thirdparty%2Fnewt.git return NEWT_EXIT_ERROR from form when stdin disappears --- diff --git a/form.c b/form.c index 24542a0..5b421fb 100644 --- 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 4e37bc1..ab41dd8 100644 --- 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 3111a21..f71ce1e 100644 --- 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)