summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tag.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/tag.c b/tag.c
index a3610a47..41cb2183 100644
--- a/tag.c
+++ b/tag.c
@@ -16,6 +16,7 @@
*/
#include <sys/types.h>
+#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
@@ -36,6 +37,7 @@ struct tag_entry {
char s[];
};
+static void tag_signal(int);
static void *tag_alloc(size_t, void *);
static void tag_free(void *, void *);
static void *tag_calloc(size_t, size_t, void *);
@@ -56,6 +58,9 @@ tag_init(void)
struct ohash_info tag_info;
tag_fn = mandoc_strdup("/tmp/man.XXXXXXXXXX");
+ signal(SIGHUP, tag_signal);
+ signal(SIGINT, tag_signal);
+ signal(SIGTERM, tag_signal);
if ((tag_fd = mkstemp(tag_fn)) == -1) {
free(tag_fn);
tag_fn = NULL;
@@ -158,6 +163,17 @@ tag_unlink(void)
unlink(tag_fn);
}
+static void
+tag_signal(int signum)
+{
+
+ tag_unlink();
+ signal(signum, SIG_DFL);
+ kill(getpid(), signum);
+ /* NOTREACHED */
+ _exit(1);
+}
+
/*
* Memory management callback functions for ohash.
*/