4 #define SIGCHAIN_MAX_SIGNALS 32
6 struct sigchain_signal
{
11 static struct sigchain_signal signals
[SIGCHAIN_MAX_SIGNALS
];
13 static void check_signum(int sig
)
15 if (sig
< 1 || sig
>= SIGCHAIN_MAX_SIGNALS
)
16 die("BUG: signal out of range: %d", sig
);
19 int sigchain_push(int sig
, sigchain_fun f
)
21 struct sigchain_signal
*s
= signals
+ sig
;
24 ALLOC_GROW(s
->old
, s
->n
+ 1, s
->alloc
);
25 s
->old
[s
->n
] = signal(sig
, f
);
26 if (s
->old
[s
->n
] == SIG_ERR
)
32 int sigchain_pop(int sig
)
34 struct sigchain_signal
*s
= signals
+ sig
;
39 if (signal(sig
, s
->old
[s
->n
- 1]) == SIG_ERR
)
45 void sigchain_push_common(sigchain_fun f
)
47 sigchain_push(SIGINT
, f
);
48 sigchain_push(SIGHUP
, f
);
49 sigchain_push(SIGTERM
, f
);
50 sigchain_push(SIGQUIT
, f
);
51 sigchain_push(SIGPIPE
, f
);
54 void sigchain_pop_common(void)
56 sigchain_pop(SIGPIPE
);
57 sigchain_pop(SIGQUIT
);
58 sigchain_pop(SIGTERM
);