diff options
Diffstat (limited to 'lib/libedit/sig.c')
-rw-r--r-- | lib/libedit/sig.c | 195 |
1 files changed, 96 insertions, 99 deletions
diff --git a/lib/libedit/sig.c b/lib/libedit/sig.c index 145b6c684f2..28ce610b0fe 100644 --- a/lib/libedit/sig.c +++ b/lib/libedit/sig.c @@ -1,5 +1,5 @@ -/* $OpenBSD: sig.c,v 1.9 2003/06/02 20:18:40 millert Exp $ */ -/* $NetBSD: sig.c,v 1.3 1997/04/11 17:52:48 christos Exp $ */ +/* $OpenBSD: sig.c,v 1.10 2003/10/31 08:42:24 otto Exp $ */ +/* $NetBSD: sig.c,v 1.11 2003/08/07 16:44:33 agc Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -33,11 +33,12 @@ * SUCH DAMAGE. */ +#include "config.h" #if !defined(lint) && !defined(SCCSID) #if 0 static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93"; #else -static const char rcsid[] = "$OpenBSD: sig.c,v 1.9 2003/06/02 20:18:40 millert Exp $"; +static const char rcsid[] = "$OpenBSD: sig.c,v 1.10 2003/10/31 08:42:24 otto Exp $"; #endif #endif /* not lint && not SCCSID */ @@ -46,17 +47,16 @@ static const char rcsid[] = "$OpenBSD: sig.c,v 1.9 2003/06/02 20:18:40 millert E * our policy is to trap all signals, set a good state * and pass the ball to our caller. */ -#include "sys.h" #include "el.h" #include <stdlib.h> private EditLine *sel = NULL; -private int sighdl[] = { -#define _DO(a) (a), - ALLSIGS -#undef _DO - -1 +private const int sighdl[] = { +#define _DO(a) (a), + ALLSIGS +#undef _DO + - 1 }; private void sig_handler(int); @@ -67,42 +67,39 @@ private void sig_handler(int); * state in a private variable */ private void -sig_handler(signo) - int signo; +sig_handler(int signo) { - int save_errno = errno; - int i; - sigset_t nset, oset; - - (void)sigemptyset(&nset); - (void)sigaddset(&nset, signo); - (void)sigprocmask(SIG_BLOCK, &nset, &oset); - - switch (signo) { - case SIGCONT: - tty_rawmode(sel); /* XXX signal race */ - if (ed_redisplay(sel, 0) == CC_REFRESH) /* XXX signal race */ - re_refresh(sel); /* XXX signal race */ - term__flush(); /* XXX signal race */ - break; - - case SIGWINCH: - el_resize(sel); /* XXX signal race */ - break; - - default: - tty_cookedmode(sel); /* XXX signal race */ - break; - } - - for (i = 0; sighdl[i] != -1; i++) - if (signo == sighdl[i]) - break; - - (void)signal(signo, sel->el_signal[i]); - (void)sigprocmask(SIG_SETMASK, &oset, NULL); - (void)kill(0, signo); - errno = save_errno; + int i; + sigset_t nset, oset; + + (void) sigemptyset(&nset); + (void) sigaddset(&nset, signo); + (void) sigprocmask(SIG_BLOCK, &nset, &oset); + + switch (signo) { + case SIGCONT: + tty_rawmode(sel); + if (ed_redisplay(sel, 0) == CC_REFRESH) + re_refresh(sel); + term__flush(); + break; + + case SIGWINCH: + el_resize(sel); + break; + + default: + tty_cookedmode(sel); + break; + } + + for (i = 0; sighdl[i] != -1; i++) + if (signo == sighdl[i]) + break; + + (void) signal(signo, sel->el_signal[i]); + (void) sigprocmask(SIG_SETMASK, &oset, NULL); + (void) kill(0, signo); } @@ -110,27 +107,28 @@ sig_handler(signo) * Initialize all signal stuff */ protected int -sig_init(el) - EditLine *el; +sig_init(EditLine *el) { - int i; - sigset_t nset, oset; + int i; + sigset_t nset, oset; - (void)sigemptyset(&nset); -#define _DO(a) (void)sigaddset(&nset, a); - ALLSIGS -#undef _DO - (void)sigprocmask(SIG_BLOCK, &nset, &oset); + (void) sigemptyset(&nset); +#define _DO(a) (void) sigaddset(&nset, a); + ALLSIGS +#undef _DO + (void) sigprocmask(SIG_BLOCK, &nset, &oset); -#define SIGSIZE (sizeof(sighdl) / sizeof(sighdl[0]) * sizeof(sig_t)) +#define SIGSIZE (sizeof(sighdl) / sizeof(sighdl[0]) * sizeof(el_signalhandler_t)) - el->el_signal = (sig_t *) el_malloc(SIGSIZE); - for (i = 0; sighdl[i] != -1; i++) - el->el_signal[i] = SIG_ERR; + el->el_signal = (el_signalhandler_t *) el_malloc(SIGSIZE); + if (el->el_signal == NULL) + return (-1); + for (i = 0; sighdl[i] != -1; i++) + el->el_signal[i] = SIG_ERR; - (void)sigprocmask(SIG_SETMASK, &oset, NULL); + (void) sigprocmask(SIG_SETMASK, &oset, NULL); - return 0; + return (0); } @@ -138,11 +136,11 @@ sig_init(el) * Clear all signal stuff */ protected void -sig_end(el) - EditLine *el; +sig_end(EditLine *el) { - el_free((ptr_t) el->el_signal); - el->el_signal = NULL; + + el_free((ptr_t) el->el_signal); + el->el_signal = NULL; } @@ -150,26 +148,25 @@ sig_end(el) * set all the signal handlers */ protected void -sig_set(el) - EditLine *el; +sig_set(EditLine *el) { - int i; - sigset_t nset, oset; - - (void)sigemptyset(&nset); -#define _DO(a) (void)sigaddset(&nset, a); - ALLSIGS -#undef _DO - (void)sigprocmask(SIG_BLOCK, &nset, &oset); - - for (i = 0; sighdl[i] != -1; i++) { - sig_t s; - /* This could happen if we get interrupted */ - if ((s = signal(sighdl[i], sig_handler)) != sig_handler) - el->el_signal[i] = s; - } - sel = el; - (void)sigprocmask(SIG_SETMASK, &oset, NULL); + int i; + sigset_t nset, oset; + + (void) sigemptyset(&nset); +#define _DO(a) (void) sigaddset(&nset, a); + ALLSIGS +#undef _DO + (void) sigprocmask(SIG_BLOCK, &nset, &oset); + + for (i = 0; sighdl[i] != -1; i++) { + el_signalhandler_t s; + /* This could happen if we get interrupted */ + if ((s = signal(sighdl[i], sig_handler)) != sig_handler) + el->el_signal[i] = s; + } + sel = el; + (void) sigprocmask(SIG_SETMASK, &oset, NULL); } @@ -177,22 +174,22 @@ sig_set(el) * clear all the signal handlers */ protected void -sig_clr(el) - EditLine *el; +sig_clr(EditLine *el) { - int i; - sigset_t nset, oset; - - (void)sigemptyset(&nset); -#define _DO(a) (void)sigaddset(&nset, a); - ALLSIGS -#undef _DO - (void)sigprocmask(SIG_BLOCK, &nset, &oset); - - for (i = 0; sighdl[i] != -1; i++) - if (el->el_signal[i] != SIG_ERR) - (void)signal(sighdl[i], el->el_signal[i]); - - sel = NULL; /* we are going to die if the handler is called */ - (void)sigprocmask(SIG_SETMASK, &oset, NULL); + int i; + sigset_t nset, oset; + + (void) sigemptyset(&nset); +#define _DO(a) (void) sigaddset(&nset, a); + ALLSIGS +#undef _DO + (void) sigprocmask(SIG_BLOCK, &nset, &oset); + + for (i = 0; sighdl[i] != -1; i++) + if (el->el_signal[i] != SIG_ERR) + (void) signal(sighdl[i], el->el_signal[i]); + + sel = NULL; /* we are going to die if the handler is + * called */ + (void) sigprocmask(SIG_SETMASK, &oset, NULL); } |