# HG changeset patch # User jbe # Date 1496879538 -7200 # Node ID 6bb191b6ead52b071b1175caea29256603cb29b5 # Parent 1a4f89f4c712359281618c240c5a9d3d56295584 Make :kill(signal) accept also strings and default to signal 9 (KILL); Improved error handling of :kill(signal) diff -r 1a4f89f4c712 -r 6bb191b6ead5 moonbridge_io.c --- a/moonbridge_io.c Tue Jun 06 21:58:26 2017 +0200 +++ b/moonbridge_io.c Thu Jun 08 01:52:18 2017 +0200 @@ -1518,11 +1518,13 @@ child = luaL_checkudata(L, 1, MOONBR_IO_CHILD_MT_REGKEY); if (child->pid) { int status; - if (kill(child->pid, SIGKILL)) { + int pid = child->pid; + child->pid = 0; + if (kill(pid, SIGKILL)) { moonbr_io_prepare_errmsg(); luaL_error(L, "Error in kill call during garbage collection: %s", errmsg); } - while (waitpid(child->pid, &status, 0) == -1) { + while (waitpid(pid, &status, 0) == -1) { if (errno != EINTR) { moonbr_io_prepare_errmsg(); luaL_error(L, "Error in waitpid call during garbage collection: %s", errmsg); @@ -1536,7 +1538,18 @@ moonbr_io_child_t *child; int sig; child = luaL_checkudata(L, 1, MOONBR_IO_CHILD_MT_REGKEY); - sig = luaL_optinteger(L, 2, SIGTERM); + if (lua_type(L, 2) == LUA_TSTRING) { + lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_SIGNALS_REGKEY); + lua_pushvalue(L, 2); + lua_gettable(L, -2); + sig = lua_tointeger(L, -1); + if (!sig) { + lua_pushvalue(L, 2); + luaL_error(L, "Unknown signal \"%s\"", lua_tostring(L, 2)); + } + } else { + sig = luaL_optinteger(L, 2, SIGKILL); + } if (!child->pid) luaL_error(L, "Attempt to kill an already collected child process"); if (kill(child->pid, sig)) { moonbr_io_prepare_errmsg(); diff -r 1a4f89f4c712 -r 6bb191b6ead5 reference.txt --- a/reference.txt Tue Jun 06 21:58:26 2017 +0200 +++ b/reference.txt Thu Jun 08 01:52:18 2017 +0200 @@ -310,8 +310,8 @@ - :wait_call(waitfunc) - :wait_yield() -Use :kill(signal) to terminate the process with the given signal (defaults to -15 for SIGTERM). +Use :kill(signal) to terminate the process with the given signal (defaults to 9 +for SIGKILL). The :wait() method will wait for the process to terminate and return its exit code. If the process was terminated by a signal, a negative integer is returned