libubox: allow reading out the pid of uloop process in lua
authorFlorian Eckert <eckert.florian@googlemail.com>
Tue, 13 Dec 2016 11:34:31 +0000 (12:34 +0100)
committerFelix Fietkau <nbd@nbd.name>
Tue, 13 Dec 2016 16:13:20 +0000 (17:13 +0100)
Add Lua method to get the forked pid of a uloop process

Signed-off-by: Florian Eckert <Eckert.Florian@googlemail.com>
lua/uloop.c

index a78c2dc64557333a27e690b258c3383b95448444..1b0389f12bc700a66ca4a30c3c53110bcf5417af 100644 (file)
@@ -288,8 +288,21 @@ static int ul_process_free(lua_State *L)
        return 1;
 }
 
+static int ul_process_pid(lua_State *L)
+{
+       struct lua_uloop_process *proc = lua_touserdata(L, 1);
+
+       if (proc->p.pid) {
+               lua_pushnumber(L, proc->p.pid);
+               return 1;
+       }
+
+       return 0;
+}
+
 static const luaL_Reg process_m[] = {
        { "delete", ul_process_free },
+       { "pid", ul_process_pid },
        { NULL, NULL }
 };