1157016Sdes/* $OpenBSD: sigaction.c,v 1.4 2001/01/22 18:01:48 millert Exp $ */ 2126274Sdes 398937Sdes/**************************************************************************** 4157016Sdes * Copyright (c) 1998,2000 Free Software Foundation, Inc. * 598937Sdes * * 698937Sdes * Permission is hereby granted, free of charge, to any person obtaining a * 798937Sdes * copy of this software and associated documentation files (the * 898937Sdes * "Software"), to deal in the Software without restriction, including * 998937Sdes * without limitation the rights to use, copy, modify, merge, publish, * 1098937Sdes * distribute, distribute with modifications, sublicense, and/or sell * 1198937Sdes * copies of the Software, and to permit persons to whom the Software is * 1298937Sdes * furnished to do so, subject to the following conditions: * 1398937Sdes * * 1498937Sdes * The above copyright notice and this permission notice shall be included * 1598937Sdes * in all copies or substantial portions of the Software. * 1698937Sdes * * 1798937Sdes * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 1898937Sdes * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 1998937Sdes * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 2098937Sdes * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 2198937Sdes * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 2298937Sdes * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 2398937Sdes * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 2498937Sdes * * 2598937Sdes * Except as contained in this notice, the name(s) of the above copyright * 2698937Sdes * holders shall not be used in advertising or otherwise to promote the * 2798937Sdes * sale, use or other dealings in this Software without prior written * 2898937Sdes * authorization. * 2998937Sdes ****************************************************************************/ 3098937Sdes 3198937Sdes/**************************************************************************** 3298937Sdes * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * 3398937Sdes * and: Eric S. Raymond <esr@snark.thyrsus.com> * 3498937Sdes ****************************************************************************/ 3598937Sdes 36157016Sdes/* OPENBSD ORIGINAL: lib/libcurses/base/sigaction.c */ 37157016Sdes 38106121Sdes#include "includes.h" 39181111Sdes#include <errno.h> 4098937Sdes#include <signal.h> 4198937Sdes#include "sigact.h" 4298937Sdes 4398937Sdes/* This file provides sigaction() emulation using sigvec() */ 4498937Sdes/* Use only if this is non POSIX system */ 4598937Sdes 4698937Sdes#if !HAVE_SIGACTION && HAVE_SIGVEC 4798937Sdes 4898937Sdesint 4998937Sdessigaction(int sig, struct sigaction *sigact, struct sigaction *osigact) 5098937Sdes{ 51181111Sdes return sigvec(sig, sigact ? &sigact->sv : NULL, 52181111Sdes osigact ? &osigact->sv : NULL); 5398937Sdes} 5498937Sdes 5598937Sdesint 56181111Sdessigemptyset (sigset_t *mask) 5798937Sdes{ 58181111Sdes if (!mask) { 59181111Sdes errno = EINVAL; 60181111Sdes return -1; 61181111Sdes } 6298937Sdes *mask = 0; 6398937Sdes return 0; 6498937Sdes} 6598937Sdes 6698937Sdesint 67181111Sdessigprocmask (int mode, sigset_t *mask, sigset_t *omask) 6898937Sdes{ 6998937Sdes sigset_t current = sigsetmask(0); 7098937Sdes 71181111Sdes if (!mask) { 72181111Sdes errno = EINVAL; 73181111Sdes return -1; 74181111Sdes } 7598937Sdes 76181111Sdes if (omask) 77181111Sdes *omask = current; 78181111Sdes 79181111Sdes if (mode == SIG_BLOCK) 8098937Sdes current |= *mask; 81181111Sdes else if (mode == SIG_UNBLOCK) 8298937Sdes current &= ~*mask; 83181111Sdes else if (mode == SIG_SETMASK) 8498937Sdes current = *mask; 8598937Sdes 8698937Sdes sigsetmask(current); 8798937Sdes return 0; 8898937Sdes} 8998937Sdes 9098937Sdesint 91181111Sdessigsuspend (sigset_t *mask) 9298937Sdes{ 93181111Sdes if (!mask) { 94181111Sdes errno = EINVAL; 95181111Sdes return -1; 96181111Sdes } 9798937Sdes return sigpause(*mask); 9898937Sdes} 9998937Sdes 10098937Sdesint 101181111Sdessigdelset (sigset_t *mask, int sig) 10298937Sdes{ 103181111Sdes if (!mask) { 104181111Sdes errno = EINVAL; 105181111Sdes return -1; 106181111Sdes } 10798937Sdes *mask &= ~sigmask(sig); 10898937Sdes return 0; 10998937Sdes} 11098937Sdes 11198937Sdesint 112181111Sdessigaddset (sigset_t *mask, int sig) 11398937Sdes{ 114181111Sdes if (!mask) { 115181111Sdes errno = EINVAL; 116181111Sdes return -1; 117181111Sdes } 11898937Sdes *mask |= sigmask(sig); 11998937Sdes return 0; 12098937Sdes} 12198937Sdes 12298937Sdesint 123181111Sdessigismember (sigset_t *mask, int sig) 12498937Sdes{ 125181111Sdes if (!mask) { 126181111Sdes errno = EINVAL; 127181111Sdes return -1; 128181111Sdes } 12998937Sdes return (*mask & sigmask(sig)) != 0; 13098937Sdes} 13198937Sdes 13298937Sdes#endif 133