diff options
author | 2019-08-17 14:25:06 +0000 | |
---|---|---|
committer | 2019-08-17 14:25:06 +0000 | |
commit | 34060d49210e99f50067334b5944e9cc81e2f71c (patch) | |
tree | 4683d502b5a3fa9c98e753773016284124006134 /usr.bin/patch/util.c | |
parent | drm/i915: Fix wrong escape clock divisor init for GLK (diff) | |
download | wireguard-openbsd-34060d49210e99f50067334b5944e9cc81e2f71c.tar.xz wireguard-openbsd-34060d49210e99f50067334b5944e9cc81e2f71c.zip |
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/util.c')
-rw-r--r-- | usr.bin/patch/util.c | 30 |
1 files changed, 23 insertions, 7 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); +} |