1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright (c) 2000 by Sun Microsystems, Inc.
24 * All rights reserved.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <signal.h>
29 #include <thread.h>
30 #include <unistd.h>
31 #include <errno.h>
32
33 #include "sysevent_signal.h"
34
35 static se_signal_f *sig_handlers[NSIG];
36 static void *sig_data[NSIG];
37
38 static void
sig_stub(int sig,siginfo_t * sip,void * ucp)39 sig_stub(int sig, siginfo_t *sip, void *ucp)
40 {
41 sig_handlers[sig](sig, sip, (ucontext_t *)ucp, sig_data[sig]);
42 }
43
44 int
se_signal_sethandler(int sig,se_signal_f * handler,void * data)45 se_signal_sethandler(int sig, se_signal_f *handler, void *data)
46 {
47 struct sigaction act;
48 int status;
49
50 sig_handlers[sig] = handler;
51 sig_data[sig] = data;
52
53 if (handler == SIG_DFL || handler == SIG_IGN) {
54 act.sa_handler = handler;
55 act.sa_flags = SA_RESTART;
56 } else {
57 act.sa_sigaction = sig_stub;
58 act.sa_flags = SA_SIGINFO | SA_RESTART;
59 }
60
61 (void) sigfillset(&act.sa_mask);
62
63 if ((status = sigaction(sig, &act, NULL)) == 0)
64 (void) se_signal_unblock(sig);
65
66 return (status);
67 }
68
69 int
se_signal_unblock(int sig)70 se_signal_unblock(int sig)
71 {
72 sigset_t set;
73
74 (void) sigemptyset(&set);
75 (void) sigaddset(&set, sig);
76
77 return (thr_sigsetmask(SIG_UNBLOCK, &set, NULL));
78 }
79
80 int
se_signal_blockall(void)81 se_signal_blockall(void)
82 {
83 sigset_t set;
84
85 (void) sigfillset(&set);
86 return (thr_sigsetmask(SIG_BLOCK, &set, NULL));
87 }
88
89 int
se_signal_unblockall(void)90 se_signal_unblockall(void)
91 {
92 sigset_t set;
93
94 (void) sigfillset(&set);
95 return (thr_sigsetmask(SIG_UNBLOCK, &set, NULL));
96 }
97