summaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2013-12-12 22:47:27 -0800
committerKaz Kylheku <kaz@kylheku.com>2013-12-12 22:47:27 -0800
commitb3f8bee89e3fa5713ff391e0172b8e1d4b92be25 (patch)
tree14d49b10503cd3e086d00c79df184e51d444fe6b /eval.c
parentccf6c78422c227778c5e6103413849803aa7b158 (diff)
downloadtxr-b3f8bee89e3fa5713ff391e0172b8e1d4b92be25.tar.gz
txr-b3f8bee89e3fa5713ff391e0172b8e1d4b92be25.tar.bz2
txr-b3f8bee89e3fa5713ff391e0172b8e1d4b92be25.zip
First cut at signal handling support.
* Makefile (OBJS-y): Include signal.o if have_posix_sigs is "y". * configure (have_posix_sigs): New variable, set by detecting POSIX signal stuff. * dep.mk: Regenerated. * arith.c, debug.c, eval.c, filter.c, hash.c, match.c, parser.y, parser.l, rand.c, regex.c, syslog.c, txr.c, utf8.c: Include new signal.h header, now required by unwind, and the <signal.h> system header. * eval.c (exit_wrap): New function. (eval_init): New functions registered as intrinsics: exit_wrap, set_sig_handler, get_sig_handler, sig_check. * gc.c (release): Unused functions removed. * gc.h (release): Declaration removed. * lib.c (init): Call sig_init. * stream.c (set_putc, se_getc, se_fflush): New static functions. (stdio_put_char_callback, stdio_get_char_callback, stdio_put_byte, stdio_flush, stdio_get_byte): Use new functions to enable signals when blocked on I/O. (tail_strategy): Allow signals across sleep. (pipev_close): Allow signals across waitpid. (se_pclose): New static function. (pipe_close): Use new function to enable signals across pclose. * unwind.c (uw_unwind_to_exit_point): use extended_longjmp instead of longjmp. * unwind.h (struct uw_block, struct uw_catch): jb member changes from jmp_buf to extended_jmp_buf. (uw_block_begin, uw_simple_catch_begin, uw_catch_begin): Use extended_setjmp instead of setjmp. * signal.c: New file. * signal.h: New file.
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index cd40a888..f30e895f 100644
--- a/eval.c
+++ b/eval.c
@@ -32,6 +32,7 @@
#include <setjmp.h>
#include <stdarg.h>
#include <wchar.h>
+#include <signal.h>
#include "config.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -41,6 +42,7 @@
#endif
#include "lib.h"
#include "gc.h"
+#include "signal.h"
#include "unwind.h"
#include "regex.h"
#include "stream.h"
@@ -2095,6 +2097,22 @@ static val daemon_wrap(val nochdir, val noclose)
}
#endif
+static val exit_wrap(val status)
+{
+ int stat;
+
+ if (status == nil)
+ stat = EXIT_FAILURE;
+ else if (status == t)
+ stat = EXIT_SUCCESS;
+ else
+ stat = c_num(status);
+
+ exit(stat);
+ /* notreached */
+ return nil;
+}
+
static void reg_fun(val sym, val fun)
{
sethash(top_fb, sym, cons(sym, fun));
@@ -2591,6 +2609,8 @@ void eval_init(void)
reg_fun(intern(lit("make-time-utc"), user_package), func_n7(make_time_utc));
reg_fun(intern(lit("errno"), user_package), func_n1o(errno_wrap, 0));
+ reg_fun(intern(lit("exit"), user_package), func_n1(exit_wrap));
+
#if HAVE_DAEMON
reg_fun(intern(lit("daemon"), user_package), func_n2(daemon_wrap));
#endif
@@ -2624,6 +2644,12 @@ void eval_init(void)
reg_fun(intern(lit("syslog"), user_package), func_n2v(syslog_wrap));
#endif
+#if HAVE_POSIX_SIGS
+ reg_fun(intern(lit("set-sig-handler"), user_package), func_n2(set_sig_handler));
+ reg_fun(intern(lit("get-sig-handler"), user_package), func_n1(get_sig_handler));
+ reg_fun(intern(lit("sig-check"), user_package), func_n0(sig_check));
+#endif
+
reg_fun(intern(lit("source-loc"), user_package), func_n1(source_loc));
reg_fun(intern(lit("source-loc-str"), user_package), func_n1(source_loc_str));