1 /* @(#)sigset.h 1.11 11/09/16 Copyright 1997-2011 J. Schilling */ 2 /* 3 * Signal set abstraction for BSD/SVR4 signals 4 * 5 * Copyright (c) 1997-2011 J. Schilling 6 */ 7 /* 8 * The contents of this file are subject to the terms of the 9 * Common Development and Distribution License, Version 1.0 only 10 * (the "License"). You may not use this file except in compliance 11 * with the License. 12 * 13 * See the file CDDL.Schily.txt in this distribution for details. 14 * A copy of the CDDL is also available via the Internet at 15 * http://www.opensource.org/licenses/cddl1.txt 16 * 17 * When distributing Covered Code, include this CDDL HEADER in each 18 * file and include the License file CDDL.Schily.txt from this distribution. 19 */ 20 21 #ifndef _SCHILY_SIGSET_H 22 #define _SCHILY_SIGSET_H 23 24 #ifndef _SCHILY_MCONFIG_H 25 #include <schily/mconfig.h> 26 #endif 27 28 #ifdef HAVE_SIGSET 29 /* 30 * Try to by default use the function that sets up signal handlers in a way 31 * that does not reset the handler after it has been called. 32 */ 33 #define signal sigset 34 #endif 35 36 #ifdef HAVE_SIGPROCMASK 37 #define blocked_sigs(a) { \ 38 sigset_t __new; \ 39 \ 40 sigemptyset(&__new); \ 41 sigprocmask(SIG_BLOCK, &__new, &a);\ 42 } 43 #define block_sigs(a) { \ 44 sigset_t __new; \ 45 \ 46 sigfillset(&__new); \ 47 sigprocmask(SIG_BLOCK, &__new, &a);\ 48 } 49 #define block_sig(s) { \ 50 sigset_t __new; \ 51 \ 52 sigemptyset(&__new); \ 53 sigaddset(&__new, (s)); \ 54 sigprocmask(SIG_BLOCK, &__new, NULL);\ 55 } 56 #define unblock_sig(s) { \ 57 sigset_t __new; \ 58 \ 59 sigemptyset(&__new); \ 60 sigaddset(&__new, (s)); \ 61 sigprocmask(SIG_UNBLOCK, &__new, NULL);\ 62 } 63 #define restore_sigs(a) sigprocmask(SIG_SETMASK, &a, 0); 64 65 #else /* !HAVE_SIGPROCMASK */ 66 #if defined(HAVE_SIGBLOCK) && defined(HAVE_SIGSETMASK) 67 68 #define sigset_t int 69 #define block_sigs(a) a = sigblock(0xFFFFFFFF) 70 #define restore_sigs(a) sigsetmask(a); 71 #define blocked_sigs(a) { \ 72 int __old; \ 73 \ 74 block_sigs(__old); \ 75 a = __old; \ 76 sigsetmask(__old); \ 77 } 78 #define block_sig(s) { \ 79 int __old, __new; \ 80 \ 81 block_sigs(__old); \ 82 __new = sigmask(s); \ 83 __new = __old | __new; \ 84 sigsetmask(__new); \ 85 } 86 #define unblock_sig(s) { \ 87 int __old, __new; \ 88 \ 89 block_sigs(__old); \ 90 __new = sigmask(s); \ 91 __new = __old & ~__new; \ 92 sigsetmask(__new); \ 93 } 94 #else /* ! defined(HAVE_SIGBLOCK) && defined(HAVE_SIGSETMASK) */ 95 96 #define sigset_t int 97 #define blocked_sigs(a) 98 #define block_sigs(a) 99 #define block_sig(a) 100 #define restore_sigs(a) 101 #define unblock_sig(s) 102 #endif /* ! defined(HAVE_SIGBLOCK) && defined(HAVE_SIGSETMASK) */ 103 #endif /* HAVE_SIGPROCMASK */ 104 105 #endif /* _SCHILY_SIGSET_H */ 106