annotate sigset.c @ 0:1493bea5ac22 0.1

Initial version of the standalone heirloom-ed
author markus schnalke <meillo@marmaro.de>
date Mon, 05 Sep 2011 16:31:35 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
1 /*
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
2 * Copyright (c) 2004 Gunnar Ritter
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
3 *
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
4 * This software is provided 'as-is', without any express or implied
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
5 * warranty. In no event will the authors be held liable for any damages
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
6 * arising from the use of this software.
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
7 *
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
8 * Permission is granted to anyone to use this software for any purpose,
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
9 * including commercial applications, and to alter it and redistribute
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
10 * it freely, subject to the following restrictions:
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
11 *
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
12 * 1. The origin of this software must not be misrepresented; you must not
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
13 * claim that you wrote the original software. If you use this software
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
14 * in a product, an acknowledgment in the product documentation would be
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
15 * appreciated but is not required.
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
16 *
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
17 * 2. Altered source versions must be plainly marked as such, and must not be
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
18 * misrepresented as being the original software.
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
19 *
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
20 * 3. This notice may not be removed or altered from any source distribution.
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
21 */
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
22 /* Sccsid @(#)sigset.c 1.7 (gritter) 1/22/06 */
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
23
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
24 #if defined (__FreeBSD__) || defined (__dietlibc__) || defined (__NetBSD__) || \
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
25 defined (__OpenBSD__) || defined (__DragonFly__) || defined (__APPLE__)
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
26 #include <signal.h>
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
27 #include "sigset.h"
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
28
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
29 void (*sigset(int sig, void (*func)(int)))(int)
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
30 {
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
31 struct sigaction nact, oact;
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
32 sigset_t nset, oset;
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
33
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
34 if (sig <= 0)
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
35 return SIG_ERR;
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
36 sigemptyset(&nset);
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
37 sigaddset(&nset, sig);
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
38 if (sigprocmask(func==SIG_HOLD?SIG_BLOCK:SIG_UNBLOCK, &nset, &oset) < 0)
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
39 return SIG_ERR;
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
40 nact.sa_handler = func;
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
41 nact.sa_flags = 0;
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
42 if (sig == SIGCHLD && func == SIG_IGN)
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
43 nact.sa_flags |= SA_NOCLDSTOP|SA_NOCLDWAIT;
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
44 sigemptyset(&nact.sa_mask);
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
45 sigaddset(&nact.sa_mask, sig);
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
46 if (sigaction(sig, func==SIG_HOLD?(struct sigaction *)0:&nact, &oact)
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
47 == -1)
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
48 return SIG_ERR;
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
49 if (sigismember(&oset, sig))
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
50 return SIG_HOLD;
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
51 else
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
52 return (oact.sa_handler);
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
53 }
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
54 #endif /* __FreeBSD__ || __dietlibc__ || __NetBSD__ || __OpenBSD__ ||
1493bea5ac22 Initial version of the standalone heirloom-ed
markus schnalke <meillo@marmaro.de>
parents:
diff changeset
55 __DragonFly__ || __APPLE__ */