diff options
author | David E. O'Brien <obrien@FreeBSD.org> | 2001-10-01 08:41:27 +0000 |
---|---|---|
committer | David E. O'Brien <obrien@FreeBSD.org> | 2001-10-01 08:41:27 +0000 |
commit | 3c195773444850fbd9cf231761a4f76eaf863e5a (patch) | |
tree | f9436ba88ca8f8420af319b0a12dd175381b507b /lib/libedit/sig.c | |
parent | c3aa3459b1000cef0734f66507785c13a7083e2a (diff) | |
download | src-3c195773444850fbd9cf231761a4f76eaf863e5a.tar.gz src-3c195773444850fbd9cf231761a4f76eaf863e5a.zip |
Notes
Diffstat (limited to 'lib/libedit/sig.c')
-rw-r--r-- | lib/libedit/sig.c | 193 |
1 files changed, 97 insertions, 96 deletions
diff --git a/lib/libedit/sig.c b/lib/libedit/sig.c index cdbed51d844b..55bebb03b59c 100644 --- a/lib/libedit/sig.c +++ b/lib/libedit/sig.c @@ -32,13 +32,15 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $NetBSD: sig.c,v 1.7 2001/01/04 15:55:03 christos Exp $ */ -#include <sys/cdefs.h> -__FBSDID("$FreeBSD$"); #if !defined(lint) && !defined(SCCSID) static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint && not SCCSID */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * sig.c: Signal handling stuff. @@ -51,14 +53,14 @@ static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93"; 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 __P((int)); +private void sig_handler(int); /* sig_handler(): * This is the handler called for all signals @@ -66,40 +68,39 @@ private void sig_handler __P((int)); * state in a private variable */ private void -sig_handler(signo) - int signo; +sig_handler(int signo) { - 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); + 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); } @@ -107,27 +108,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(sig_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 = (sig_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); } @@ -135,11 +137,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; } @@ -147,26 +149,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++) { + 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); } @@ -174,22 +175,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); } |