summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2024-07-12 14:30:28 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2024-07-12 14:30:28 +0000
commitd3f1275fefb0ce5158cbe1cff64b9c026568721a (patch)
tree085cf76d7173047b5a1862f27d1d1cb276a169f7
parent545301fbad354cc0fa10e5231760ebb4613beaea (diff)
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
-rw-r--r--bin/dd/dd.c10
-rw-r--r--bin/dd/extern.h8
-rw-r--r--bin/dd/misc.c22
-rw-r--r--bin/dd/position.c4
4 files changed, 23 insertions, 21 deletions
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;
}