diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2015-07-18 03:41:37 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2015-07-18 03:41:37 +0000 |
commit | b539a584ed036e3ce6bc8c06d7064ebcd0a8749d (patch) | |
tree | 69797ab78b6a235dfb7a037707bedf836ab0012e | |
parent | 7cdeeeae6409bfe474baf9dd555cf51d8212d6ed (diff) | |
download | mandoc-b539a584ed036e3ce6bc8c06d7064ebcd0a8749d.tar.gz |
clean up the temporary file when the process dies from a signal
-rw-r--r-- | tag.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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. */ |