ae3f2fc94467b13b88c1d23172a59e141af7c948
[oweals/cde.git] / cde / lib / tt / mini_isam / issignals.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
24 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
25 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
26 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
27 /*%%  $XConsortium: issignals.c /main/3 1995/10/23 11:44:41 rswiston $                                                   */
28 #ifndef lint
29 static char sccsid[] = "@(#)issignals.c 1.7 89/08/30 Copyr 1988 Sun Micro";
30 #endif
31 /*
32  * Copyright (c) 1988 by Sun Microsystems, Inc.
33  */
34
35 /*
36  * issignals.c
37  *
38  * Description:
39  *      Signal masking functions
40  */
41
42
43 #include "isam_impl.h"
44 #include <signal.h>
45
46 /*
47  * _issignal_mask() is called at the beginning of each ISAM update operation
48  * to mask signals for the duration of the operation. _issignals_unmask()
49  * is called at the end of the operation to restore the original signal
50  * mask.
51  *
52  * _issignals_cntl() enables/disables this signal masking facility.
53  * (the default is "mask the signals").
54  *
55  * The variable already_masked is used to provide more robustness: it
56  * will prevent permanent signal masking due to bugs in the ISAM package.
57  * The permanent masking of signals would happen if _issignals_mask()
58  * were called twice in a row.
59  */
60
61
62 static int      do_mask = 1;                /* default value */
63 static int      already_masked;
64 static sigset_t oldmask;
65 static sigset_t allsignals;
66
67
68 /* opt, 1 will enable masking, 0 will disable masking */
69 _issignals_cntl(int opt)
70 {
71     int         oldmask = do_mask;
72
73     do_mask = opt ? 1 : 0;
74
75     return (oldmask);
76 }
77
78 void
79 _issignals_mask(void)
80 {
81     if (do_mask && !already_masked) {
82         (void) sigfillset(&allsignals);
83         (void) sigdelset(&allsignals, SIGTRAP);
84         (void) sigdelset(&allsignals, SIGSEGV);
85         (void) sigdelset(&allsignals, SIGILL);
86         (void) sigdelset(&allsignals, SIGBUS);
87         (void) sigprocmask(SIG_SETMASK, &allsignals, &oldmask);
88         already_masked = 1;
89     }
90 }
91
92 void
93 _issignals_unmask(void)
94 {
95     if (do_mask) {
96         (void)sigprocmask(SIG_SETMASK, &oldmask, NULL);
97         already_masked = 0;
98     }
99 }