source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: clean up the temporary file when the process dies from a signal
@ 2015-07-18  3:42 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-07-18  3:42 UTC (permalink / raw)
  To: source

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 <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;
@@ -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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-07-18  3:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-18  3:42 mdocml: clean up the temporary file when the process dies from a signal schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).