diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2015-07-18 03:40:52 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2015-07-18 03:40:52 +0000 |
commit | 2c787177f3d7ef93b90052ef75d28b0f46181041 (patch) | |
tree | d73b1ceb4749bd6f67bfbed316947cea1ea99592 | |
parent | ebb51a338138bd6da65d5114232f33a34fd5681b (diff) |
clean up the temporary file when the process dies from a signal
-rw-r--r-- | usr.bin/mandoc/tag.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/usr.bin/mandoc/tag.c b/usr.bin/mandoc/tag.c index 9b191cc73a3..0d1f19ec77f 100644 --- a/usr.bin/mandoc/tag.c +++ b/usr.bin/mandoc/tag.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tag.c,v 1.1 2015/07/17 22:35:36 schwarze Exp $ */ +/* $OpenBSD: tag.c,v 1.2 2015/07/18 03:40:51 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> @@ -32,6 +33,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 *); @@ -52,6 +54,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; @@ -154,6 +159,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. */ |