This commit adds the reset_all_signals() function, which resets all custom signal handlers to the default signal handler (SIG_DFL).
Signed-off-by: Nadav Tasher <[email protected]> --- include/libbb.h | 2 ++ libbb/signals.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/libbb.h b/include/libbb.h index ed2af5af2..11d2c27ec 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -649,6 +649,8 @@ int sigprocmask2(int how, sigset_t *set) FAST_FUNC; /* Standard handler which just records signo */ extern smallint bb_got_signal; void record_signo(int signo); /* not FAST_FUNC! */ +/* Resets all signal handlers just like exec() does */ +void reset_all_signals(void) FAST_FUNC; void xsetgid(gid_t gid) FAST_FUNC; diff --git a/libbb/signals.c b/libbb/signals.c index 0bebc847d..1b2fc8b21 100644 --- a/libbb/signals.c +++ b/libbb/signals.c @@ -128,3 +128,29 @@ void FAST_FUNC signal_no_SA_RESTART_empty_mask(int sig, void (*handler)(int)) sa.sa_handler = handler; sigaction_set(sig, &sa); } + +void FAST_FUNC reset_all_signals(void) +{ + struct sigaction sa; + memset(&sa, 0, sizeof(sa)); + + /* used as the default sigaction */ + sa.sa_handler = SIG_DFL; + + for (int sig = 1; sig < NSIG; ++sig) { + struct sigaction old; + + /* returns 0 on success*/ + if (sigaction(sig, NULL, &old) != 0) + continue; + + if (old.sa_handler == SIG_IGN) + continue; + + if (old.sa_handler == SIG_DFL) + continue; + + /* change signal handler to default */ + sigaction(sig, &sa, NULL); + } +} \ No newline at end of file -- 2.43.0 _______________________________________________ busybox mailing list [email protected] https://lists.busybox.net/mailman/listinfo/busybox
