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 #include <signal.h>
28 #include <thread.h>
29 #include <unistd.h>
30 #include <errno.h>
31
32 #include "sysevent_signal.h"
33
34 static se_signal_f *sig_handlers[NSIG];
35 static void *sig_data[NSIG];
36
37 static void
sig_stub(int sig,siginfo_t * sip,void * ucp)38 sig_stub(int sig, siginfo_t *sip, void *ucp)
39 {
40 sig_handlers[sig](sig, sip, (ucontext_t *)ucp, sig_data[sig]);
41 }
42
43 int
se_signal_sethandler(int sig,se_signal_f * handler,void * data)44 se_signal_sethandler(int sig, se_signal_f *handler, void *data)
45 {
46 struct sigaction act;
47 int status;
48
49 sig_handlers[sig] = handler;
50 sig_data[sig] = data;
51
52 if (handler == SE_SIG_DFL) {
53 act.sa_handler = SIG_DFL;
54 act.sa_flags = SA_RESTART;
55 } else if (handler == SE_SIG_IGN) {
56 act.sa_handler = SIG_IGN;
57 act.sa_flags = SA_RESTART;
58 } else {
59 act.sa_sigaction = sig_stub;
60 act.sa_flags = SA_SIGINFO | SA_RESTART;
61 }
62
63 (void) sigfillset(&act.sa_mask);
64
65 if ((status = sigaction(sig, &act, NULL)) == 0)
66 (void) se_signal_unblock(sig);
67
68 return (status);
69 }
70
71 int
se_signal_unblock(int sig)72 se_signal_unblock(int sig)
73 {
74 sigset_t set;
75
76 (void) sigemptyset(&set);
77 (void) sigaddset(&set, sig);
78
79 return (thr_sigsetmask(SIG_UNBLOCK, &set, NULL));
80 }
81
82 int
se_signal_blockall(void)83 se_signal_blockall(void)
84 {
85 sigset_t set;
86
87 (void) sigfillset(&set);
88 return (thr_sigsetmask(SIG_BLOCK, &set, NULL));
89 }
90
91 int
se_signal_unblockall(void)92 se_signal_unblockall(void)
93 {
94 sigset_t set;
95
96 (void) sigfillset(&set);
97 return (thr_sigsetmask(SIG_UNBLOCK, &set, NULL));
98 }
99