2017-11-20 19:49:47 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
1994-05-27 05:00:24 +00:00
|
|
|
* Copyright (c) 1989, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2017-02-28 23:42:47 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-27 05:00:24 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
|
|
|
static char sccsid[] = "@(#)sigcompat.c 8.1 (Berkeley) 6/2/93";
|
|
|
|
#endif /* LIBC_SCCS and not lint */
|
2002-03-22 21:53:29 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-01-24 13:01:12 +00:00
|
|
|
#include "namespace.h"
|
1994-05-27 05:00:24 +00:00
|
|
|
#include <sys/param.h>
|
2010-07-12 10:14:24 +00:00
|
|
|
#include <errno.h>
|
1994-05-27 05:00:24 +00:00
|
|
|
#include <signal.h>
|
2009-11-26 13:49:37 +00:00
|
|
|
#include <string.h>
|
2001-01-24 13:01:12 +00:00
|
|
|
#include "un-namespace.h"
|
|
|
|
#include "libc_private.h"
|
1994-05-27 05:00:24 +00:00
|
|
|
|
1996-07-12 18:57:58 +00:00
|
|
|
int
|
2015-09-20 20:53:24 +00:00
|
|
|
sigvec(int signo, struct sigvec *sv, struct sigvec *osv)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
1999-10-09 00:25:29 +00:00
|
|
|
struct sigaction sa, osa;
|
|
|
|
struct sigaction *sap, *osap;
|
1994-05-27 05:00:24 +00:00
|
|
|
int ret;
|
|
|
|
|
1999-10-09 00:25:29 +00:00
|
|
|
if (sv != NULL) {
|
|
|
|
sa.sa_handler = sv->sv_handler;
|
|
|
|
sa.sa_flags = sv->sv_flags ^ SV_INTERRUPT;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sa.sa_mask.__bits[0] = sv->sv_mask;
|
|
|
|
sap = &sa;
|
|
|
|
} else
|
|
|
|
sap = NULL;
|
|
|
|
osap = osv != NULL ? &osa : NULL;
|
2015-08-29 14:25:01 +00:00
|
|
|
ret = __libc_sigaction(signo, sap, osap);
|
1999-10-09 00:25:29 +00:00
|
|
|
if (ret == 0 && osv != NULL) {
|
|
|
|
osv->sv_handler = osa.sa_handler;
|
|
|
|
osv->sv_flags = osa.sa_flags ^ SV_INTERRUPT;
|
|
|
|
osv->sv_mask = osa.sa_mask.__bits[0];
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
1996-07-12 18:57:58 +00:00
|
|
|
int
|
2015-09-20 20:53:24 +00:00
|
|
|
sigsetmask(int mask)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
1999-09-29 15:18:46 +00:00
|
|
|
sigset_t set, oset;
|
1999-10-02 19:24:24 +00:00
|
|
|
int n;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
1999-09-29 15:18:46 +00:00
|
|
|
sigemptyset(&set);
|
|
|
|
set.__bits[0] = mask;
|
2015-08-29 14:25:01 +00:00
|
|
|
n = __libc_sigprocmask(SIG_SETMASK, &set, &oset);
|
1999-10-02 19:24:24 +00:00
|
|
|
if (n)
|
|
|
|
return (n);
|
1999-09-29 15:18:46 +00:00
|
|
|
return (oset.__bits[0]);
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
1996-07-12 18:57:58 +00:00
|
|
|
int
|
2015-09-20 20:53:24 +00:00
|
|
|
sigblock(int mask)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
1999-09-29 15:18:46 +00:00
|
|
|
sigset_t set, oset;
|
1999-10-02 19:24:24 +00:00
|
|
|
int n;
|
1999-09-29 15:18:46 +00:00
|
|
|
|
|
|
|
sigemptyset(&set);
|
|
|
|
set.__bits[0] = mask;
|
2015-08-29 14:25:01 +00:00
|
|
|
n = __libc_sigprocmask(SIG_BLOCK, &set, &oset);
|
1999-10-02 19:24:24 +00:00
|
|
|
if (n)
|
|
|
|
return (n);
|
1999-09-29 15:18:46 +00:00
|
|
|
return (oset.__bits[0]);
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
1996-07-12 18:57:58 +00:00
|
|
|
int
|
2009-11-26 13:49:37 +00:00
|
|
|
sigpause(int mask)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
1999-09-29 15:18:46 +00:00
|
|
|
sigset_t set;
|
|
|
|
|
|
|
|
sigemptyset(&set);
|
|
|
|
set.__bits[0] = mask;
|
2015-08-29 14:25:01 +00:00
|
|
|
return (__libc_sigsuspend(&set));
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
2009-11-26 13:49:37 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
xsi_sigpause(int sig)
|
|
|
|
{
|
|
|
|
sigset_t set;
|
|
|
|
|
2015-08-29 14:25:01 +00:00
|
|
|
if (__libc_sigprocmask(SIG_BLOCK, NULL, &set) == -1)
|
2010-07-22 09:14:18 +00:00
|
|
|
return (-1);
|
|
|
|
if (sigdelset(&set, sig) == -1)
|
2010-07-12 10:14:24 +00:00
|
|
|
return (-1);
|
2015-08-29 14:25:01 +00:00
|
|
|
return (__libc_sigsuspend(&set));
|
2009-11-26 13:49:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sighold(int sig)
|
|
|
|
{
|
|
|
|
sigset_t set;
|
|
|
|
|
|
|
|
sigemptyset(&set);
|
2010-07-22 09:14:18 +00:00
|
|
|
if (sigaddset(&set, sig) == -1)
|
|
|
|
return (-1);
|
2015-08-29 14:25:01 +00:00
|
|
|
return (__libc_sigprocmask(SIG_BLOCK, &set, NULL));
|
2009-11-26 13:49:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sigignore(int sig)
|
|
|
|
{
|
|
|
|
struct sigaction sa;
|
|
|
|
|
|
|
|
bzero(&sa, sizeof(sa));
|
|
|
|
sa.sa_handler = SIG_IGN;
|
2015-08-29 14:25:01 +00:00
|
|
|
return (__libc_sigaction(sig, &sa, NULL));
|
2009-11-26 13:49:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sigrelse(int sig)
|
|
|
|
{
|
|
|
|
sigset_t set;
|
|
|
|
|
|
|
|
sigemptyset(&set);
|
2010-07-22 09:14:18 +00:00
|
|
|
if (sigaddset(&set, sig) == -1)
|
|
|
|
return (-1);
|
2015-08-29 14:25:01 +00:00
|
|
|
return (__libc_sigprocmask(SIG_UNBLOCK, &set, NULL));
|
2009-11-26 13:49:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
(*sigset(int sig, void (*disp)(int)))(int)
|
|
|
|
{
|
|
|
|
sigset_t set, pset;
|
|
|
|
struct sigaction sa, psa;
|
|
|
|
|
|
|
|
sigemptyset(&set);
|
2010-07-22 09:14:18 +00:00
|
|
|
if (sigaddset(&set, sig) == -1)
|
|
|
|
return (SIG_ERR);
|
2015-08-29 14:25:01 +00:00
|
|
|
if (__libc_sigprocmask(SIG_BLOCK, NULL, &pset) == -1)
|
2009-11-26 13:49:37 +00:00
|
|
|
return (SIG_ERR);
|
|
|
|
if ((__sighandler_t *)disp == SIG_HOLD) {
|
2015-08-29 14:25:01 +00:00
|
|
|
if (__libc_sigprocmask(SIG_BLOCK, &set, &pset) == -1)
|
2009-11-26 13:49:37 +00:00
|
|
|
return (SIG_ERR);
|
|
|
|
if (sigismember(&pset, sig))
|
|
|
|
return (SIG_HOLD);
|
|
|
|
else {
|
2015-08-29 14:25:01 +00:00
|
|
|
if (__libc_sigaction(sig, NULL, &psa) == -1)
|
2009-11-26 13:49:37 +00:00
|
|
|
return (SIG_ERR);
|
|
|
|
return (psa.sa_handler);
|
|
|
|
}
|
|
|
|
} else {
|
2015-08-29 14:25:01 +00:00
|
|
|
if (__libc_sigprocmask(SIG_UNBLOCK, &set, &pset) == -1)
|
2009-11-26 13:49:37 +00:00
|
|
|
return (SIG_ERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
bzero(&sa, sizeof(sa));
|
|
|
|
sa.sa_handler = disp;
|
2015-08-29 14:25:01 +00:00
|
|
|
if (__libc_sigaction(sig, &sa, &psa) == -1)
|
2009-11-26 13:49:37 +00:00
|
|
|
return (SIG_ERR);
|
|
|
|
if (sigismember(&pset, sig))
|
|
|
|
return (SIG_HOLD);
|
|
|
|
else
|
|
|
|
return (psa.sa_handler);
|
|
|
|
}
|