xref: /dragonfly/lib/libc/compat-43/sigcompat.c (revision 0fe46dc6)
1 /*
2  * Copyright (c) 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD: src/lib/libc/compat-43/sigcompat.c,v 1.7 2000/01/27 23:06:04 jasone Exp $
30  * $DragonFly: src/lib/libc/compat-43/sigcompat.c,v 1.3 2005/01/31 22:29:03 dillon Exp $
31  */
32 
33 #include "namespace.h"
34 #include <sys/param.h>
35 #include <signal.h>
36 #include "un-namespace.h"
37 #include "libc_private.h"
38 
39 int
40 sigvec(int signo, struct sigvec *sv, struct sigvec *osv)
41 {
42 	struct sigaction sa, osa;
43 	struct sigaction *sap, *osap;
44 	int ret;
45 
46 	if (sv != NULL) {
47 		sa.sa_handler = sv->sv_handler;
48 		sa.sa_flags = sv->sv_flags ^ SV_INTERRUPT;
49 		sigemptyset(&sa.sa_mask);
50 		sa.sa_mask.__bits[0] = sv->sv_mask;
51 		sap = &sa;
52 	} else
53 		sap = NULL;
54 	osap = osv != NULL ? &osa : NULL;
55 	ret = _sigaction(signo, sap, osap);
56 	if (ret == 0 && osv != NULL) {
57 		osv->sv_handler = osa.sa_handler;
58 		osv->sv_flags = osa.sa_flags ^ SV_INTERRUPT;
59 		osv->sv_mask = osa.sa_mask.__bits[0];
60 	}
61 	return (ret);
62 }
63 
64 int
65 sigsetmask(int mask)
66 {
67 	sigset_t set, oset;
68 	int n;
69 
70 	sigemptyset(&set);
71 	set.__bits[0] = mask;
72 	n = _sigprocmask(SIG_SETMASK, &set, &oset);
73 	if (n)
74 		return (n);
75 	return (oset.__bits[0]);
76 }
77 
78 int
79 sigblock(int mask)
80 {
81 	sigset_t set, oset;
82 	int n;
83 
84 	sigemptyset(&set);
85 	set.__bits[0] = mask;
86 	n = _sigprocmask(SIG_BLOCK, &set, &oset);
87 	if (n)
88 		return (n);
89 	return (oset.__bits[0]);
90 }
91 
92 int
93 sigpause(int mask)
94 {
95 	sigset_t set;
96 
97 	sigemptyset(&set);
98 	set.__bits[0] = mask;
99 	return (_sigsuspend(&set));
100 }
101