From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: clean up the temporary file when the process dies from a signal
Date: Fri, 17 Jul 2015 22:42:07 -0500 (EST) [thread overview]
Message-ID: <8848217450401579502.enqueue@fantadrom.bsd.lv> (raw)
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
reply other threads:[~2015-07-18 3:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8848217450401579502.enqueue@fantadrom.bsd.lv \
--to=schwarze@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).