From: Philipp Takacs Date: Sat, 21 Feb 2015 10:05:43 +0000 (+0100) Subject: remove longjmp in signalhandler of prompter X-Git-Tag: mmh-0.2-RC1~53 X-Git-Url: http://git.marmaro.de/?p=mmh;a=commitdiff_plain;h=11f38fca55972832ee09a3b1ac8693050500545b remove longjmp in signalhandler of prompter to avoid undefined behavior use close(2) in the signal handler --- diff --git a/uip/prompter.c b/uip/prompter.c index 4d0ce86..e42e8df 100644 --- a/uip/prompter.c +++ b/uip/prompter.c @@ -12,6 +12,7 @@ #include #include #include +#include static struct swit switches[] = { #define PREPSW 0 @@ -34,8 +35,8 @@ static struct swit switches[] = { }; -static int wtuser = 0; -static int sigint = 0; +volatile sig_atomic_t wtuser = 0; +volatile sig_atomic_t sigint = 0; static jmp_buf sigenv; /* @@ -263,6 +264,7 @@ int getln(char *buffer, int n) { int c; + sig_atomic_t psigint; char *cp; cp = buffer; @@ -271,15 +273,17 @@ getln(char *buffer, int n) switch (setjmp(sigenv)) { case 0: wtuser = 1; + psigint = sigint; break; - case DONE: - wtuser = 0; - return 0; - default: wtuser = 0; - return NOTOK; + if (sigint == psigint) { + return 0; + } else { + sigint = psigint; + return NOTOK; + } } for (;;) { @@ -311,7 +315,8 @@ getln(char *buffer, int n) static void intrser(int i) { - if (wtuser) - longjmp(sigenv, NOTOK); + if (wtuser) { + close(STDIN_FILENO); + } sigint++; }