]> git.e2factory.org Git - e2factory.git/commitdiff
Reset all signal handlers to their defaults
authorTobias Ulmer <tu@emlix.com>
Wed, 29 Jul 2015 10:31:50 +0000 (12:31 +0200)
committerTobias Ulmer <tu@emlix.com>
Wed, 7 Oct 2015 18:41:56 +0000 (20:41 +0200)
bz#147

Signed-off-by: Tobias Ulmer <tu@emlix.com>
Changelog
generic/e2lib.lua
generic/e2util.c

index 03db8775f3fa52f131f80b59e315774aa63b8790..fbd96f89cceca3c5db1e264cfa56c99c7fc775a9 100644 (file)
--- 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
 
index b24b17ed1919f2d41468fd1464e4897e4e35a8a0..e36906af670b638ef690f0404ca92a0d177d9d35 100644 (file)
@@ -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,
index 1cb6f803f2976f03bd8ff540a86024b958e0a8a0..9be5b504075b320356b82e1e4ad73a0c7d18287c 100644 (file)
@@ -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 }
 };