meillo@0: /* meillo@0: * Copyright (c) 2004 Gunnar Ritter meillo@0: * meillo@0: * This software is provided 'as-is', without any express or implied meillo@0: * warranty. In no event will the authors be held liable for any damages meillo@0: * arising from the use of this software. meillo@0: * meillo@0: * Permission is granted to anyone to use this software for any purpose, meillo@0: * including commercial applications, and to alter it and redistribute meillo@0: * it freely, subject to the following restrictions: meillo@0: * meillo@0: * 1. The origin of this software must not be misrepresented; you must not meillo@0: * claim that you wrote the original software. If you use this software meillo@0: * in a product, an acknowledgment in the product documentation would be meillo@0: * appreciated but is not required. meillo@0: * meillo@0: * 2. Altered source versions must be plainly marked as such, and must not be meillo@0: * misrepresented as being the original software. meillo@0: * meillo@0: * 3. This notice may not be removed or altered from any source distribution. meillo@0: */ meillo@0: /* Sccsid @(#)sigset.c 1.7 (gritter) 1/22/06 */ meillo@0: meillo@0: #if defined (__FreeBSD__) || defined (__dietlibc__) || defined (__NetBSD__) || \ meillo@0: defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__) meillo@0: #include meillo@0: #include "sigset.h" meillo@0: meillo@0: void (*sigset(int sig, void (*func)(int)))(int) meillo@0: { meillo@0: struct sigaction nact, oact; meillo@0: sigset_t nset, oset; meillo@0: meillo@0: if (sig <= 0) meillo@0: return SIG_ERR; meillo@0: sigemptyset(&nset); meillo@0: sigaddset(&nset, sig); meillo@0: if (sigprocmask(func==SIG_HOLD?SIG_BLOCK:SIG_UNBLOCK, &nset, &oset) < 0) meillo@0: return SIG_ERR; meillo@0: nact.sa_handler = func; meillo@0: nact.sa_flags = 0; meillo@0: if (sig == SIGCHLD && func == SIG_IGN) meillo@0: nact.sa_flags |= SA_NOCLDSTOP|SA_NOCLDWAIT; meillo@0: sigemptyset(&nact.sa_mask); meillo@0: sigaddset(&nact.sa_mask, sig); meillo@0: if (sigaction(sig, func==SIG_HOLD?(struct sigaction *)0:&nact, &oact) meillo@0: == -1) meillo@0: return SIG_ERR; meillo@0: if (sigismember(&oset, sig)) meillo@0: return SIG_HOLD; meillo@0: else meillo@0: return (oact.sa_handler); meillo@0: } meillo@0: #endif /* __FreeBSD__ || __dietlibc__ || __NetBSD__ || __OpenBSD__ || meillo@0: __DragonFly__ || __APPLE__ */