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 * 4. 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 30 #if defined(LIBC_SCCS) && !defined(lint) 31 static char sccsid[] = "@(#)sigcompat.c 8.1 (Berkeley) 6/2/93"; 32 #endif /* LIBC_SCCS and not lint */ 33 #include <sys/cdefs.h> 34 __FBSDID("$FreeBSD$"); 35 36 #include "namespace.h" 37 #include <sys/param.h> 38 #include <signal.h> 39 #include "un-namespace.h" 40 #include "libc_private.h" 41 42 int 43 sigvec(signo, sv, osv) 44 int signo; 45 struct sigvec *sv, *osv; 46 { 47 struct sigaction sa, osa; 48 struct sigaction *sap, *osap; 49 int ret; 50 51 if (sv != NULL) { 52 sa.sa_handler = sv->sv_handler; 53 sa.sa_flags = sv->sv_flags ^ SV_INTERRUPT; 54 sigemptyset(&sa.sa_mask); 55 sa.sa_mask.__bits[0] = sv->sv_mask; 56 sap = &sa; 57 } else 58 sap = NULL; 59 osap = osv != NULL ? &osa : NULL; 60 ret = _sigaction(signo, sap, osap); 61 if (ret == 0 && osv != NULL) { 62 osv->sv_handler = osa.sa_handler; 63 osv->sv_flags = osa.sa_flags ^ SV_INTERRUPT; 64 osv->sv_mask = osa.sa_mask.__bits[0]; 65 } 66 return (ret); 67 } 68 69 int 70 sigsetmask(mask) 71 int mask; 72 { 73 sigset_t set, oset; 74 int n; 75 76 sigemptyset(&set); 77 set.__bits[0] = mask; 78 n = _sigprocmask(SIG_SETMASK, &set, &oset); 79 if (n) 80 return (n); 81 return (oset.__bits[0]); 82 } 83 84 int 85 sigblock(mask) 86 int mask; 87 { 88 sigset_t set, oset; 89 int n; 90 91 sigemptyset(&set); 92 set.__bits[0] = mask; 93 n = _sigprocmask(SIG_BLOCK, &set, &oset); 94 if (n) 95 return (n); 96 return (oset.__bits[0]); 97 } 98 99 int 100 sigpause(mask) 101 int mask; 102 { 103 sigset_t set; 104 105 sigemptyset(&set); 106 set.__bits[0] = mask; 107 return (_sigsuspend(&set)); 108 } 109