configure: create some convenience AC_SUBST's for the global includes
[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 /*
29  * Copyright (c) 1988 by Sun Microsystems, Inc.
30  */
31
32 /*
33  * issignals.c
34  *
35  * Description:
36  *      Signal masking functions
37  */
38
39
40 #include "isam_impl.h"
41 #include <signal.h>
42
43 /*
44  * _issignal_mask() is called at the beginning of each ISAM update operation
45  * to mask signals for the duration of the operation. _issignals_unmask()
46  * is called at the end of the operation to restore the original signal
47  * mask.
48  *
49  * _issignals_cntl() enables/disables this signal masking facility.
50  * (the default is "mask the signals").
51  *
52  * The variable already_masked is used to provide more robustness: it
53  * will prevent permanent signal masking due to bugs in the ISAM package.
54  * The permanent masking of signals would happen if _issignals_mask()
55  * were called twice in a row.
56  */
57
58
59 static int      do_mask = 1;                /* default value */
60 static int      already_masked;
61 static sigset_t oldmask;
62 static sigset_t allsignals;
63
64
65 /* opt, 1 will enable masking, 0 will disable masking */
66 int _issignals_cntl(int opt)
67 {
68     int         oldmask = do_mask;
69
70     do_mask = opt ? 1 : 0;
71
72     return (oldmask);
73 }
74
75 void
76 _issignals_mask(void)
77 {
78     if (do_mask && !already_masked) {
79         (void) sigfillset(&allsignals);
80         (void) sigdelset(&allsignals, SIGTRAP);
81         (void) sigdelset(&allsignals, SIGSEGV);
82         (void) sigdelset(&allsignals, SIGILL);
83         (void) sigdelset(&allsignals, SIGBUS);
84         (void) sigprocmask(SIG_SETMASK, &allsignals, &oldmask);
85         already_masked = 1;
86     }
87 }
88
89 void
90 _issignals_unmask(void)
91 {
92     if (do_mask) {
93         (void)sigprocmask(SIG_SETMASK, &oldmask, NULL);
94         already_masked = 0;
95     }
96 }