1 #include "git-compat-util.h"
5 #define SIGCHAIN_MAX_SIGNALS 32
7 struct sigchain_signal
{
12 static struct sigchain_signal signals
[SIGCHAIN_MAX_SIGNALS
];
14 static void check_signum(int sig
)
16 if (sig
< 1 || sig
>= SIGCHAIN_MAX_SIGNALS
)
17 BUG("signal out of range: %d", sig
);
20 int sigchain_push(int sig
, sigchain_fun f
)
22 struct sigchain_signal
*s
= signals
+ sig
;
25 ALLOC_GROW(s
->old
, s
->n
+ 1, s
->alloc
);
26 s
->old
[s
->n
] = signal(sig
, f
);
27 if (s
->old
[s
->n
] == SIG_ERR
)
33 int sigchain_pop(int sig
)
35 struct sigchain_signal
*s
= signals
+ sig
;
40 if (signal(sig
, s
->old
[s
->n
- 1]) == SIG_ERR
)
46 void sigchain_push_common(sigchain_fun f
)
48 sigchain_push(SIGINT
, f
);
49 sigchain_push(SIGHUP
, f
);
50 sigchain_push(SIGTERM
, f
);
51 sigchain_push(SIGQUIT
, f
);
52 sigchain_push(SIGPIPE
, f
);
55 void sigchain_pop_common(void)
57 sigchain_pop(SIGPIPE
);
58 sigchain_pop(SIGQUIT
);
59 sigchain_pop(SIGTERM
);