tools/migration/Makefile: Don't install main.lua (we already install it as prosody...
[prosody.git] / util-src / signal.c
index 4bda69d81451edf33d2d0714021117d43c48d96d..961d2d3e06acda484613a0ebdfc54a8f25625586 100644 (file)
@@ -1,9 +1,9 @@
 /*
  * signal.c -- Signal Handler Library for Lua
  *
- * Version: 1.000
+ * Version: 1.000+changes
  *
- * Copyright (C) 2007  Patrick J. Donnelly (batrick@unm.edu)
+ * Copyright (C) 2007  Patrick J. Donnelly (batrick@batbytes.com)
  *
  * This software is distributed under the same license as Lua 5.0:
  *
@@ -27,7 +27,7 @@
 */
 
 #include <signal.h>
-#include <malloc.h>
+#include <stdlib.h>
 
 #include "lua.h"
 #include "lauxlib.h"
@@ -165,10 +165,13 @@ static struct signal_event *last_event = NULL;
 
 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);
 
-  struct signal_event *event;
   while((event = signal_queue))
   {
     lua_pushnumber(L, event->Nsig);
@@ -180,8 +183,6 @@ static void sighook(lua_State *L, lua_Debug *ar)
 
   lua_pop(L, 1); /* pop lua_signal table */
 
-  /* restore the old hook */
-  lua_sethook(L, Hsig, Hmask, Hcount);
 }
 
 static void handle(int sig)
@@ -325,7 +326,7 @@ static int l_raise(lua_State *L)
   return 1;
 }
 
-#if defined _POSIX_SOURCE || (defined(sun) || defined(__sun))
+#if defined(__unix__) || defined(__APPLE__)
 
 /* define some posix only functions */
 
@@ -372,7 +373,7 @@ static int l_kill(lua_State *L)
 static const struct luaL_Reg lsignal_lib[] = {
   {"signal", l_signal},
   {"raise", l_raise},
-#if defined _POSIX_SOURCE || (defined(sun) || defined(__sun))
+#if defined(__unix__) || defined(__APPLE__)
   {"kill", l_kill},
 #endif
   {NULL, NULL}