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 | 171417732fb420345e67987614021f0e9f47992d (patch) | |
tree | e8c432f3de13a9a432f1651c86a367259f68ff4d | |
parent | 7221f76a236baf4056bfe1c909f3c978a4a94349 (diff) | |
download | mandoc-171417732fb420345e67987614021f0e9f47992d.tar.gz mandoc-171417732fb420345e67987614021f0e9f47992d.tar.zst mandoc-171417732fb420345e67987614021f0e9f47992d.zip |
clean up the temporary file when the process dies from a signal
-rw-r--r-- | tag.c | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -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. */ |