Software /
code /
prosody
Annotate
util-src/signal.c @ 8274:3798955049e3
prosodyctl: cert import: Reuse function from certmanager for locating certificates and keys
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 27 Sep 2017 15:21:20 +0200 |
parent | 7973:703f7f45feb4 |
child | 8414:7ea3311ca632 |
rev | line source |
---|---|
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 /* |
2405
88f73ee1c46f
util.signal: Update header comment for new filename
Matthew Wild <mwild1@gmail.com>
parents:
2343
diff
changeset
|
2 * signal.c -- Signal Handler Library for Lua |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 * |
2431
c4d32b35fe60
util.signal: Update version in header, and author's email
Matthew Wild <mwild1@gmail.com>
parents:
2430
diff
changeset
|
4 * Version: 1.000+changes |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 * |
2431
c4d32b35fe60
util.signal: Update version in header, and author's email
Matthew Wild <mwild1@gmail.com>
parents:
2430
diff
changeset
|
6 * Copyright (C) 2007 Patrick J. Donnelly (batrick@batbytes.com) |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 * |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 * This software is distributed under the same license as Lua 5.0: |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 * |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 * Permission is hereby granted, free of charge, to any person obtaining a |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 * copy of this software and associated documentation files (the "Software"), |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 * to deal in the Software without restriction, including without limitation |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 * and/or sell copies of the Software, and to permit persons to whom the |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 * Software is furnished to do so, subject to the following conditions: |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 * |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 * The above copyright notice and this permission notice shall be included |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 * in all copies or substantial portions of the Software. |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 * |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
26 * OTHER DEALINGS IN THE SOFTWARE. |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 */ |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 |
7973
703f7f45feb4
util.signal: Enable all GNU features, _DEFAULT_SOURCE doesn't have the desired effect before glibc 2.19
Kim Alvefur <zash@zash.se>
parents:
7971
diff
changeset
|
29 #define _GNU_SOURCE |
7931
b619b85e01aa
util.pposix, configure: Move _GNU_SOURCE macro into source files
Kim Alvefur <zash@zash.se>
parents:
7889
diff
changeset
|
30 |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 #include <signal.h> |
2459
66f60e69567b
util.signal: Using stdlib.h instead of malloc.h.
Tobias Markmann <tm@ayena.de>
parents:
2432
diff
changeset
|
32 #include <stdlib.h> |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 #include "lua.h" |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 #include "lauxlib.h" |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 |
6789
6b180e77c97a
util-src/*.c: Invert Lua 5.2 compat to be 5.2+ by default and a macro to support 5.1
Kim Alvefur <zash@zash.se>
parents:
6620
diff
changeset
|
37 #if (LUA_VERSION_NUM == 501) |
6b180e77c97a
util-src/*.c: Invert Lua 5.2 compat to be 5.2+ by default and a macro to support 5.1
Kim Alvefur <zash@zash.se>
parents:
6620
diff
changeset
|
38 #define luaL_setfuncs(L, R, N) luaL_register(L, NULL, R) |
6413
a552f4170aed
util-src/*.c: Add macro for compiling with Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
6412
diff
changeset
|
39 #endif |
a552f4170aed
util-src/*.c: Add macro for compiling with Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
6412
diff
changeset
|
40 |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 #ifndef lsig |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 #define lsig |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
45 struct lua_signal { |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
46 char *name; /* name of the signal */ |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
47 int sig; /* the signal */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 }; |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 #define LUA_SIGNAL "lua_signal" |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 static const struct lua_signal lua_signals[] = { |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
55 /* ANSI C signals */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 #ifdef SIGABRT |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
57 {"SIGABRT", SIGABRT}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 #ifdef SIGFPE |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
60 {"SIGFPE", SIGFPE}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 #ifdef SIGILL |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
63 {"SIGILL", SIGILL}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 #ifdef SIGINT |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
66 {"SIGINT", SIGINT}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 #ifdef SIGSEGV |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
69 {"SIGSEGV", SIGSEGV}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 #ifdef SIGTERM |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
72 {"SIGTERM", SIGTERM}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 #endif |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
74 /* posix signals */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 #ifdef SIGHUP |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
76 {"SIGHUP", SIGHUP}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 #ifdef SIGQUIT |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
79 {"SIGQUIT", SIGQUIT}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 #ifdef SIGTRAP |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
82 {"SIGTRAP", SIGTRAP}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 #ifdef SIGKILL |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
85 {"SIGKILL", SIGKILL}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 #ifdef SIGUSR1 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
88 {"SIGUSR1", SIGUSR1}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 #ifdef SIGUSR2 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
91 {"SIGUSR2", SIGUSR2}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 #ifdef SIGPIPE |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
94 {"SIGPIPE", SIGPIPE}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 #ifdef SIGALRM |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
97 {"SIGALRM", SIGALRM}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 #ifdef SIGCHLD |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
100 {"SIGCHLD", SIGCHLD}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 #ifdef SIGCONT |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
103 {"SIGCONT", SIGCONT}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 #ifdef SIGSTOP |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
106 {"SIGSTOP", SIGSTOP}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 #ifdef SIGTTIN |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
109 {"SIGTTIN", SIGTTIN}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 #ifdef SIGTTOU |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
112 {"SIGTTOU", SIGTTOU}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 #endif |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
114 /* some BSD signals */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 #ifdef SIGIOT |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
116 {"SIGIOT", SIGIOT}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 #ifdef SIGBUS |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
119 {"SIGBUS", SIGBUS}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 #ifdef SIGCLD |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
122 {"SIGCLD", SIGCLD}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 #ifdef SIGURG |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
125 {"SIGURG", SIGURG}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 #ifdef SIGXCPU |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
128 {"SIGXCPU", SIGXCPU}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 #ifdef SIGXFSZ |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
131 {"SIGXFSZ", SIGXFSZ}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 #ifdef SIGVTALRM |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
134 {"SIGVTALRM", SIGVTALRM}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 #ifdef SIGPROF |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
137 {"SIGPROF", SIGPROF}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 #ifdef SIGWINCH |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
140 {"SIGWINCH", SIGWINCH}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 #ifdef SIGPOLL |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
143 {"SIGPOLL", SIGPOLL}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 #ifdef SIGIO |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
146 {"SIGIO", SIGIO}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 #endif |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
148 /* add odd signals */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 #ifdef SIGSTKFLT |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
150 {"SIGSTKFLT", SIGSTKFLT}, /* stack fault */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 #ifdef SIGSYS |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
153 {"SIGSYS", SIGSYS}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 #endif |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
155 {NULL, 0} |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 }; |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
158 static lua_State *Lsig = NULL; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 static lua_Hook Hsig = NULL; |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 static int Hmask = 0; |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 static int Hcount = 0; |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
163 static struct signal_event { |
2430
69d377c84fe3
util.signal: Queue up multiple signals, instead of trampling on the previous debug hook (and never clearing our own)
Matthew Wild <mwild1@gmail.com>
parents:
2405
diff
changeset
|
164 int Nsig; |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
165 struct signal_event *next_event; |
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
166 } *signal_queue = NULL; |
2430
69d377c84fe3
util.signal: Queue up multiple signals, instead of trampling on the previous debug hook (and never clearing our own)
Matthew Wild <mwild1@gmail.com>
parents:
2405
diff
changeset
|
167 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
168 static struct signal_event *last_event = NULL; |
2430
69d377c84fe3
util.signal: Queue up multiple signals, instead of trampling on the previous debug hook (and never clearing our own)
Matthew Wild <mwild1@gmail.com>
parents:
2405
diff
changeset
|
169 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
170 static void sighook(lua_State *L, lua_Debug *ar) { |
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
171 struct signal_event *event; |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
172 /* restore the old hook */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
173 lua_sethook(L, Hsig, Hmask, Hcount); |
2432
1e045b3e9dce
util.signal: Restore the old debug hook earlier, just in case we receive another signal between clearing the signal queue and restoring it
Matthew Wild <mwild1@gmail.com>
parents:
2431
diff
changeset
|
174 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
175 lua_pushstring(L, LUA_SIGNAL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
176 lua_gettable(L, LUA_REGISTRYINDEX); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
178 while((event = signal_queue)) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
179 lua_pushnumber(L, event->Nsig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
180 lua_gettable(L, -2); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
181 lua_call(L, 0, 0); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
182 signal_queue = event->next_event; |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
183 free(event); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
184 }; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
186 lua_pop(L, 1); /* pop lua_signal table */ |
2430
69d377c84fe3
util.signal: Queue up multiple signals, instead of trampling on the previous debug hook (and never clearing our own)
Matthew Wild <mwild1@gmail.com>
parents:
2405
diff
changeset
|
187 |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
188 } |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
189 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
190 static void handle(int sig) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
191 if(!signal_queue) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
192 /* Store the existing debug hook (if any) and its parameters */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
193 Hsig = lua_gethook(Lsig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
194 Hmask = lua_gethookmask(Lsig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
195 Hcount = lua_gethookcount(Lsig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
196 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
197 signal_queue = malloc(sizeof(struct signal_event)); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
198 signal_queue->Nsig = sig; |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
199 signal_queue->next_event = NULL; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
200 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
201 last_event = signal_queue; |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
202 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
203 /* Set our new debug hook */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
204 lua_sethook(Lsig, sighook, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
205 } else { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
206 last_event->next_event = malloc(sizeof(struct signal_event)); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
207 last_event->next_event->Nsig = sig; |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
208 last_event->next_event->next_event = NULL; |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
209 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
210 last_event = last_event->next_event; |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
211 } |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
212 } |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
214 /* |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 * l_signal == signal(signal [, func [, chook]]) |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
216 * |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
217 * signal = signal number or string |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
218 * func = Lua function to call |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
219 * chook = catch within C functions |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
220 * if caught, Lua function _must_ |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 * exit, as the stack is most likely |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
222 * in an unstable state. |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
223 */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
225 static int l_signal(lua_State *L) { |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
226 int args = lua_gettop(L); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
227 int t, sig; /* type, signal */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
228 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
229 /* get type of signal */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
230 luaL_checkany(L, 1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
231 t = lua_type(L, 1); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
233 if(t == LUA_TNUMBER) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
234 sig = (int) lua_tonumber(L, 1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
235 } else if(t == LUA_TSTRING) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
236 lua_pushstring(L, LUA_SIGNAL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
237 lua_gettable(L, LUA_REGISTRYINDEX); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
238 lua_pushvalue(L, 1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
239 lua_gettable(L, -2); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
240 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
241 if(!lua_isnumber(L, -1)) { |
6620
50eaefeec013
util-src/*.c: Per convention call luaL_error() as argument to return
Florian Zeitz <florob@babelmonkeys.de>
parents:
6615
diff
changeset
|
242 return luaL_error(L, "invalid signal string"); |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
243 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
244 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
245 sig = (int) lua_tonumber(L, -1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
246 lua_pop(L, 1); /* get rid of number we pushed */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
247 } else { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
248 luaL_checknumber(L, 1); /* will always error, with good error msg */ |
6620
50eaefeec013
util-src/*.c: Per convention call luaL_error() as argument to return
Florian Zeitz <florob@babelmonkeys.de>
parents:
6615
diff
changeset
|
249 return luaL_error(L, "unreachable: invalid number was accepted"); |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
250 } |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
251 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
252 /* set handler */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
253 if(args == 1 || lua_isnil(L, 2)) { /* clear handler */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
254 lua_pushstring(L, LUA_SIGNAL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
255 lua_gettable(L, LUA_REGISTRYINDEX); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
256 lua_pushnumber(L, sig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
257 lua_gettable(L, -2); /* return old handler */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
258 lua_pushnumber(L, sig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
259 lua_pushnil(L); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
260 lua_settable(L, -4); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
261 lua_remove(L, -2); /* remove LUA_SIGNAL table */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
262 signal(sig, SIG_DFL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
263 } else { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
264 luaL_checktype(L, 2, LUA_TFUNCTION); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
265 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
266 lua_pushstring(L, LUA_SIGNAL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
267 lua_gettable(L, LUA_REGISTRYINDEX); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
268 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
269 lua_pushnumber(L, sig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
270 lua_pushvalue(L, 2); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
271 lua_settable(L, -3); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
272 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
273 /* Set the state for the handler */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
274 Lsig = L; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
275 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
276 if(lua_toboolean(L, 3)) { /* c hook? */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
277 if(signal(sig, handle) == SIG_ERR) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
278 lua_pushboolean(L, 0); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
279 } else { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
280 lua_pushboolean(L, 1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
281 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
282 } else { /* lua_hook */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
283 if(signal(sig, handle) == SIG_ERR) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
284 lua_pushboolean(L, 0); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
285 } else { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
286 lua_pushboolean(L, 1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
287 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
288 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
289 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
290 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
291 return 1; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
292 } |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
293 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
294 /* |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
295 * l_raise == raise(signal) |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
296 * |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
297 * signal = signal number or string |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
298 */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
299 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
300 static int l_raise(lua_State *L) { |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
301 /* int args = lua_gettop(L); */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
302 int t = 0; /* type */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
303 lua_Number ret; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
304 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
305 luaL_checkany(L, 1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
306 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
307 t = lua_type(L, 1); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
308 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
309 if(t == LUA_TNUMBER) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
310 ret = (lua_Number) raise((int) lua_tonumber(L, 1)); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
311 lua_pushnumber(L, ret); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
312 } else if(t == LUA_TSTRING) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
313 lua_pushstring(L, LUA_SIGNAL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
314 lua_gettable(L, LUA_REGISTRYINDEX); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
315 lua_pushvalue(L, 1); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
316 lua_gettable(L, -2); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
317 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
318 if(!lua_isnumber(L, -1)) { |
6620
50eaefeec013
util-src/*.c: Per convention call luaL_error() as argument to return
Florian Zeitz <florob@babelmonkeys.de>
parents:
6615
diff
changeset
|
319 return luaL_error(L, "invalid signal string"); |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
320 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
321 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
322 ret = (lua_Number) raise((int) lua_tonumber(L, -1)); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
323 lua_pop(L, 1); /* get rid of number we pushed */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
324 lua_pushnumber(L, ret); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
325 } else { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
326 luaL_checknumber(L, 1); /* will always error, with good error msg */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
327 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
328 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
329 return 1; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
330 } |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
331 |
3282
8ef3beed0779
util.signal: Make kill() available on OS X (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
3274
diff
changeset
|
332 #if defined(__unix__) || defined(__APPLE__) |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
333 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
334 /* define some posix only functions */ |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
335 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
336 /* |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
337 * l_kill == kill(pid, signal) |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
338 * |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
339 * pid = process id |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
340 * signal = signal number or string |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
341 */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
342 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
343 static int l_kill(lua_State *L) { |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
344 int t; /* type */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
345 lua_Number ret; /* return value */ |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
346 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
347 luaL_checknumber(L, 1); /* must be int for pid */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
348 luaL_checkany(L, 2); /* check for a second arg */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
349 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
350 t = lua_type(L, 2); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
351 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
352 if(t == LUA_TNUMBER) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
353 ret = (lua_Number) kill((int) lua_tonumber(L, 1), |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
354 (int) lua_tonumber(L, 2)); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
355 lua_pushnumber(L, ret); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
356 } else if(t == LUA_TSTRING) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
357 lua_pushstring(L, LUA_SIGNAL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
358 lua_gettable(L, LUA_REGISTRYINDEX); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
359 lua_pushvalue(L, 2); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
360 lua_gettable(L, -2); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
361 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
362 if(!lua_isnumber(L, -1)) { |
6620
50eaefeec013
util-src/*.c: Per convention call luaL_error() as argument to return
Florian Zeitz <florob@babelmonkeys.de>
parents:
6615
diff
changeset
|
363 return luaL_error(L, "invalid signal string"); |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
364 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
365 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
366 ret = (lua_Number) kill((int) lua_tonumber(L, 1), |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
367 (int) lua_tonumber(L, -1)); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
368 lua_pop(L, 1); /* get rid of number we pushed */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
369 lua_pushnumber(L, ret); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
370 } else { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
371 luaL_checknumber(L, 2); /* will always error, with good error msg */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
372 } |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
373 |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
374 return 1; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
375 } |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
376 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
377 #endif |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
378 |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
379 static const struct luaL_Reg lsignal_lib[] = { |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
380 {"signal", l_signal}, |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
381 {"raise", l_raise}, |
3282
8ef3beed0779
util.signal: Make kill() available on OS X (thanks darkrain).
Waqas Hussain <waqas20@gmail.com>
parents:
3274
diff
changeset
|
382 #if defined(__unix__) || defined(__APPLE__) |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
383 {"kill", l_kill}, |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
384 #endif |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
385 {NULL, NULL} |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
386 }; |
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
387 |
7889
b8d694646597
util-src/*.c: Attach pointer * to name instead of type
Kim Alvefur <zash@zash.se>
parents:
7818
diff
changeset
|
388 int luaopen_util_signal(lua_State *L) { |
7818
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
6789
diff
changeset
|
389 #if (LUA_VERSION_NUM > 501) |
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
6789
diff
changeset
|
390 luaL_checkversion(L); |
54669df178c2
util-src: Make C modules assert that the Lua runtime matches what it was compiled for
Kim Alvefur <zash@zash.se>
parents:
6789
diff
changeset
|
391 #endif |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
392 int i = 0; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
393 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
394 /* add the library */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
395 lua_newtable(L); |
6789
6b180e77c97a
util-src/*.c: Invert Lua 5.2 compat to be 5.2+ by default and a macro to support 5.1
Kim Alvefur <zash@zash.se>
parents:
6620
diff
changeset
|
396 luaL_setfuncs(L, lsignal_lib, 0); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
397 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
398 /* push lua_signals table into the registry */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
399 /* put the signals inside the library table too, |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
400 * they are only a reference */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
401 lua_pushstring(L, LUA_SIGNAL); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
402 lua_newtable(L); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
403 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
404 while(lua_signals[i].name != NULL) { |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
405 /* registry table */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
406 lua_pushstring(L, lua_signals[i].name); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
407 lua_pushnumber(L, lua_signals[i].sig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
408 lua_settable(L, -3); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
409 /* signal table */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
410 lua_pushstring(L, lua_signals[i].name); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
411 lua_pushnumber(L, lua_signals[i].sig); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
412 lua_settable(L, -5); |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
413 i++; |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
414 } |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
415 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
416 /* add newtable to the registry */ |
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
417 lua_settable(L, LUA_REGISTRYINDEX); |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
418 |
6615
8e4572a642cb
util-src/*.c: astyle --indent=tab --brackets=attach --indent-switches --break-blocks --pad-oper --unpad-paren --add-brackets --align-pointer=type --lineend=linux
Kim Alvefur <zash@zash.se>
parents:
6413
diff
changeset
|
419 return 1; |
988
8cb9a0d59e78
util.lsignal: Add lsignal library for catching POSIX signals
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
420 } |