1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 * Copyright (C) 2006 Rob Landley
7 * Copyright (C) 2006 Denys Vlasenko
9 * Licensed under GPL version 2, see file LICENSE in this tarball for details.
14 /* All known arches use small ints for signals */
15 smallint bb_got_signal;
17 void record_signo(int signo)
19 bb_got_signal = signo;
22 /* Saves 2 bytes on x86! Oh my... */
23 int FAST_FUNC sigaction_set(int signum, const struct sigaction *act)
25 return sigaction(signum, act, NULL);
28 int FAST_FUNC sigprocmask_allsigs(int how)
32 return sigprocmask(how, &set, NULL);
35 void FAST_FUNC bb_signals(int sigs, void (*f)(int))
50 void FAST_FUNC bb_signals_recursive(int sigs, void (*f)(int))
56 memset(&sa, 0, sizeof(sa));
59 /*sigemptyset(&sa.sa_mask); - hope memset did it*/
64 sigaction_set(sig_no, &sa);
71 void FAST_FUNC sig_block(int sig)
76 sigprocmask(SIG_BLOCK, &ss, NULL);
79 void FAST_FUNC sig_unblock(int sig)
84 sigprocmask(SIG_UNBLOCK, &ss, NULL);
87 void FAST_FUNC wait_for_any_sig(void)
94 /* Assuming the sig is fatal */
95 void FAST_FUNC kill_myself_with_sig(int sig)
100 _exit(EXIT_FAILURE); /* Should not reach it */
103 void FAST_FUNC signal_SA_RESTART_empty_mask(int sig, void (*handler)(int))
106 memset(&sa, 0, sizeof(sa));
107 /*sigemptyset(&sa.sa_mask);*/
108 sa.sa_flags = SA_RESTART;
109 sa.sa_handler = handler;
110 sigaction_set(sig, &sa);
113 void FAST_FUNC signal_no_SA_RESTART_empty_mask(int sig, void (*handler)(int))
116 memset(&sa, 0, sizeof(sa));
117 /*sigemptyset(&sa.sa_mask);*/
119 sa.sa_handler = handler;
120 sigaction_set(sig, &sa);