]> git.e2factory.org Git - e2factory.git/commitdiff
e2lib: finish: if we received a signal, exit with the signal code
authorTobias Ulmer <tu@emlix.com>
Fri, 15 Feb 2019 10:42:08 +0000 (11:42 +0100)
committerTobias Ulmer <tu@emlix.com>
Fri, 15 Feb 2019 10:59:58 +0000 (11:59 +0100)
Receiving a signal causes subsequent errors which hide the true cause
for termination. Make sure we always exit with 128 + signalno and let
the user know that above errors were caused by a signal.

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

index 44a50f15f3028ed68acdc64ea72aaf449a56b3aa..8837ceb85fc0f7c8d05f76c61f14da42ba069c54 100644 (file)
@@ -878,18 +878,30 @@ end
 -- @param rc number: return code (optional, defaults to 0)
 -- @return This function does not return.
 function e2lib.finish(returncode)
+    local sigstr, signum
+    local finalreturn
     if not returncode then
         returncode = 0
     end
     e2lib.cleanup()
 
-    e2lib.logf(4, "exiting e2factory with returncode=%d", returncode)
+    finalreturn = returncode
+    sigstr, signum = e2lib.signal_received()
+    if sigstr ~= "" then
+        e2lib.logf(1,"Error: *** received signal %d \"%s\" ***", signum, sigstr)
+        finalreturn = 128 + signum
+    end
+
+    children_assert_empty()
+
+    e2lib.logf(4, "exiting e2factory with pid=%d returncode=%d finalreturn=%d",
+        e2lib.getpid(), returncode, finalreturn)
     if e2lib.globals.debuglogfile then
         eio.fclose(e2lib.globals.debuglogfile)
         e2lib.globals.debuglogfile = false
     end
     console.close()
-    os.exit(returncode)
+    os.exit(finalreturn)
 end
 
 --- Returns the "directory" part of a path