Make signal handler safe. From Michael Knudsen, many thanks.

This commit is contained in:
christos 2005-05-18 00:50:24 +00:00
parent 9641151edb
commit 308097fac3

View File

@ -1,4 +1,4 @@
/* $NetBSD: test.c,v 1.15 2003/12/08 12:03:01 lukem Exp $ */
/* $NetBSD: test.c,v 1.16 2005/05/18 00:50:24 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
#if 0
static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: test.c,v 1.15 2003/12/08 12:03:01 lukem Exp $");
__RCSID("$NetBSD: test.c,v 1.16 2005/05/18 00:50:24 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -63,6 +63,8 @@ __RCSID("$NetBSD: test.c,v 1.15 2003/12/08 12:03:01 lukem Exp $");
static int continuation = 0;
static EditLine *el = NULL;
volatile sig_atomic_t gotsig = 0;
static u_char complete(EditLine *, int);
int main(int, char **);
static char *prompt(EditLine *);
@ -80,9 +82,7 @@ prompt(EditLine *el)
static void
sig(int i)
{
(void) fprintf(stderr, "Got signal %d.\n", i);
el_reset(el);
gotsig = i;
}
static unsigned char
@ -185,6 +185,12 @@ main(int argc, char *argv[])
(li->cursor >= li->lastchar) ? "" : li->cursor);
#endif
if (gotsig) {
(void) fprintf(stderr, "Got signal %d.\n", gotsig);
gotsig = 0;
el_reset(el);
}
if (!continuation && num == 1)
continue;