From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]); by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id aa240c3f; for ; Fri, 17 Jul 2015 22:42:07 -0500 (EST) Date: Fri, 17 Jul 2015 22:42:07 -0500 (EST) Message-Id: <8848217450401579502.enqueue@fantadrom.bsd.lv> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: clean up the temporary file when the process dies from a signal X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- clean up the temporary file when the process dies from a signal Modified Files: -------------- mdocml: tag.c Revision Data ------------- Index: tag.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/tag.c,v retrieving revision 1.1 retrieving revision 1.2 diff -Ltag.c -Ltag.c -u -p -r1.1 -r1.2 --- tag.c +++ tag.c @@ -16,6 +16,7 @@ */ #include +#include #include #include #include @@ -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; @@ -156,6 +161,17 @@ tag_unlink(void) if (tag_fn != NULL) unlink(tag_fn); +} + +static void +tag_signal(int signum) +{ + + tag_unlink(); + signal(signum, SIG_DFL); + kill(getpid(), signum); + /* NOTREACHED */ + _exit(1); } /* -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv