diff options
author | Kim Alvefur <zash@zash.se> | 2017-11-23 17:42:48 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2017-11-23 17:42:48 +0100 |
commit | 28c16a7f5bb8f9cf8cd4f1fa69290fc7a413e44b (patch) | |
tree | 1a9a9b40cf43fe8ee9bc407011deab06739b8a00 /util-src | |
parent | 1c8bd46535265c04bb446fb24f18c6ce082b4938 (diff) | |
parent | 4b1e3a2b85b3c174485a030477437428a5a23eeb (diff) | |
download | prosody-28c16a7f5bb8f9cf8cd4f1fa69290fc7a413e44b.tar.gz prosody-28c16a7f5bb8f9cf8cd4f1fa69290fc7a413e44b.zip |
Merge 0.10->trunk
Diffstat (limited to 'util-src')
-rw-r--r-- | util-src/signal.c | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/util-src/signal.c b/util-src/signal.c index 2268e11c..b94beffa 100644 --- a/util-src/signal.c +++ b/util-src/signal.c @@ -49,6 +49,8 @@ struct lua_signal { #endif +#define MAX_PENDING_SIGNALS 32 + #define LUA_SIGNAL "lua_signal" static const struct lua_signal lua_signals[] = { @@ -160,54 +162,41 @@ static lua_Hook Hsig = NULL; static int Hmask = 0; static int Hcount = 0; -static struct signal_event { - int Nsig; - struct signal_event *next_event; -} *signal_queue = NULL; - -static struct signal_event *last_event = NULL; +int signals[MAX_PENDING_SIGNALS]; +int nsig = 0; static void sighook(lua_State *L, lua_Debug *ar) { - struct signal_event *event; /* restore the old hook */ lua_sethook(L, Hsig, Hmask, Hcount); lua_pushstring(L, LUA_SIGNAL); lua_gettable(L, LUA_REGISTRYINDEX); - while((event = signal_queue)) { - lua_pushnumber(L, event->Nsig); + for(int i = 1; i <= nsig; i--) { + lua_pushnumber(L, signals[i]); lua_gettable(L, -2); lua_call(L, 0, 0); - signal_queue = event->next_event; - free(event); }; + nsig = 0; + lua_pop(L, 1); /* pop lua_signal table */ } static void handle(int sig) { - if(!signal_queue) { + if(nsig == 0) { /* Store the existing debug hook (if any) and its parameters */ Hsig = lua_gethook(Lsig); Hmask = lua_gethookmask(Lsig); Hcount = lua_gethookcount(Lsig); - signal_queue = malloc(sizeof(struct signal_event)); - signal_queue->Nsig = sig; - signal_queue->next_event = NULL; - - last_event = signal_queue; - /* Set our new debug hook */ lua_sethook(Lsig, sighook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); - } else { - last_event->next_event = malloc(sizeof(struct signal_event)); - last_event->next_event->Nsig = sig; - last_event->next_event->next_event = NULL; + } - last_event = last_event->next_event; + if(nsig < MAX_PENDING_SIGNALS) { + signals[++nsig] = sig; } } |