# HG changeset patch # User jbe # Date 1496599976 -7200 # Node ID 30629973dcff1c6f5bbfea4018b8a70b26ea7bfe # Parent fab22173abc8d725cf574d982dac7176600147a9 Make moonbridge_io.signalsocket(...) accept strings as argument diff -r fab22173abc8 -r 30629973dcff moonbridge_io.c --- a/moonbridge_io.c Sun Jun 04 19:53:34 2017 +0200 +++ b/moonbridge_io.c Sun Jun 04 20:12:56 2017 +0200 @@ -65,6 +65,7 @@ #define MOONBR_IO_CHILD_MT_REGKEY "moonbridge_io_child" #define MOONBR_IO_CHILD_PT_REGKEY "moonbridge_io_child_pt" #define MOONBR_IO_SIGNALSOCKET_REGKEY "moonbridge_io_signalsocket" +#define MOONBR_IO_SIGNALS_REGKEY "moonbridge_io_signals" #ifdef MOONBR_IO_USE_TLS @@ -1626,9 +1627,22 @@ luaL_error(L, "Could not create socket pair for signal queueing"); } } + lua_getfield(L, LUA_REGISTRYINDEX, MOONBR_IO_SIGNALS_REGKEY); + lua_insert(L, 1); argc = lua_gettop(L); - for (i=1; i<=argc; i++) { - sig = luaL_checkinteger(L, i); + for (i=2; i<=argc; i++) { + if (lua_type(L, i) == LUA_TSTRING) { + lua_pushvalue(L, i); + lua_gettable(L, 1); + sig = lua_tointeger(L, -1); + lua_pop(L, 1); + if (!sig) { + lua_pushvalue(L, i); + luaL_error(L, "Unknown signal \"%s\"", lua_tostring(L, i)); + } + } else { + sig = luaL_checkinteger(L, i); + } errno = 0; signal(sig, moonbr_io_signalhandler); if (errno) luaL_error(L, "Could not install signal handler (invalid signal number?)"); @@ -2094,7 +2108,9 @@ lua_pushinteger(L, SIGINFO); lua_setfield(L, -2, "INFO"); lua_pushinteger(L, SIGUSR1); lua_setfield(L, -2, "USR1"); lua_pushinteger(L, SIGUSR2); lua_setfield(L, -2, "USR2"); - lua_setfield(L, -2, "signals"); + lua_pushvalue(L, -1); + lua_setfield(L, -3, "signals"); + lua_setfield(L, LUA_REGISTRYINDEX, MOONBR_IO_SIGNALS_REGKEY); luaL_setfuncs(L, moonbr_io_module_funcs, 0); return 1; diff -r fab22173abc8 -r 30629973dcff reference.txt --- a/reference.txt Sun Jun 04 19:53:34 2017 +0200 +++ b/reference.txt Sun Jun 04 20:12:56 2017 +0200 @@ -400,7 +400,8 @@ This function installs a signal handler for the signals with the numbers passed as arguments and returns a socket which receives a byte for each received -signal. +signal. Optionally, a string may be used instead of the signal number (e.g. +"KILL" instead of 9, or "TERM" instead of 15). Subsequent calls of this function can extend the set of signals but will always return the same socket. If the socket is closed, it is no longer possible to