Software / code / prosody
Comparison
util-src/signal.c @ 7889:b8d694646597
util-src/*.c: Attach pointer * to name instead of type
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 12 Feb 2017 16:42:29 +0100 |
| parent | 7818:54669df178c2 |
| child | 7931:b619b85e01aa |
comparison
equal
deleted
inserted
replaced
| 7888:74187ee6ed55 | 7889:b8d694646597 |
|---|---|
| 39 #ifndef lsig | 39 #ifndef lsig |
| 40 | 40 |
| 41 #define lsig | 41 #define lsig |
| 42 | 42 |
| 43 struct lua_signal { | 43 struct lua_signal { |
| 44 char* name; /* name of the signal */ | 44 char *name; /* name of the signal */ |
| 45 int sig; /* the signal */ | 45 int sig; /* the signal */ |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 #endif | 48 #endif |
| 49 | 49 |
| 151 {"SIGSYS", SIGSYS}, | 151 {"SIGSYS", SIGSYS}, |
| 152 #endif | 152 #endif |
| 153 {NULL, 0} | 153 {NULL, 0} |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 static lua_State* Lsig = NULL; | 156 static lua_State *Lsig = NULL; |
| 157 static lua_Hook Hsig = NULL; | 157 static lua_Hook Hsig = NULL; |
| 158 static int Hmask = 0; | 158 static int Hmask = 0; |
| 159 static int Hcount = 0; | 159 static int Hcount = 0; |
| 160 | 160 |
| 161 static struct signal_event { | 161 static struct signal_event { |
| 162 int Nsig; | 162 int Nsig; |
| 163 struct signal_event* next_event; | 163 struct signal_event *next_event; |
| 164 }* signal_queue = NULL; | 164 } *signal_queue = NULL; |
| 165 | 165 |
| 166 static struct signal_event* last_event = NULL; | 166 static struct signal_event *last_event = NULL; |
| 167 | 167 |
| 168 static void sighook(lua_State* L, lua_Debug* ar) { | 168 static void sighook(lua_State *L, lua_Debug *ar) { |
| 169 struct signal_event* event; | 169 struct signal_event *event; |
| 170 /* restore the old hook */ | 170 /* restore the old hook */ |
| 171 lua_sethook(L, Hsig, Hmask, Hcount); | 171 lua_sethook(L, Hsig, Hmask, Hcount); |
| 172 | 172 |
| 173 lua_pushstring(L, LUA_SIGNAL); | 173 lua_pushstring(L, LUA_SIGNAL); |
| 174 lua_gettable(L, LUA_REGISTRYINDEX); | 174 lua_gettable(L, LUA_REGISTRYINDEX); |
| 218 * if caught, Lua function _must_ | 218 * if caught, Lua function _must_ |
| 219 * exit, as the stack is most likely | 219 * exit, as the stack is most likely |
| 220 * in an unstable state. | 220 * in an unstable state. |
| 221 */ | 221 */ |
| 222 | 222 |
| 223 static int l_signal(lua_State* L) { | 223 static int l_signal(lua_State *L) { |
| 224 int args = lua_gettop(L); | 224 int args = lua_gettop(L); |
| 225 int t, sig; /* type, signal */ | 225 int t, sig; /* type, signal */ |
| 226 | 226 |
| 227 /* get type of signal */ | 227 /* get type of signal */ |
| 228 luaL_checkany(L, 1); | 228 luaL_checkany(L, 1); |
| 293 * l_raise == raise(signal) | 293 * l_raise == raise(signal) |
| 294 * | 294 * |
| 295 * signal = signal number or string | 295 * signal = signal number or string |
| 296 */ | 296 */ |
| 297 | 297 |
| 298 static int l_raise(lua_State* L) { | 298 static int l_raise(lua_State *L) { |
| 299 /* int args = lua_gettop(L); */ | 299 /* int args = lua_gettop(L); */ |
| 300 int t = 0; /* type */ | 300 int t = 0; /* type */ |
| 301 lua_Number ret; | 301 lua_Number ret; |
| 302 | 302 |
| 303 luaL_checkany(L, 1); | 303 luaL_checkany(L, 1); |
| 336 * | 336 * |
| 337 * pid = process id | 337 * pid = process id |
| 338 * signal = signal number or string | 338 * signal = signal number or string |
| 339 */ | 339 */ |
| 340 | 340 |
| 341 static int l_kill(lua_State* L) { | 341 static int l_kill(lua_State *L) { |
| 342 int t; /* type */ | 342 int t; /* type */ |
| 343 lua_Number ret; /* return value */ | 343 lua_Number ret; /* return value */ |
| 344 | 344 |
| 345 luaL_checknumber(L, 1); /* must be int for pid */ | 345 luaL_checknumber(L, 1); /* must be int for pid */ |
| 346 luaL_checkany(L, 2); /* check for a second arg */ | 346 luaL_checkany(L, 2); /* check for a second arg */ |
| 381 {"kill", l_kill}, | 381 {"kill", l_kill}, |
| 382 #endif | 382 #endif |
| 383 {NULL, NULL} | 383 {NULL, NULL} |
| 384 }; | 384 }; |
| 385 | 385 |
| 386 int luaopen_util_signal(lua_State* L) { | 386 int luaopen_util_signal(lua_State *L) { |
| 387 #if (LUA_VERSION_NUM > 501) | 387 #if (LUA_VERSION_NUM > 501) |
| 388 luaL_checkversion(L); | 388 luaL_checkversion(L); |
| 389 #endif | 389 #endif |
| 390 int i = 0; | 390 int i = 0; |
| 391 | 391 |