Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / lib / tt / mini_isam / issignals.c
1 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
2 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
3 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
4 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
5 /*%%  $XConsortium: issignals.c /main/3 1995/10/23 11:44:41 rswiston $                                                   */
6 #ifndef lint
7 static char sccsid[] = "@(#)issignals.c 1.7 89/08/30 Copyr 1988 Sun Micro";
8 #endif
9 /*
10  * Copyright (c) 1988 by Sun Microsystems, Inc.
11  */
12
13 /*
14  * issignals.c
15  *
16  * Description:
17  *      Signal masking functions
18  */
19
20
21 #include "isam_impl.h"
22 #include <signal.h>
23
24 /*
25  * _issignal_mask() is called at the beginning of each ISAM update operation
26  * to mask signals for the duration of the operation. _issignals_unmask()
27  * is called at the end of the operation to restore the original signal
28  * mask.
29  *
30  * _issignals_cntl() enables/disables this signal masking facility.
31  * (the default is "mask the signals").
32  *
33  * The variable already_masked is used to provide more robustness: it
34  * will prevent permanent signal masking due to bugs in the ISAM package.
35  * The permanent masking of signals would happen if _issignals_mask()
36  * were called twice in a row.
37  */
38
39
40 static int      do_mask = 1;                /* default value */
41 static int      already_masked;
42 static sigset_t oldmask;
43 static sigset_t allsignals;
44
45
46 _issignals_cntl(opt)
47     int         opt;                         /* 1 will enable masking */
48                                              /* 0 will disable masking */
49 {
50     int         oldmask = do_mask;
51
52     do_mask = opt ? 1 : 0;
53
54     return (oldmask);
55 }
56
57 _issignals_mask()
58 {
59     if (do_mask && !already_masked) {
60         (void) sigfillset(&allsignals);
61         (void) sigdelset(&allsignals, SIGTRAP);
62         (void) sigdelset(&allsignals, SIGSEGV);
63         (void) sigdelset(&allsignals, SIGILL);
64         (void) sigdelset(&allsignals, SIGBUS);
65         (void) sigprocmask(SIG_SETMASK, &allsignals, &oldmask);
66         already_masked = 1;
67     }
68 }
69
70 _issignals_unmask()
71 {
72     if (do_mask) {
73         (void)sigprocmask(SIG_SETMASK, &oldmask, NULL);
74         already_masked = 0;
75     }
76 }