Jacob has pointed out why SIGCHLD was blocked, so I've updated the
[sgt/putty] / unix / signal.c
1 #include <signal.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4
5 /*
6 * Calling signal() is a non-portable, as it varies in meaning between
7 * platforms and depending on feature macros, and has stupid semantics
8 * at least some of the time.
9 *
10 * This function provides the same interface as the libc function, but
11 * provides consistent semantics. It assumes POSIX semantics for
12 * sigaction() (so you might need to do some more work if you port to
13 * something ancient like SunOS 4)
14 */
15 void (*putty_signal(int sig, void (*func)(int)))(int) {
16 struct sigaction sa;
17 struct sigaction old;
18
19 sa.sa_handler = func;
20 if(sigemptyset(&sa.sa_mask) < 0)
21 return SIG_ERR;
22 sa.sa_flags = SA_RESTART;
23 if(sigaction(sig, &sa, &old) < 0)
24 return SIG_ERR;
25 return old.sa_handler;
26 }
27
28 void block_signal(int sig, int block_it)
29 {
30 sigset_t ss;
31
32 sigemptyset(&ss);
33 sigaddset(&ss, sig);
34 if(sigprocmask(block_it ? SIG_BLOCK : SIG_UNBLOCK, &ss, 0) < 0) {
35 perror("sigprocmask");
36 exit(1);
37 }
38 }
39
40 /*
41 Local Variables:
42 c-basic-offset:4
43 comment-column:40
44 End:
45 */