summaryrefslogtreecommitdiffstats
path: root/bin/dd/misc.c
diff options
context:
space:
mode:
authoreadler <eadler@FreeBSD.org>2013-05-10 18:43:36 +0000
committereadler <eadler@FreeBSD.org>2013-05-10 18:43:36 +0000
commit9f34a8fbd1042ff5b6aacf0953a19839a9d2f7b5 (patch)
tree70263e024132ba7c7573919f9f71f2103a1f1d06 /bin/dd/misc.c
parent6ea39edf934cff6ee443d1e0447b0081574612e5 (diff)
downloadFreeBSD-src-9f34a8fbd1042ff5b6aacf0953a19839a9d2f7b5.zip
FreeBSD-src-9f34a8fbd1042ff5b6aacf0953a19839a9d2f7b5.tar.gz
Make dd's signal handler async safe.
PR: bin/75258 Submitted by: "Oleg V. Nauman" <oleg@reis.zp.ua> Arrival Date: Sun Dec 19 14:50:21 GMT 2004 Reviewed by: mjg, jhb Reviewed by: jilles (earlier version) MFC after: 1 week
Diffstat (limited to 'bin/dd/misc.c')
-rw-r--r--bin/dd/misc.c28
1 files changed, 10 insertions, 18 deletions
diff --git a/bin/dd/misc.c b/bin/dd/misc.c
index 8edc5a5..84cc5ee 100644
--- a/bin/dd/misc.c
+++ b/bin/dd/misc.c
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <inttypes.h>
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -57,41 +58,32 @@ summary(void)
{
struct timeval tv;
double secs;
- char buf[100];
(void)gettimeofday(&tv, NULL);
secs = tv.tv_sec + tv.tv_usec * 1e-6 - st.start;
if (secs < 1e-6)
secs = 1e-6;
- /* Use snprintf(3) so that we don't reenter stdio(3). */
- (void)snprintf(buf, sizeof(buf),
+ (void)fprintf(stderr,
"%ju+%ju records in\n%ju+%ju records out\n",
st.in_full, st.in_part, st.out_full, st.out_part);
- (void)write(STDERR_FILENO, buf, strlen(buf));
- if (st.swab) {
- (void)snprintf(buf, sizeof(buf), "%ju odd length swab %s\n",
+ if (st.swab)
+ (void)fprintf(stderr, "%ju odd length swab %s\n",
st.swab, (st.swab == 1) ? "block" : "blocks");
- (void)write(STDERR_FILENO, buf, strlen(buf));
- }
- if (st.trunc) {
- (void)snprintf(buf, sizeof(buf), "%ju truncated %s\n",
+ if (st.trunc)
+ (void)fprintf(stderr, "%ju truncated %s\n",
st.trunc, (st.trunc == 1) ? "block" : "blocks");
- (void)write(STDERR_FILENO, buf, strlen(buf));
- }
- (void)snprintf(buf, sizeof(buf),
+ (void)fprintf(stderr,
"%ju bytes transferred in %.6f secs (%.0f bytes/sec)\n",
st.bytes, secs, st.bytes / secs);
- (void)write(STDERR_FILENO, buf, strlen(buf));
+ need_summary = 0;
}
/* ARGSUSED */
void
-summaryx(int notused __unused)
+siginfo_handler(int signo __unused)
{
- int save_errno = errno;
- summary();
- errno = save_errno;
+ need_summary = 1;
}
/* ARGSUSED */
OpenPOWER on IntegriCloud