xref: /titanic_41/usr/src/cmd/ssh/libopenbsd-compat/common/sigact.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*	$OpenBSD: sigaction.c,v 1.3 1999/06/27 08:14:21 millert Exp $	*/
2*7c478bd9Sstevel@tonic-gate 
3*7c478bd9Sstevel@tonic-gate /****************************************************************************
4*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1998 Free Software Foundation, Inc.                        *
5*7c478bd9Sstevel@tonic-gate  *                                                                          *
6*7c478bd9Sstevel@tonic-gate  * Permission is hereby granted, free of charge, to any person obtaining a  *
7*7c478bd9Sstevel@tonic-gate  * copy of this software and associated documentation files (the            *
8*7c478bd9Sstevel@tonic-gate  * "Software"), to deal in the Software without restriction, including      *
9*7c478bd9Sstevel@tonic-gate  * without limitation the rights to use, copy, modify, merge, publish,      *
10*7c478bd9Sstevel@tonic-gate  * distribute, distribute with modifications, sublicense, and/or sell       *
11*7c478bd9Sstevel@tonic-gate  * copies of the Software, and to permit persons to whom the Software is    *
12*7c478bd9Sstevel@tonic-gate  * furnished to do so, subject to the following conditions:                 *
13*7c478bd9Sstevel@tonic-gate  *                                                                          *
14*7c478bd9Sstevel@tonic-gate  * The above copyright notice and this permission notice shall be included  *
15*7c478bd9Sstevel@tonic-gate  * in all copies or substantial portions of the Software.                   *
16*7c478bd9Sstevel@tonic-gate  *                                                                          *
17*7c478bd9Sstevel@tonic-gate  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18*7c478bd9Sstevel@tonic-gate  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19*7c478bd9Sstevel@tonic-gate  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20*7c478bd9Sstevel@tonic-gate  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21*7c478bd9Sstevel@tonic-gate  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22*7c478bd9Sstevel@tonic-gate  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23*7c478bd9Sstevel@tonic-gate  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24*7c478bd9Sstevel@tonic-gate  *                                                                          *
25*7c478bd9Sstevel@tonic-gate  * Except as contained in this notice, the name(s) of the above copyright   *
26*7c478bd9Sstevel@tonic-gate  * holders shall not be used in advertising or otherwise to promote the     *
27*7c478bd9Sstevel@tonic-gate  * sale, use or other dealings in this Software without prior written       *
28*7c478bd9Sstevel@tonic-gate  * authorization.                                                           *
29*7c478bd9Sstevel@tonic-gate  ****************************************************************************/
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate /****************************************************************************
32*7c478bd9Sstevel@tonic-gate  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
33*7c478bd9Sstevel@tonic-gate  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
34*7c478bd9Sstevel@tonic-gate  ****************************************************************************/
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #include "includes.h"
37*7c478bd9Sstevel@tonic-gate #include <signal.h>
38*7c478bd9Sstevel@tonic-gate #include "sigact.h"
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate /* This file provides sigaction() emulation using sigvec() */
41*7c478bd9Sstevel@tonic-gate /* Use only if this is non POSIX system */
42*7c478bd9Sstevel@tonic-gate 
43*7c478bd9Sstevel@tonic-gate #if !HAVE_SIGACTION && HAVE_SIGVEC
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate int
sigaction(int sig,struct sigaction * sigact,struct sigaction * osigact)46*7c478bd9Sstevel@tonic-gate sigaction(int sig, struct sigaction *sigact, struct sigaction *osigact)
47*7c478bd9Sstevel@tonic-gate {
48*7c478bd9Sstevel@tonic-gate 	return sigvec(sig, &(sigact->sv), &(osigact->sv));
49*7c478bd9Sstevel@tonic-gate }
50*7c478bd9Sstevel@tonic-gate 
51*7c478bd9Sstevel@tonic-gate int
sigemptyset(sigset_t * mask)52*7c478bd9Sstevel@tonic-gate sigemptyset (sigset_t * mask)
53*7c478bd9Sstevel@tonic-gate {
54*7c478bd9Sstevel@tonic-gate 	*mask = 0;
55*7c478bd9Sstevel@tonic-gate 	return 0;
56*7c478bd9Sstevel@tonic-gate }
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate int
sigprocmask(int mode,sigset_t * mask,sigset_t * omask)59*7c478bd9Sstevel@tonic-gate sigprocmask (int mode, sigset_t * mask, sigset_t * omask)
60*7c478bd9Sstevel@tonic-gate {
61*7c478bd9Sstevel@tonic-gate 	sigset_t current = sigsetmask(0);
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate 	if (omask) *omask = current;
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate 	if (mode==SIG_BLOCK)
66*7c478bd9Sstevel@tonic-gate 		current |= *mask;
67*7c478bd9Sstevel@tonic-gate 	else if (mode==SIG_UNBLOCK)
68*7c478bd9Sstevel@tonic-gate 		current &= ~*mask;
69*7c478bd9Sstevel@tonic-gate 	else if (mode==SIG_SETMASK)
70*7c478bd9Sstevel@tonic-gate 	current = *mask;
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 	sigsetmask(current);
73*7c478bd9Sstevel@tonic-gate 	return 0;
74*7c478bd9Sstevel@tonic-gate }
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate int
sigsuspend(sigset_t * mask)77*7c478bd9Sstevel@tonic-gate sigsuspend (sigset_t * mask)
78*7c478bd9Sstevel@tonic-gate {
79*7c478bd9Sstevel@tonic-gate 	return sigpause(*mask);
80*7c478bd9Sstevel@tonic-gate }
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate int
sigdelset(sigset_t * mask,int sig)83*7c478bd9Sstevel@tonic-gate sigdelset (sigset_t * mask, int sig)
84*7c478bd9Sstevel@tonic-gate {
85*7c478bd9Sstevel@tonic-gate 	*mask &= ~sigmask(sig);
86*7c478bd9Sstevel@tonic-gate 	return 0;
87*7c478bd9Sstevel@tonic-gate }
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate int
sigaddset(sigset_t * mask,int sig)90*7c478bd9Sstevel@tonic-gate sigaddset (sigset_t * mask, int sig)
91*7c478bd9Sstevel@tonic-gate {
92*7c478bd9Sstevel@tonic-gate 	*mask |= sigmask(sig);
93*7c478bd9Sstevel@tonic-gate 	return 0;
94*7c478bd9Sstevel@tonic-gate }
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate int
sigismember(sigset_t * mask,int sig)97*7c478bd9Sstevel@tonic-gate sigismember (sigset_t * mask, int sig)
98*7c478bd9Sstevel@tonic-gate {
99*7c478bd9Sstevel@tonic-gate 	return (*mask & sigmask(sig)) != 0;
100*7c478bd9Sstevel@tonic-gate }
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate #endif
103*7c478bd9Sstevel@tonic-gate 
104*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
105