1/*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Christos Zoulas of Cornell University. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution.
| 1/*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Christos Zoulas of Cornell University. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution.
|
16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors
| 16 * 3. Neither the name of the University nor the names of its contributors
|
21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 *
| 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 *
|
36 * $NetBSD: sig.c,v 1.7 2001/01/04 15:55:03 christos Exp $
| 32 * $NetBSD: sig.c,v 1.11 2003/08/07 16:44:33 agc Exp $
|
37 */ 38 39#if !defined(lint) && !defined(SCCSID) 40static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93"; 41#endif /* not lint && not SCCSID */ 42#include <sys/cdefs.h>
| 33 */ 34 35#if !defined(lint) && !defined(SCCSID) 36static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93"; 37#endif /* not lint && not SCCSID */ 38#include <sys/cdefs.h>
|
43__FBSDID("$FreeBSD: head/lib/libedit/sig.c 84260 2001-10-01 08:41:27Z obrien $");
| 39__FBSDID("$FreeBSD: head/lib/libedit/sig.c 148834 2005-08-07 20:55:59Z stefanf $");
|
44 45/* 46 * sig.c: Signal handling stuff. 47 * our policy is to trap all signals, set a good state 48 * and pass the ball to our caller. 49 */ 50#include "sys.h" 51#include "el.h" 52#include <stdlib.h> 53 54private EditLine *sel = NULL; 55 56private const int sighdl[] = { 57#define _DO(a) (a), 58 ALLSIGS 59#undef _DO 60 - 1 61}; 62 63private void sig_handler(int); 64 65/* sig_handler(): 66 * This is the handler called for all signals 67 * XXX: we cannot pass any data so we just store the old editline 68 * state in a private variable 69 */ 70private void 71sig_handler(int signo) 72{ 73 int i; 74 sigset_t nset, oset; 75 76 (void) sigemptyset(&nset); 77 (void) sigaddset(&nset, signo); 78 (void) sigprocmask(SIG_BLOCK, &nset, &oset); 79 80 switch (signo) { 81 case SIGCONT: 82 tty_rawmode(sel); 83 if (ed_redisplay(sel, 0) == CC_REFRESH) 84 re_refresh(sel); 85 term__flush(); 86 break; 87 88 case SIGWINCH: 89 el_resize(sel); 90 break; 91 92 default: 93 tty_cookedmode(sel); 94 break; 95 } 96 97 for (i = 0; sighdl[i] != -1; i++) 98 if (signo == sighdl[i]) 99 break; 100 101 (void) signal(signo, sel->el_signal[i]); 102 (void) sigprocmask(SIG_SETMASK, &oset, NULL); 103 (void) kill(0, signo); 104} 105 106 107/* sig_init(): 108 * Initialize all signal stuff 109 */ 110protected int 111sig_init(EditLine *el) 112{ 113 int i; 114 sigset_t nset, oset; 115 116 (void) sigemptyset(&nset); 117#define _DO(a) (void) sigaddset(&nset, a); 118 ALLSIGS 119#undef _DO 120 (void) sigprocmask(SIG_BLOCK, &nset, &oset); 121
| 40 41/* 42 * sig.c: Signal handling stuff. 43 * our policy is to trap all signals, set a good state 44 * and pass the ball to our caller. 45 */ 46#include "sys.h" 47#include "el.h" 48#include <stdlib.h> 49 50private EditLine *sel = NULL; 51 52private const int sighdl[] = { 53#define _DO(a) (a), 54 ALLSIGS 55#undef _DO 56 - 1 57}; 58 59private void sig_handler(int); 60 61/* sig_handler(): 62 * This is the handler called for all signals 63 * XXX: we cannot pass any data so we just store the old editline 64 * state in a private variable 65 */ 66private void 67sig_handler(int signo) 68{ 69 int i; 70 sigset_t nset, oset; 71 72 (void) sigemptyset(&nset); 73 (void) sigaddset(&nset, signo); 74 (void) sigprocmask(SIG_BLOCK, &nset, &oset); 75 76 switch (signo) { 77 case SIGCONT: 78 tty_rawmode(sel); 79 if (ed_redisplay(sel, 0) == CC_REFRESH) 80 re_refresh(sel); 81 term__flush(); 82 break; 83 84 case SIGWINCH: 85 el_resize(sel); 86 break; 87 88 default: 89 tty_cookedmode(sel); 90 break; 91 } 92 93 for (i = 0; sighdl[i] != -1; i++) 94 if (signo == sighdl[i]) 95 break; 96 97 (void) signal(signo, sel->el_signal[i]); 98 (void) sigprocmask(SIG_SETMASK, &oset, NULL); 99 (void) kill(0, signo); 100} 101 102 103/* sig_init(): 104 * Initialize all signal stuff 105 */ 106protected int 107sig_init(EditLine *el) 108{ 109 int i; 110 sigset_t nset, oset; 111 112 (void) sigemptyset(&nset); 113#define _DO(a) (void) sigaddset(&nset, a); 114 ALLSIGS 115#undef _DO 116 (void) sigprocmask(SIG_BLOCK, &nset, &oset); 117
|
122#define SIGSIZE (sizeof(sighdl) / sizeof(sighdl[0]) * sizeof(sig_t))
| 118#define SIGSIZE (sizeof(sighdl) / sizeof(sighdl[0]) * sizeof(el_signalhandler_t))
|
123
| 119
|
124 el->el_signal = (sig_t *) el_malloc(SIGSIZE);
| 120 el->el_signal = (el_signalhandler_t *) el_malloc(SIGSIZE);
|
125 if (el->el_signal == NULL) 126 return (-1); 127 for (i = 0; sighdl[i] != -1; i++) 128 el->el_signal[i] = SIG_ERR; 129 130 (void) sigprocmask(SIG_SETMASK, &oset, NULL); 131 132 return (0); 133} 134 135 136/* sig_end(): 137 * Clear all signal stuff 138 */ 139protected void 140sig_end(EditLine *el) 141{ 142 143 el_free((ptr_t) el->el_signal); 144 el->el_signal = NULL; 145} 146 147 148/* sig_set(): 149 * set all the signal handlers 150 */ 151protected void 152sig_set(EditLine *el) 153{ 154 int i; 155 sigset_t nset, oset; 156 157 (void) sigemptyset(&nset); 158#define _DO(a) (void) sigaddset(&nset, a); 159 ALLSIGS 160#undef _DO 161 (void) sigprocmask(SIG_BLOCK, &nset, &oset); 162 163 for (i = 0; sighdl[i] != -1; i++) {
| 121 if (el->el_signal == NULL) 122 return (-1); 123 for (i = 0; sighdl[i] != -1; i++) 124 el->el_signal[i] = SIG_ERR; 125 126 (void) sigprocmask(SIG_SETMASK, &oset, NULL); 127 128 return (0); 129} 130 131 132/* sig_end(): 133 * Clear all signal stuff 134 */ 135protected void 136sig_end(EditLine *el) 137{ 138 139 el_free((ptr_t) el->el_signal); 140 el->el_signal = NULL; 141} 142 143 144/* sig_set(): 145 * set all the signal handlers 146 */ 147protected void 148sig_set(EditLine *el) 149{ 150 int i; 151 sigset_t nset, oset; 152 153 (void) sigemptyset(&nset); 154#define _DO(a) (void) sigaddset(&nset, a); 155 ALLSIGS 156#undef _DO 157 (void) sigprocmask(SIG_BLOCK, &nset, &oset); 158 159 for (i = 0; sighdl[i] != -1; i++) {
|
164 sig_t s;
| 160 el_signalhandler_t s;
|
165 /* This could happen if we get interrupted */ 166 if ((s = signal(sighdl[i], sig_handler)) != sig_handler) 167 el->el_signal[i] = s; 168 } 169 sel = el; 170 (void) sigprocmask(SIG_SETMASK, &oset, NULL); 171} 172 173 174/* sig_clr(): 175 * clear all the signal handlers 176 */ 177protected void 178sig_clr(EditLine *el) 179{ 180 int i; 181 sigset_t nset, oset; 182 183 (void) sigemptyset(&nset); 184#define _DO(a) (void) sigaddset(&nset, a); 185 ALLSIGS 186#undef _DO 187 (void) sigprocmask(SIG_BLOCK, &nset, &oset); 188 189 for (i = 0; sighdl[i] != -1; i++) 190 if (el->el_signal[i] != SIG_ERR) 191 (void) signal(sighdl[i], el->el_signal[i]); 192 193 sel = NULL; /* we are going to die if the handler is 194 * called */ 195 (void) sigprocmask(SIG_SETMASK, &oset, NULL); 196}
| 161 /* This could happen if we get interrupted */ 162 if ((s = signal(sighdl[i], sig_handler)) != sig_handler) 163 el->el_signal[i] = s; 164 } 165 sel = el; 166 (void) sigprocmask(SIG_SETMASK, &oset, NULL); 167} 168 169 170/* sig_clr(): 171 * clear all the signal handlers 172 */ 173protected void 174sig_clr(EditLine *el) 175{ 176 int i; 177 sigset_t nset, oset; 178 179 (void) sigemptyset(&nset); 180#define _DO(a) (void) sigaddset(&nset, a); 181 ALLSIGS 182#undef _DO 183 (void) sigprocmask(SIG_BLOCK, &nset, &oset); 184 185 for (i = 0; sighdl[i] != -1; i++) 186 if (el->el_signal[i] != SIG_ERR) 187 (void) signal(sighdl[i], el->el_signal[i]); 188 189 sel = NULL; /* we are going to die if the handler is 190 * called */ 191 (void) sigprocmask(SIG_SETMASK, &oset, NULL); 192}
|