386BSD 0.1 development
[unix-history] / usr / othersrc / contrib / isode / compat / signals.c
CommitLineData
48435ab0
WJ
1/* signals.c - signal handling */
2
3#ifndef lint
4static char *rcsid = "$Header: /f/osi/compat/RCS/signals.c,v 7.2 91/02/22 09:15:51 mrose Interim $";
5#endif
6
7/*
8 * $Header: /f/osi/compat/RCS/signals.c,v 7.2 91/02/22 09:15:51 mrose Interim $
9 *
10 *
11 * $Log: signals.c,v $
12 * Revision 7.2 91/02/22 09:15:51 mrose
13 * Interim 6.8
14 *
15 * Revision 7.1 90/10/29 18:38:03 mrose
16 * updates
17 *
18 * Revision 7.0 89/11/23 21:23:28 mrose
19 * Release 6.0
20 *
21 */
22
23/*
24 * NOTICE
25 *
26 * Acquisition, use, and distribution of this module and related
27 * materials are subject to the restrictions of a license agreement.
28 * Consult the Preface in the User's Manual for the full terms of
29 * this agreement.
30 *
31 */
32
33
34/* LINTLIBRARY */
35
36#include <signal.h>
37#ifndef BADSIG
38#define BADSIG ((SFP) -1)
39#endif
40#include "manifest.h"
41
42/* \f */
43
44int _iosignals_set = 0;
45
46/* \f Berkeley UNIX: 4.2 */
47
48#ifndef XOS_2
49#ifdef BSDSIGS
50
51/* Simply including <signal.h> is sufficient for everything but AIX */
52
53#ifdef AIX /* #define'd to be _signal */
54IFP signal (sig, func)
55int sig;
56IFP func;
57{
58 struct sigvec sv1,
59 sv2;
60
61 sv1.sv_handler = func;
62 sv1.sv_mask = sv1.sv_onstack = 0;
63 return (sigvec (sig, &sv1, &sv2) != NOTOK ? sv2.sv_handler : BADSIG);
64}
65#endif
66
67#else
68
69/* \f AT&T UNIX: 5 */
70
71
72/* Probably a race condition or two in this code */
73
74
75static int blocked = 0;
76static int pending = 0;
77
78static SFP handler[NSIG];
79
80
81static int sigser (sig)
82int sig;
83{
84 (void) signal (sig, sigser);
85
86 pending |= sigmask (sig);
87}
88
89/* \f */
90
91int sigblock (mask)
92int mask;
93{
94 register int sig,
95 smask;
96 long omask = blocked;
97
98 if (mask == 0)
99 return blocked;
100
101 for (sig = 1, smask = sigmask (sig); sig < NSIG; sig++, smask <<= 1)
102 if ((smask & mask) && !(smask & blocked)) {
103 pending &= ~smask;
104 handler[sig] = signal (sig, sigser);
105 blocked |= smask;
106 }
107
108 return omask;
109}
110
111
112int sigsetmask (mask)
113int mask;
114{
115 register int sig,
116 smask;
117 long omask = blocked;
118
119 for (sig = 1, smask = sigmask (sig); sig < NSIG; sig++, smask <<= 1)
120 if (smask & mask) {
121 if (smask & blocked)
122 continue;
123
124 pending &= ~smask;
125 handler[sig] = signal (sig, sigser);
126 blocked |= smask;
127 }
128 else
129 if (smask & blocked) {
130 blocked &= ~smask;
131 (void) signal (sig, handler[sig] != BADSIG ? handler[sig]
132 : SIG_DFL);
133 if (smask & pending) {
134 pending &= ~smask;
135 (void) kill (getpid (), sig);
136 }
137 }
138
139 return omask;
140}
141
142#endif
143#endif