1 // SPDX-License-Identifier: GPL-2.0
3 #include "subcmd-util.h"
6 #define SIGCHAIN_MAX_SIGNALS 32
8 struct sigchain_signal
{
13 static struct sigchain_signal signals
[SIGCHAIN_MAX_SIGNALS
];
15 static void check_signum(int sig
)
17 if (sig
< 1 || sig
>= SIGCHAIN_MAX_SIGNALS
)
18 die("BUG: signal out of range: %d", sig
);
21 static int sigchain_push(int sig
, sigchain_fun f
)
23 struct sigchain_signal
*s
= signals
+ sig
;
26 ALLOC_GROW(s
->old
, s
->n
+ 1, s
->alloc
);
27 s
->old
[s
->n
] = signal(sig
, f
);
28 if (s
->old
[s
->n
] == SIG_ERR
)
34 int sigchain_pop(int sig
)
36 struct sigchain_signal
*s
= signals
+ sig
;
41 if (signal(sig
, s
->old
[s
->n
- 1]) == SIG_ERR
)
47 void sigchain_push_common(sigchain_fun f
)
49 sigchain_push(SIGINT
, f
);
50 sigchain_push(SIGHUP
, f
);
51 sigchain_push(SIGTERM
, f
);
52 sigchain_push(SIGQUIT
, f
);
53 sigchain_push(SIGPIPE
, f
);