From 49d2bd6438c045eeb965f47a323b1f3115b2a175 Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Tue, 9 Oct 2007 01:32:06 -0500 Subject: initial implementation of suspend() --- src/signal.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/signal.c b/src/signal.c index 0291dcc..a4ea4eb 100644 --- a/src/signal.c +++ b/src/signal.c @@ -172,12 +172,68 @@ static int l_raise(lua_State* L) return 1; } +static int l_suspend(lua_State* L) +{ + sigset_t sset; + int first_arg = 1; + + sigprocmask(0, NULL, &sset); + if (lua_isstring(L, 1)) { + const char* init; + + init = lua_tostring(L, 1); + if (strcmp(init, "all") == 0) { + sigfillset(&sset); + } + else if (strcmp(init, "none") == 0) { + sigemptyset(&sset); + } + else if (strcmp(init, "cur") != 0) { + lua_pushfstring(L, "suspend(): invalid sigset initializer: %s", init); + lua_error(L); + } + first_arg = 2; + } + + luaL_checktype(L, first_arg, LUA_TTABLE); + luaL_checktype(L, first_arg + 1, LUA_TTABLE); + + lua_pushnil(L); + while (lua_next(L, first_arg) != 0) { + if (lua_isstring(L, -1)) { + int sig; + + sig = name_to_sig(lua_tostring(L, -1)); + if (sig != -1) { + sigaddset(&sset, sig); + } + } + lua_pop(L, 1); + } + lua_pushnil(L); + while (lua_next(L, first_arg + 1) != 0) { + if (lua_isstring(L, -1)) { + int sig; + + sig = name_to_sig(lua_tostring(L, -1)); + if (sig != -1) { + sigdelset(&sset, sig); + } + } + lua_pop(L, 1); + } + + sigsuspend(&sset); + + return 0; +} + const luaL_Reg reg[] = { { "signal", l_signal }, { "alarm", l_alarm }, { "kill", l_kill }, { "raise", l_raise }, - /*{ "suspend", l_suspend },*/ + { "suspend", l_suspend }, /*{ "block", l_block },*/ { NULL, NULL }, }; -- cgit v1.2.3-54-g00ecf