From 60cfd588c5155779235fb655f5cfb72ced1833e5 Mon Sep 17 00:00:00 2001 From: Tobias Ulmer Date: Wed, 29 Jul 2015 12:31:50 +0200 Subject: [PATCH] Reset all signal handlers to their defaults bz#147 Signed-off-by: Tobias Ulmer --- Changelog | 1 + generic/e2lib.lua | 5 +++++ generic/e2util.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/Changelog b/Changelog index 03db877..fbd96f8 100644 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ NEXT: + * Reset all signal handlers to their default values * Fix rotating logs when the result name contains a dash * Fix rsync silently skipping non-regular files and directories diff --git a/generic/e2lib.lua b/generic/e2lib.lua index b24b17e..e36906a 100644 --- a/generic/e2lib.lua +++ b/generic/e2lib.lua @@ -133,6 +133,11 @@ function e2lib.init() -- DEBUG: change to "cr" to log return from function debug.sethook(e2lib.tracer, "c") + local rc, re = e2util.signal_reset() + if not rc then + e2lib.abort(re) + end + e2lib.globals.warn_category = { WDEFAULT = false, WDEPRECATED = false, diff --git a/generic/e2util.c b/generic/e2util.c index 1cb6f80..9be5b50 100644 --- a/generic/e2util.c +++ b/generic/e2util.c @@ -723,6 +723,46 @@ do_getpid(lua_State *lua) { return 1; } +/* e2util.signal_reset() + * Reset all (possible) signals back to their default settings + */ +static int +signal_reset(lua_State *L) +{ + int s; + struct sigaction act; + + for (s = 1; s < NSIG; s++) { + if (sigaction(s, NULL, &act) < 0) + break; /* end of signals */ + + switch (s) { + case SIGINT: + /* used by e2factory */ + continue; + case SIGFPE: + act.sa_handler = SIG_IGN; + break; + case SIGKILL: + case SIGSTOP: + case SIGCONT: + continue; + default: + act.sa_handler = SIG_DFL; + } + + if (sigaction(s, &act, NULL) < 0) { + // fprintf(stderr, "%d is set to %p\n", s, (void *)act.sa_handler); + lua_pushboolean(L, 0); + lua_pushstring(L, strerror(errno)); + return 2; + } + } + + lua_pushboolean(L, 1); + return 1; +} + /* e2util.catch_interrupt() Establish signal handler for SIGINT that aborts. */ @@ -782,6 +822,7 @@ static luaL_Reg lib[] = { { "unsetenv", do_unsetenv }, { "exec", do_exec }, { "getpid", do_getpid }, + { "signal_reset", signal_reset }, { NULL, NULL } }; -- 2.39.5