From: deraadt Date: Fri, 12 Jul 2024 14:30:27 +0000 (+0000) Subject: refactor the signal handlers for clarity, inverting the situation: X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=f901c358bd03eff7abd75270f605497f5228c6b0;p=openbsd refactor the signal handlers for clarity, inverting the situation: the signal handler was calling a big function which is shared between multiple contexts -- that hides the rule that this big function has signal safe requirements (which it fails). now, the signal handler contains all the code, and everyone else calls the signal handler function as a regular function, from their (normal) contexts. the signal handler context is the most strict, so this pattern is better. ok florian --- diff --git a/bin/dd/dd.c b/bin/dd/dd.c index d07d935bde7..ef5c4b7a97b 100644 --- a/bin/dd/dd.c +++ b/bin/dd/dd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dd.c,v 1.28 2021/10/24 21:24:21 deraadt Exp $ */ +/* $OpenBSD: dd.c,v 1.29 2024/07/12 14:30:27 deraadt Exp $ */ /* $NetBSD: dd.c,v 1.6 1996/02/20 19:29:06 jtc Exp $ */ /*- @@ -74,10 +74,10 @@ main(int argc, char *argv[]) jcl(argv); setup(); - (void)signal(SIGINFO, summaryx); - (void)signal(SIGINT, terminate); + (void)signal(SIGINFO, sig_summary); + (void)signal(SIGINT, sig_terminate); - atexit(summary); + atexit(exit_summary); if (cpy_cnt != (size_t)-1) { while (files_cnt--) @@ -265,7 +265,7 @@ dd_in(void) if (!(ddflags & C_NOERROR)) err(1, "%s", in.name); warn("%s", in.name); - summary(); + sig_summary(0); /* * If it's not a tape drive or a pipe, seek past the diff --git a/bin/dd/extern.h b/bin/dd/extern.h index 4b933ce2827..aff85daf021 100644 --- a/bin/dd/extern.h +++ b/bin/dd/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.9 2014/03/27 15:32:13 tedu Exp $ */ +/* $OpenBSD: extern.h,v 1.10 2024/07/12 14:30:27 deraadt Exp $ */ /* $NetBSD: extern.h,v 1.7 1996/02/20 19:29:07 jtc Exp $ */ /*- @@ -44,9 +44,9 @@ void def_close(void); void jcl(char **); void pos_in(void); void pos_out(void); -void summary(void); -void summaryx(int); -void terminate(int); +void exit_summary(void); +void sig_summary(int); +void sig_terminate(int); void unblock(void); void unblock_close(void); diff --git a/bin/dd/misc.c b/bin/dd/misc.c index ae64cea5d13..68afbeb9333 100644 --- a/bin/dd/misc.c +++ b/bin/dd/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.24 2024/07/12 07:22:44 deraadt Exp $ */ +/* $OpenBSD: misc.c,v 1.25 2024/07/12 14:30:27 deraadt Exp $ */ /* $NetBSD: misc.c,v 1.4 1995/03/21 09:04:10 cgd Exp $ */ /*- @@ -45,9 +45,11 @@ #include "dd.h" #include "extern.h" +/* SIGINFO handler */ void -summary(void) +sig_summary(int notused) { + int save_errno = errno; struct timespec elapsed, now; double nanosecs; @@ -79,20 +81,20 @@ summary(void) (long long)elapsed.tv_sec, elapsed.tv_nsec / 1000000, ((double)st.bytes * 1000000000) / nanosecs); } + errno = save_errno; } +/* SIGINT handler */ void -summaryx(int notused) +sig_terminate(int signo) { - int save_errno = errno; - - summary(); /* XXX signal race, dprintf floating point */ - errno = save_errno; + sig_summary(0); + _exit(128 + signo); } +/* atexit variation to summarize */ void -terminate(int signo) +exit_summary(void) { - summary(); /* XXX signal race, dprintf floating point */ - _exit(128 + signo); + sig_summary(0); } diff --git a/bin/dd/position.c b/bin/dd/position.c index ee8b039bdae..9e1b2ba0230 100644 --- a/bin/dd/position.c +++ b/bin/dd/position.c @@ -1,4 +1,4 @@ -/* $OpenBSD: position.c,v 1.11 2019/06/28 13:34:59 deraadt Exp $ */ +/* $OpenBSD: position.c,v 1.12 2024/07/12 14:30:27 deraadt Exp $ */ /* $NetBSD: position.c,v 1.4 1995/03/21 09:04:12 cgd Exp $ */ /*- @@ -103,7 +103,7 @@ pos_in(void) if (!warned) { warn("%s", in.name); warned = 1; - summary(); + sig_summary(0); } continue; }