]> git.e2factory.org Git - e2factory.git/commitdiff
Add return of terminating signal in e2lib.wait()
authorTobias Ulmer <tu@emlix.com>
Fri, 22 Nov 2013 11:29:45 +0000 (12:29 +0100)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:17 +0000 (15:41 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/e2lib.lua
generic/le2lib.c

index 20507f2e3bca8204c375b74197a18be3c29bbf79..4a32aa049c77276d6b12a80669c94a427589d4b6 100644 (file)
@@ -199,14 +199,15 @@ end
 -- @param pid Process ID, -1 to wait for any child.
 -- @return Exit status of process (WEXITSTATUS), or false on error.
 -- @return Process ID of the terminated child or error object on failure.
+-- @return Number of signal that killed the process, if any.
 function e2lib.wait(pid)
-    local rc, childpid = le2lib.wait(pid)
+    local rc, childpid, sig = le2lib.wait(pid)
 
     if not rc then
         return false, err.new("waiting for child %d failed: %s", pid, childpid)
     end
 
-    return rc, childpid
+    return rc, childpid, sig
 end
 
 --- Poll input output multiplexing.
index fb6930229612411a982df080ea3309b7560a58d1..8f7ce6f68268f330670e53e54e2e3fd83bde27ca 100644 (file)
@@ -295,8 +295,18 @@ process_wait(lua_State *lua)
                return 2;
        }
 
+       if (!(WIFEXITED(status) || WIFSIGNALED(status))) {
+               lua_pushboolean(lua, 0);
+               lua_pushstring(lua, "process terminated(?) due to unknown cause");
+               return 2;
+       }
+
        lua_pushnumber(lua, WEXITSTATUS(status));
        lua_pushnumber(lua, rc);
+       if (WIFSIGNALED(status)) {
+               lua_pushnumber(lua, WTERMSIG(status));
+               return 3;
+       }
 
        return 2;
 }