summaryrefslogtreecommitdiff
path: root/usr.bin/patch
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2019-08-17 14:25:07 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2019-08-17 14:25:07 +0000
commitf8bbf66dd2611b1c2dbe88fb37c0d7b9bc63ab08 (patch)
treebb176269b9f213889758d76f21be65aeb750b818 /usr.bin/patch
parent499e17da9c8a4367656607dddc6de540c5973c63 (diff)
signal handlers should not call exit() due to possibility of reentering
libc (stdio etc), instead do the unlink tasks then call _exit() instead ok millert
Diffstat (limited to 'usr.bin/patch')
-rw-r--r--usr.bin/patch/util.c30
-rw-r--r--usr.bin/patch/util.h3
2 files changed, 25 insertions, 8 deletions
diff --git a/usr.bin/patch/util.c b/usr.bin/patch/util.c
index ae14e359895..0f274825065 100644
--- a/usr.bin/patch/util.c
+++ b/usr.bin/patch/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.43 2019/06/28 13:35:02 deraadt Exp $ */
+/* $OpenBSD: util.c,v 1.44 2019/08/17 14:25:06 deraadt Exp $ */
/*
* patch - a program to apply diffs to original files
@@ -289,10 +289,10 @@ set_signals(int reset)
if (!reset) {
hupval = signal(SIGHUP, SIG_IGN);
if (hupval != SIG_IGN)
- hupval = (sig_t) my_exit;
+ hupval = my_sigexit;
intval = signal(SIGINT, SIG_IGN);
if (intval != SIG_IGN)
- intval = (sig_t) my_exit;
+ intval = my_sigexit;
}
signal(SIGHUP, hupval);
signal(SIGINT, intval);
@@ -393,11 +393,8 @@ version(void)
my_exit(EXIT_SUCCESS);
}
-/*
- * Exit with cleanup.
- */
void
-my_exit(int status)
+my_cleanup(void)
{
unlink(TMPINNAME);
if (!toutkeep)
@@ -405,5 +402,24 @@ my_exit(int status)
if (!trejkeep)
unlink(TMPREJNAME);
unlink(TMPPATNAME);
+}
+
+/*
+ * Exit with cleanup.
+ */
+void
+my_exit(int status)
+{
+ my_cleanup();
exit(status);
}
+
+/*
+ * Exit with cleanup, from a signal handler.
+ */
+void
+my_sigexit(int signo)
+{
+ my_cleanup();
+ _exit(2);
+}
diff --git a/usr.bin/patch/util.h b/usr.bin/patch/util.h
index 6404eb21baf..a21929b4fa1 100644
--- a/usr.bin/patch/util.h
+++ b/usr.bin/patch/util.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.h,v 1.17 2015/07/26 14:32:19 millert Exp $ */
+/* $OpenBSD: util.h,v 1.18 2019/08/17 14:25:06 deraadt Exp $ */
/*
* patch - a program to apply diffs to original files
@@ -45,6 +45,7 @@ void ignore_signals(void);
void makedirs(const char *, bool);
void version(void);
void my_exit(int) __attribute__((noreturn));
+void my_sigexit(int) __attribute__((noreturn));
/* in mkpath.c */
extern int mkpath(char *);