xref: /netbsd-src/lib/libc/compat-43/sigcompat.c (revision 5e4c038a45edbc7d63b7c2daa76e29f88b64a4e3)
1 /*	$NetBSD: sigcompat.c,v 1.10 1998/09/27 13:21:28 christos Exp $	*/
2 
3 /*
4  * Copyright (c) 1989, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by the University of
18  *	California, Berkeley and its contributors.
19  * 4. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #include <sys/cdefs.h>
37 #if defined(LIBC_SCCS) && !defined(lint)
38 #if 0
39 static char sccsid[] = "@(#)sigcompat.c	8.1 (Berkeley) 6/2/93";
40 #else
41 __RCSID("$NetBSD: sigcompat.c,v 1.10 1998/09/27 13:21:28 christos Exp $");
42 #endif
43 #endif /* LIBC_SCCS and not lint */
44 
45 #include <sys/param.h>
46 #include <signal.h>
47 
48 static __inline void sv2sa __P((struct sigaction *, const struct sigvec *));
49 static __inline void sa2sv __P((struct sigvec *, const struct sigaction *));
50 
51 static __inline void
52 sv2sa(sa, sv)
53 	struct sigaction *sa;
54 	const struct sigvec *sv;
55 {
56 	sigemptyset(&sa->sa_mask);
57 	sa->sa_mask.__bits[0] = sv->sv_mask;
58 	sa->sa_handler = sv->sv_handler;
59 	sa->sa_flags = sv->sv_flags ^ SV_INTERRUPT; /* !SA_INTERRUPT */
60 }
61 
62 static __inline void
63 sa2sv(sv, sa)
64 	struct sigvec *sv;
65 	const struct sigaction *sa;
66 {
67 	sv->sv_mask = sa->sa_mask.__bits[0];
68 	sv->sv_handler = sa->sa_handler;
69 	sv->sv_flags = sa->sa_flags ^ SV_INTERRUPT; /* !SA_INTERRUPT */
70 }
71 
72 int
73 sigvec(signo, nsv, osv)
74 	int signo;
75 	struct sigvec *nsv, *osv;
76 {
77 	int ret;
78 	struct sigaction osa, nsa;
79 
80 	if (nsv)
81 		sv2sa(&nsa, nsv);
82 
83 	ret = sigaction(signo, nsv ? &nsa : NULL, osv ? &osa : NULL);
84 
85 	if (ret == 0 && osv)
86 		sa2sv(osv, &osa);
87 
88 	return (ret);
89 }
90 
91 int
92 sigsetmask(mask)
93 	int mask;
94 {
95 	sigset_t nmask, omask;
96 	int n;
97 
98 	sigemptyset(&nmask);
99 	nmask.__bits[0] = mask;
100 
101 	n = sigprocmask(SIG_SETMASK, &nmask, &omask);
102 	if (n)
103 		return (n);
104 	return (omask.__bits[0]);
105 }
106 
107 int
108 sigblock(mask)
109 	int mask;
110 {
111 	sigset_t nmask, omask;
112 	int n;
113 
114 	sigemptyset(&nmask);
115 	nmask.__bits[0] = mask;
116 
117 	n = sigprocmask(SIG_BLOCK, &nmask, &omask);
118 	if (n)
119 		return (n);
120 	return (omask.__bits[0]);
121 }
122 
123 int
124 sigpause(mask)
125 	int mask;
126 {
127 	sigset_t nmask;
128 
129 	sigemptyset(&nmask);
130 	nmask.__bits[0] = mask;
131 	return (sigsuspend(&nmask));
132 }
133