Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / util / posix_signals.c
blob90c250cf43f46488f27eae43d220c06688b17358
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* posix_signals 3
6 /* SUMMARY
7 /* POSIX signal handling compatibility
8 /* SYNOPSIS
9 /* #include <posix_signals.h>
11 /* int sigemptyset(m)
12 /* sigset_t *m;
14 /* int sigaddset(set, signum)
15 /* sigset_t *set;
16 /* int signum;
18 /* int sigprocmask(how, set, old)
19 /* int how;
20 /* sigset_t *set;
21 /* sigset_t *old;
23 /* int sigaction(sig, act, oact)
24 /* int sig;
25 /* struct sigaction *act;
26 /* struct sigaction *oact;
27 /* DESCRIPTION
28 /* These routines emulate the POSIX signal handling interface.
29 /* AUTHOR(S)
30 /* Pieter Schoenmakers
31 /* Eindhoven University of Technology
32 /* P.O. Box 513
33 /* 5600 MB Eindhoven
34 /* The Netherlands
35 /*--*/
37 /* System library. */
39 #include "sys_defs.h"
40 #include <signal.h>
41 #include <errno.h>
43 /* Utility library.*/
45 #include "posix_signals.h"
47 #ifdef MISSING_SIGSET_T
49 int sigemptyset(sigset_t *m)
51 return *m = 0;
54 int sigaddset(sigset_t *set, int signum)
56 *set |= sigmask(signum);
57 return 0;
60 int sigprocmask(int how, sigset_t *set, sigset_t *old)
62 int previous;
64 if (how == SIG_BLOCK)
65 previous = sigblock(*set);
66 else if (how == SIG_SETMASK)
67 previous = sigsetmask(*set);
68 else if (how == SIG_UNBLOCK) {
69 int m = sigblock(0);
71 previous = sigsetmask(m & ~*set);
72 } else {
73 errno = EINVAL;
74 return -1;
77 if (old)
78 *old = previous;
79 return 0;
82 #endif
84 #ifdef MISSING_SIGACTION
86 static struct sigaction actions[NSIG] = {};
88 static int sighandle(int signum)
90 if (signum == SIGCHLD) {
91 /* XXX If the child is just stopped, don't invoke the handler. */
93 actions[signum].sa_handler(signum);
96 int sigaction(int sig, struct sigaction *act, struct sigaction *oact)
98 static int initialized = 0;
100 if (!initialized) {
101 int i;
103 for (i = 0; i < NSIG; i++)
104 actions[i].sa_handler = SIG_DFL;
105 initialized = 1;
107 if (sig <= 0 || sig >= NSIG) {
108 errno = EINVAL;
109 return -1;
111 if (oact)
112 *oact = actions[sig];
115 struct sigvec mine = {
116 sighandle, act->sa_mask,
117 act->sa_flags & SA_RESTART ? SV_INTERRUPT : 0
120 if (sigvec(sig, &mine, NULL))
121 return -1;
124 actions[sig] = *act;
125 return 0;
128 #endif