4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #pragma weak _signal = signal
30 #pragma weak _sighold = sighold
31 #pragma weak _sigrelse = sigrelse
32 #pragma weak _sigignore = sigignore
33 #pragma weak _sigset = sigset
36 #include <sys/types.h>
43 * Check for valid signal number as per SVID.
45 #define CHECK_SIG(s, code) \
46 if ((s) <= 0 || (s) >= NSIG || (s) == SIGKILL || (s) == SIGSTOP) { \
52 * Equivalent to stopdefault set in the kernel implementation (sig.c).
54 #define STOPDEFAULT(s) \
55 ((s) == SIGSTOP || (s) == SIGTSTP || (s) == SIGTTOU || (s) == SIGTTIN)
59 * SVr3.x signal compatibility routines. They are now
60 * implemented as library routines instead of system
65 signal(int sig
, void(*func
)(int)))(int)
67 struct sigaction nact
;
68 struct sigaction oact
;
70 CHECK_SIG(sig
, SIG_ERR
);
72 nact
.sa_handler
= func
;
73 nact
.sa_flags
= SA_RESETHAND
|SA_NODEFER
;
74 (void) sigemptyset(&nact
.sa_mask
);
77 * Pay special attention if sig is SIGCHLD and
78 * the disposition is SIG_IGN, per sysV signal man page.
81 nact
.sa_flags
|= SA_NOCLDSTOP
;
83 nact
.sa_flags
|= SA_NOCLDWAIT
;
87 nact
.sa_flags
|= SA_RESTART
;
89 if (sigaction(sig
, &nact
, &oact
) < 0)
92 return (oact
.sa_handler
);
103 * errno set on failure by either sigaddset or sigprocmask.
105 (void) sigemptyset(&set
);
106 if (sigaddset(&set
, sig
) < 0)
108 return (sigprocmask(SIG_BLOCK
, &set
, (sigset_t
*)0));
119 * errno set on failure by either sigaddset or sigprocmask.
121 (void) sigemptyset(&set
);
122 if (sigaddset(&set
, sig
) < 0)
124 return (sigprocmask(SIG_UNBLOCK
, &set
, (sigset_t
*)0));
130 struct sigaction act
;
135 act
.sa_handler
= SIG_IGN
;
137 (void) sigemptyset(&act
.sa_mask
);
140 * Pay special attention if sig is SIGCHLD and
141 * the disposition is SIG_IGN, per sysV signal man page.
143 if (sig
== SIGCHLD
) {
144 act
.sa_flags
|= SA_NOCLDSTOP
;
145 act
.sa_flags
|= SA_NOCLDWAIT
;
148 if (STOPDEFAULT(sig
))
149 act
.sa_flags
|= SA_RESTART
;
151 if (sigaction(sig
, &act
, NULL
) < 0)
154 (void) sigemptyset(&set
);
155 if (sigaddset(&set
, sig
) < 0)
157 return (sigprocmask(SIG_UNBLOCK
, &set
, (sigset_t
*)0));
169 * sigpause() is defined to unblock the signal
170 * and not block it again on return.
171 * sigsuspend() restores the original signal set,
172 * so we have to unblock sig overtly.
174 (void) sigprocmask(0, (sigset_t
*)0, &set
);
175 if (sigdelset(&set
, sig
) < 0)
177 rval
= sigsuspend(&set
);
178 (void) sigrelse(sig
);
183 sigset(int sig
, void(*func
)(int)))(int)
185 struct sigaction nact
;
186 struct sigaction oact
;
191 CHECK_SIG(sig
, SIG_ERR
);
193 (void) sigemptyset(&nset
);
194 if (sigaddset(&nset
, sig
) < 0)
197 if (func
== SIG_HOLD
) {
198 if (sigprocmask(SIG_BLOCK
, &nset
, &oset
) < 0)
200 if (sigaction(sig
, NULL
, &oact
) < 0)
203 nact
.sa_handler
= func
;
205 (void) sigemptyset(&nact
.sa_mask
);
207 * Pay special attention if sig is SIGCHLD and
208 * the disposition is SIG_IGN, per sysV signal man page.
210 if (sig
== SIGCHLD
) {
211 nact
.sa_flags
|= SA_NOCLDSTOP
;
213 nact
.sa_flags
|= SA_NOCLDWAIT
;
216 if (STOPDEFAULT(sig
))
217 nact
.sa_flags
|= SA_RESTART
;
219 if (sigaction(sig
, &nact
, &oact
) < 0)
222 if (sigprocmask(SIG_UNBLOCK
, &nset
, &oset
) < 0)
226 if ((code
= sigismember(&oset
, sig
)) < 0)
231 return (oact
.sa_handler
);