aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tag.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2015-07-18 03:41:37 +0000
committerIngo Schwarze <schwarze@openbsd.org>2015-07-18 03:41:37 +0000
commit171417732fb420345e67987614021f0e9f47992d (patch)
treee8c432f3de13a9a432f1651c86a367259f68ff4d /tag.c
parent7221f76a236baf4056bfe1c909f3c978a4a94349 (diff)
downloadmandoc-171417732fb420345e67987614021f0e9f47992d.tar.gz
mandoc-171417732fb420345e67987614021f0e9f47992d.tar.zst
mandoc-171417732fb420345e67987614021f0e9f47992d.zip
clean up the temporary file when the process dies from a signal
Diffstat (limited to 'tag.c')
-rw-r--r--tag.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/tag.c b/tag.c
index f281b81f..69f4e422 100644
--- a/tag.c
+++ b/tag.c
@@ -1,4 +1,4 @@
-/* $Id: tag.c,v 1.1 2015/07/17 22:38:29 schwarze Exp $ */
+/* $Id: tag.c,v 1.2 2015/07/18 03:41:37 schwarze Exp $ */
/*
* Copyright (c) 2015 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -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.
*/