aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-11-23 17:42:48 +0100
committerKim Alvefur <zash@zash.se>2017-11-23 17:42:48 +0100
commit8fad47a0c616242cade2b81d7b54af6ea8c7176b (patch)
tree1a9a9b40cf43fe8ee9bc407011deab06739b8a00
parent9290f9588a329280e41dd51fbb2895e46e7e29ed (diff)
parent27d99dd43b75773ce537a7fdd2977987a3f913a0 (diff)
downloadprosody-8fad47a0c616242cade2b81d7b54af6ea8c7176b.tar.gz
prosody-8fad47a0c616242cade2b81d7b54af6ea8c7176b.zip
Merge 0.10->trunk
-rw-r--r--util-src/signal.c35
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;
}
}