|
|
dd59ef |
From af2a4ed22594badd2719c0123441d69b17bd8328 Mon Sep 17 00:00:00 2001
|
|
|
dd59ef |
From: Federico Simoncelli <fsimonce@redhat.com>
|
|
|
dd59ef |
Date: Fri, 26 Sep 2014 17:12:32 +0000
|
|
|
dd59ef |
Subject: [PATCH] dd: new status=progress level to print stats periodically
|
|
|
dd59ef |
|
|
|
dd59ef |
* src/dd.c: Report the transfer progress every second when the
|
|
|
dd59ef |
new status=progress level is used. Adjust the handling and
|
|
|
dd59ef |
description of the status= option so that they're treated as
|
|
|
dd59ef |
mutually exclusive levels, rather than flags with implicit precedence.
|
|
|
dd59ef |
* doc/coreutils.texi (dd invocation): Document the new progress
|
|
|
dd59ef |
status level. Reference the new level in the description of SIGUSR1.
|
|
|
dd59ef |
* tests/dd/stats.sh: Add new test for status=progress.
|
|
|
dd59ef |
* tests/dd/misc.sh: Change so status=none only takes precedence
|
|
|
dd59ef |
if it's the last level specified.
|
|
|
dd59ef |
---
|
|
|
dd59ef |
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
|
|
|
dd59ef |
index 7d32af5..03bb710 100644
|
|
|
dd59ef |
--- a/doc/coreutils.texi
|
|
|
dd59ef |
+++ b/doc/coreutils.texi
|
|
|
dd59ef |
@@ -8631,24 +8631,32 @@ will ensure that @samp{count=} corresponds to complete input blocks
|
|
|
dd59ef |
rather than the traditional POSIX specified behavior of counting
|
|
|
dd59ef |
input read operations.
|
|
|
dd59ef |
|
|
|
dd59ef |
-@item status=@var{which}
|
|
|
dd59ef |
+@item status=@var{level}
|
|
|
dd59ef |
@opindex status
|
|
|
dd59ef |
Transfer information is normally output to stderr upon
|
|
|
dd59ef |
receipt of the @samp{INFO} signal or when @command{dd} exits.
|
|
|
dd59ef |
-Specifying @var{which} will identify which information to suppress.
|
|
|
dd59ef |
+Specifying @var{level} will adjust the amount of information printed,
|
|
|
dd59ef |
+with the last @var{level} specified taking precedence.
|
|
|
dd59ef |
|
|
|
dd59ef |
@table @samp
|
|
|
dd59ef |
|
|
|
dd59ef |
-@item noxfer
|
|
|
dd59ef |
-@opindex noxfer @r{dd status=}
|
|
|
dd59ef |
-Do not print the transfer rate and volume statistics
|
|
|
dd59ef |
-that normally make up the last status line.
|
|
|
dd59ef |
-
|
|
|
dd59ef |
@item none
|
|
|
dd59ef |
@opindex none @r{dd status=}
|
|
|
dd59ef |
Do not print any informational or warning messages to stderr.
|
|
|
dd59ef |
Error messages are output as normal.
|
|
|
dd59ef |
|
|
|
dd59ef |
+@item noxfer
|
|
|
dd59ef |
+@opindex noxfer @r{dd status=}
|
|
|
dd59ef |
+Do not print the final transfer rate and volume statistics
|
|
|
dd59ef |
+that normally make up the last status line.
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+@item progress
|
|
|
dd59ef |
+@opindex progress @r{dd status=}
|
|
|
dd59ef |
+Print the transfer rate and volume statistics on stderr,
|
|
|
dd59ef |
+when processing each input block. Statistics are output
|
|
|
dd59ef |
+on a single line at most once every second, but updates
|
|
|
dd59ef |
+can be delayed when waiting on I/O.
|
|
|
dd59ef |
+
|
|
|
dd59ef |
@end table
|
|
|
dd59ef |
|
|
|
dd59ef |
@item conv=@var{conversion}[,@var{conversion}]@dots{}
|
|
|
dd59ef |
@@ -9033,6 +9041,9 @@ The above script will output in the following format
|
|
|
dd59ef |
5120000000 bytes (5.1 GB) copied, 18.913 seconds, 271 MB/s
|
|
|
dd59ef |
@end example
|
|
|
dd59ef |
|
|
|
dd59ef |
+Note also the @samp{status=progress} option which periodically updates
|
|
|
dd59ef |
+the last line of the transfer statistics above.
|
|
|
dd59ef |
+
|
|
|
dd59ef |
@vindex POSIXLY_CORRECT
|
|
|
dd59ef |
On systems lacking the @samp{INFO} signal @command{dd} responds to the
|
|
|
dd59ef |
@samp{USR1} signal instead, unless the @env{POSIXLY_CORRECT}
|
|
|
dd59ef |
diff --git a/src/dd.c b/src/dd.c
|
|
|
dd59ef |
index d22ec59..4018190 100644
|
|
|
dd59ef |
--- a/src/dd.c
|
|
|
dd59ef |
+++ b/src/dd.c
|
|
|
dd59ef |
@@ -34,6 +34,7 @@
|
|
|
dd59ef |
#include "long-options.h"
|
|
|
dd59ef |
#include "quote.h"
|
|
|
dd59ef |
#include "quotearg.h"
|
|
|
dd59ef |
+#include "verror.h"
|
|
|
dd59ef |
#include "xstrtol.h"
|
|
|
dd59ef |
#include "xtime.h"
|
|
|
dd59ef |
|
|
|
dd59ef |
@@ -132,11 +133,13 @@ enum
|
|
|
dd59ef |
C_SPARSE = 0200000
|
|
|
dd59ef |
};
|
|
|
dd59ef |
|
|
|
dd59ef |
-/* Status bit masks. */
|
|
|
dd59ef |
+/* Status levels. */
|
|
|
dd59ef |
enum
|
|
|
dd59ef |
{
|
|
|
dd59ef |
- STATUS_NOXFER = 01,
|
|
|
dd59ef |
- STATUS_NONE = 02
|
|
|
dd59ef |
+ STATUS_NONE = 1,
|
|
|
dd59ef |
+ STATUS_NOXFER = 2,
|
|
|
dd59ef |
+ STATUS_DEFAULT = 3,
|
|
|
dd59ef |
+ STATUS_PROGRESS = 4
|
|
|
dd59ef |
};
|
|
|
dd59ef |
|
|
|
dd59ef |
/* The name of the input file, or NULL for the standard input. */
|
|
|
dd59ef |
@@ -188,7 +191,7 @@ static int input_flags = 0;
|
|
|
dd59ef |
static int output_flags = 0;
|
|
|
dd59ef |
|
|
|
dd59ef |
/* Status flags for what is printed to stderr. */
|
|
|
dd59ef |
-static int status_flags = 0;
|
|
|
dd59ef |
+static int status_level = STATUS_DEFAULT;
|
|
|
dd59ef |
|
|
|
dd59ef |
/* If nonzero, filter characters through the translation table. */
|
|
|
dd59ef |
static bool translation_needed = false;
|
|
|
dd59ef |
@@ -211,6 +214,12 @@ static uintmax_t w_bytes = 0;
|
|
|
dd59ef |
/* Time that dd started. */
|
|
|
dd59ef |
static xtime_t start_time;
|
|
|
dd59ef |
|
|
|
dd59ef |
+/* Previous time for periodic progress. */
|
|
|
dd59ef |
+static xtime_t previous_time;
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+/* Whether a '\n' is pending after writing progress. */
|
|
|
dd59ef |
+static bool newline_pending;
|
|
|
dd59ef |
+
|
|
|
dd59ef |
/* True if input is seekable. */
|
|
|
dd59ef |
static bool input_seekable;
|
|
|
dd59ef |
|
|
|
dd59ef |
@@ -373,8 +382,9 @@ static struct symbol_value const flags[] =
|
|
|
dd59ef |
/* Status, for status="...". */
|
|
|
dd59ef |
static struct symbol_value const statuses[] =
|
|
|
dd59ef |
{
|
|
|
dd59ef |
- {"noxfer", STATUS_NOXFER},
|
|
|
dd59ef |
{"none", STATUS_NONE},
|
|
|
dd59ef |
+ {"noxfer", STATUS_NOXFER},
|
|
|
dd59ef |
+ {"progress", STATUS_PROGRESS},
|
|
|
dd59ef |
{"", 0}
|
|
|
dd59ef |
};
|
|
|
dd59ef |
|
|
|
dd59ef |
@@ -517,6 +527,25 @@ maybe_close_stdout (void)
|
|
|
dd59ef |
_exit (EXIT_FAILURE);
|
|
|
dd59ef |
}
|
|
|
dd59ef |
|
|
|
dd59ef |
+/* Like error() but handle any pending newline. */
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+static void _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4))
|
|
|
dd59ef |
+nl_error (int status, int errnum, const char *fmt, ...)
|
|
|
dd59ef |
+{
|
|
|
dd59ef |
+ if (newline_pending)
|
|
|
dd59ef |
+ {
|
|
|
dd59ef |
+ fputc ('\n', stderr);
|
|
|
dd59ef |
+ newline_pending = false;
|
|
|
dd59ef |
+ }
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ va_list ap;
|
|
|
dd59ef |
+ va_start (ap, fmt);
|
|
|
dd59ef |
+ verror (status, errnum, fmt, ap);
|
|
|
dd59ef |
+ va_end (ap);
|
|
|
dd59ef |
+}
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+#define error nl_error
|
|
|
dd59ef |
+
|
|
|
dd59ef |
void
|
|
|
dd59ef |
usage (int status)
|
|
|
dd59ef |
{
|
|
|
dd59ef |
@@ -546,8 +575,10 @@ Copy a file, converting and formatting according to the operands.\n\
|
|
|
dd59ef |
oflag=FLAGS write as per the comma separated symbol list\n\
|
|
|
dd59ef |
seek=N skip N obs-sized blocks at start of output\n\
|
|
|
dd59ef |
skip=N skip N ibs-sized blocks at start of input\n\
|
|
|
dd59ef |
- status=WHICH WHICH info to suppress outputting to stderr;\n\
|
|
|
dd59ef |
- 'noxfer' suppresses transfer stats, 'none' suppresses all\n\
|
|
|
dd59ef |
+ status=LEVEL The LEVEL of information to print to stderr;\n\
|
|
|
dd59ef |
+ 'none' suppresses everything but error messages,\n\
|
|
|
dd59ef |
+ 'noxfer' suppresses the final transfer statistics,\n\
|
|
|
dd59ef |
+ 'progress' shows periodic transfer statistics\n\
|
|
|
dd59ef |
"), stdout);
|
|
|
dd59ef |
fputs (_("\
|
|
|
dd59ef |
\n\
|
|
|
dd59ef |
@@ -724,8 +755,7 @@ multiple_bits_set (int i)
|
|
|
dd59ef |
/* Print transfer statistics. */
|
|
|
dd59ef |
|
|
|
dd59ef |
static void
|
|
|
dd59ef |
-print_stats (void)
|
|
|
dd59ef |
-{
|
|
|
dd59ef |
+print_xfer_stats (xtime_t progress_time) {
|
|
|
dd59ef |
char hbuf[LONGEST_HUMAN_READABLE + 1];
|
|
|
dd59ef |
int human_opts =
|
|
|
dd59ef |
(human_autoscale | human_round_to_nearest
|
|
|
dd59ef |
@@ -733,23 +763,8 @@ print_stats (void)
|
|
|
dd59ef |
double delta_s;
|
|
|
dd59ef |
char const *bytes_per_second;
|
|
|
dd59ef |
|
|
|
dd59ef |
- if (status_flags & STATUS_NONE)
|
|
|
dd59ef |
- return;
|
|
|
dd59ef |
-
|
|
|
dd59ef |
- fprintf (stderr,
|
|
|
dd59ef |
- _("%"PRIuMAX"+%"PRIuMAX" records in\n"
|
|
|
dd59ef |
- "%"PRIuMAX"+%"PRIuMAX" records out\n"),
|
|
|
dd59ef |
- r_full, r_partial, w_full, w_partial);
|
|
|
dd59ef |
-
|
|
|
dd59ef |
- if (r_truncate != 0)
|
|
|
dd59ef |
- fprintf (stderr,
|
|
|
dd59ef |
- ngettext ("%"PRIuMAX" truncated record\n",
|
|
|
dd59ef |
- "%"PRIuMAX" truncated records\n",
|
|
|
dd59ef |
- select_plural (r_truncate)),
|
|
|
dd59ef |
- r_truncate);
|
|
|
dd59ef |
-
|
|
|
dd59ef |
- if (status_flags & STATUS_NOXFER)
|
|
|
dd59ef |
- return;
|
|
|
dd59ef |
+ if (progress_time)
|
|
|
dd59ef |
+ fputc ('\r', stderr);
|
|
|
dd59ef |
|
|
|
dd59ef |
/* Use integer arithmetic to compute the transfer rate,
|
|
|
dd59ef |
since that makes it easy to use SI abbreviations. */
|
|
|
dd59ef |
@@ -761,7 +776,8 @@ print_stats (void)
|
|
|
dd59ef |
w_bytes,
|
|
|
dd59ef |
human_readable (w_bytes, hbuf, human_opts, 1, 1));
|
|
|
dd59ef |
|
|
|
dd59ef |
- xtime_t now = gethrxtime ();
|
|
|
dd59ef |
+ xtime_t now = progress_time ? progress_time : gethrxtime ();
|
|
|
dd59ef |
+
|
|
|
dd59ef |
if (start_time < now)
|
|
|
dd59ef |
{
|
|
|
dd59ef |
double XTIME_PRECISIONe0 = XTIME_PRECISION;
|
|
|
dd59ef |
@@ -787,7 +803,42 @@ print_stats (void)
|
|
|
dd59ef |
but that was incorrect for languages like Polish. To fix this
|
|
|
dd59ef |
bug we now use SI symbols even though they're a bit more
|
|
|
dd59ef |
confusing in English. */
|
|
|
dd59ef |
- fprintf (stderr, _(", %g s, %s/s\n"), delta_s, bytes_per_second);
|
|
|
dd59ef |
+ char const *time_fmt = _(", %g s, %s/s\n");;
|
|
|
dd59ef |
+ if (progress_time)
|
|
|
dd59ef |
+ time_fmt = _(", %.6f s, %s/s"); /* OK with '\r' as increasing width. */
|
|
|
dd59ef |
+ fprintf (stderr, time_fmt, delta_s, bytes_per_second);
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ newline_pending = !!progress_time;
|
|
|
dd59ef |
+}
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+static void
|
|
|
dd59ef |
+print_stats (void)
|
|
|
dd59ef |
+{
|
|
|
dd59ef |
+ if (status_level == STATUS_NONE)
|
|
|
dd59ef |
+ return;
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ if (newline_pending)
|
|
|
dd59ef |
+ {
|
|
|
dd59ef |
+ fputc ('\n', stderr);
|
|
|
dd59ef |
+ newline_pending = false;
|
|
|
dd59ef |
+ }
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ fprintf (stderr,
|
|
|
dd59ef |
+ _("%"PRIuMAX"+%"PRIuMAX" records in\n"
|
|
|
dd59ef |
+ "%"PRIuMAX"+%"PRIuMAX" records out\n"),
|
|
|
dd59ef |
+ r_full, r_partial, w_full, w_partial);
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ if (r_truncate != 0)
|
|
|
dd59ef |
+ fprintf (stderr,
|
|
|
dd59ef |
+ ngettext ("%"PRIuMAX" truncated record\n",
|
|
|
dd59ef |
+ "%"PRIuMAX" truncated records\n",
|
|
|
dd59ef |
+ select_plural (r_truncate)),
|
|
|
dd59ef |
+ r_truncate);
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ if (status_level == STATUS_NOXFER)
|
|
|
dd59ef |
+ return;
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ print_xfer_stats (0);
|
|
|
dd59ef |
}
|
|
|
dd59ef |
|
|
|
dd59ef |
/* An ordinary signal was received; arrange for the program to exit. */
|
|
|
dd59ef |
@@ -1035,7 +1086,7 @@ iread (int fd, char *buf, size_t size)
|
|
|
dd59ef |
if (0 < prev_nread && prev_nread < size)
|
|
|
dd59ef |
{
|
|
|
dd59ef |
uintmax_t prev = prev_nread;
|
|
|
dd59ef |
- if (!(status_flags & STATUS_NONE))
|
|
|
dd59ef |
+ if (status_level != STATUS_NONE)
|
|
|
dd59ef |
error (0, 0, ngettext (("warning: partial read (%"PRIuMAX" byte); "
|
|
|
dd59ef |
"suggest iflag=fullblock"),
|
|
|
dd59ef |
("warning: partial read (%"PRIuMAX" bytes); "
|
|
|
dd59ef |
@@ -1086,7 +1137,7 @@ iwrite (int fd, char const *buf, size_t size)
|
|
|
dd59ef |
{
|
|
|
dd59ef |
int old_flags = fcntl (STDOUT_FILENO, F_GETFL);
|
|
|
dd59ef |
if (fcntl (STDOUT_FILENO, F_SETFL, old_flags & ~O_DIRECT) != 0
|
|
|
dd59ef |
- && !(status_flags & STATUS_NONE))
|
|
|
dd59ef |
+ && status_level != STATUS_NONE)
|
|
|
dd59ef |
error (0, errno, _("failed to turn off O_DIRECT: %s"),
|
|
|
dd59ef |
quote (output_file));
|
|
|
dd59ef |
|
|
|
dd59ef |
@@ -1219,7 +1270,7 @@ operand_matches (char const *str, char const *pattern, char delim)
|
|
|
dd59ef |
|
|
|
dd59ef |
static int
|
|
|
dd59ef |
parse_symbols (char const *str, struct symbol_value const *table,
|
|
|
dd59ef |
- char const *error_msgid)
|
|
|
dd59ef |
+ bool exclusive, char const *error_msgid)
|
|
|
dd59ef |
{
|
|
|
dd59ef |
int value = 0;
|
|
|
dd59ef |
|
|
|
dd59ef |
@@ -1241,7 +1292,10 @@ parse_symbols (char const *str, struct symbol_value const *table,
|
|
|
dd59ef |
}
|
|
|
dd59ef |
}
|
|
|
dd59ef |
|
|
|
dd59ef |
- value |= entry->value;
|
|
|
dd59ef |
+ if (exclusive)
|
|
|
dd59ef |
+ value = entry->value;
|
|
|
dd59ef |
+ else
|
|
|
dd59ef |
+ value |= entry->value;
|
|
|
dd59ef |
if (!strcomma)
|
|
|
dd59ef |
break;
|
|
|
dd59ef |
str = strcomma + 1;
|
|
|
dd59ef |
@@ -1316,17 +1370,17 @@ scanargs (int argc, char *const *argv)
|
|
|
dd59ef |
else if (operand_is (name, "of"))
|
|
|
dd59ef |
output_file = val;
|
|
|
dd59ef |
else if (operand_is (name, "conv"))
|
|
|
dd59ef |
- conversions_mask |= parse_symbols (val, conversions,
|
|
|
dd59ef |
+ conversions_mask |= parse_symbols (val, conversions, false,
|
|
|
dd59ef |
N_("invalid conversion"));
|
|
|
dd59ef |
else if (operand_is (name, "iflag"))
|
|
|
dd59ef |
- input_flags |= parse_symbols (val, flags,
|
|
|
dd59ef |
+ input_flags |= parse_symbols (val, flags, false,
|
|
|
dd59ef |
N_("invalid input flag"));
|
|
|
dd59ef |
else if (operand_is (name, "oflag"))
|
|
|
dd59ef |
- output_flags |= parse_symbols (val, flags,
|
|
|
dd59ef |
+ output_flags |= parse_symbols (val, flags, false,
|
|
|
dd59ef |
N_("invalid output flag"));
|
|
|
dd59ef |
else if (operand_is (name, "status"))
|
|
|
dd59ef |
- status_flags |= parse_symbols (val, statuses,
|
|
|
dd59ef |
- N_("invalid status flag"));
|
|
|
dd59ef |
+ status_level = parse_symbols (val, statuses, true,
|
|
|
dd59ef |
+ N_("invalid status level"));
|
|
|
dd59ef |
else
|
|
|
dd59ef |
{
|
|
|
dd59ef |
bool invalid = false;
|
|
|
dd59ef |
@@ -1613,7 +1667,7 @@ skip_via_lseek (char const *filename, int fdesc, off_t offset, int whence)
|
|
|
dd59ef |
&& ioctl (fdesc, MTIOCGET, &s2) == 0
|
|
|
dd59ef |
&& MT_SAME_POSITION (s1, s2))
|
|
|
dd59ef |
{
|
|
|
dd59ef |
- if (!(status_flags & STATUS_NONE))
|
|
|
dd59ef |
+ if (status_level != STATUS_NONE)
|
|
|
dd59ef |
error (0, 0, _("warning: working around lseek kernel bug for file "
|
|
|
dd59ef |
"(%s)\n of mt_type=0x%0lx -- "
|
|
|
dd59ef |
"see <sys/mtio.h> for the list of types"),
|
|
|
dd59ef |
@@ -1787,7 +1841,7 @@ advance_input_after_read_error (size_t nbytes)
|
|
|
dd59ef |
if (offset == input_offset)
|
|
|
dd59ef |
return true;
|
|
|
dd59ef |
diff = input_offset - offset;
|
|
|
dd59ef |
- if (! (0 <= diff && diff <= nbytes) && !(status_flags & STATUS_NONE))
|
|
|
dd59ef |
+ if (! (0 <= diff && diff <= nbytes) && status_level != STATUS_NONE)
|
|
|
dd59ef |
error (0, 0, _("warning: invalid file offset after failed read"));
|
|
|
dd59ef |
if (0 <= skip_via_lseek (input_file, STDIN_FILENO, diff, SEEK_CUR))
|
|
|
dd59ef |
return true;
|
|
|
dd59ef |
@@ -1986,7 +2040,7 @@ dd_copy (void)
|
|
|
dd59ef |
2. pipe has not enough data
|
|
|
dd59ef |
3. partial reads */
|
|
|
dd59ef |
if ((us_blocks || (!input_offset_overflow && us_bytes))
|
|
|
dd59ef |
- && !(status_flags & STATUS_NONE))
|
|
|
dd59ef |
+ && status_level != STATUS_NONE)
|
|
|
dd59ef |
{
|
|
|
dd59ef |
error (0, 0,
|
|
|
dd59ef |
_("%s: cannot skip to specified offset"), quote (input_file));
|
|
|
dd59ef |
@@ -2029,6 +2083,19 @@ dd_copy (void)
|
|
|
dd59ef |
|
|
|
dd59ef |
while (1)
|
|
|
dd59ef |
{
|
|
|
dd59ef |
+ if (status_level == STATUS_PROGRESS)
|
|
|
dd59ef |
+ {
|
|
|
dd59ef |
+ xtime_t progress_time = gethrxtime ();
|
|
|
dd59ef |
+ uintmax_t delta_xtime = progress_time;
|
|
|
dd59ef |
+ delta_xtime -= previous_time;
|
|
|
dd59ef |
+ double XTIME_PRECISIONe0 = XTIME_PRECISION;
|
|
|
dd59ef |
+ if (delta_xtime / XTIME_PRECISIONe0 > 1)
|
|
|
dd59ef |
+ {
|
|
|
dd59ef |
+ print_xfer_stats (progress_time);
|
|
|
dd59ef |
+ previous_time = progress_time;
|
|
|
dd59ef |
+ }
|
|
|
dd59ef |
+ }
|
|
|
dd59ef |
+
|
|
|
dd59ef |
if (r_partial + r_full >= max_records + !!max_bytes)
|
|
|
dd59ef |
break;
|
|
|
dd59ef |
|
|
|
dd59ef |
@@ -2053,7 +2120,7 @@ dd_copy (void)
|
|
|
dd59ef |
|
|
|
dd59ef |
if (nread < 0)
|
|
|
dd59ef |
{
|
|
|
dd59ef |
- if (!(conversions_mask & C_NOERROR) || !(status_flags & STATUS_NONE))
|
|
|
dd59ef |
+ if (!(conversions_mask & C_NOERROR) || status_level != STATUS_NONE)
|
|
|
dd59ef |
error (0, errno, _("error reading %s"), quote (input_file));
|
|
|
dd59ef |
|
|
|
dd59ef |
if (conversions_mask & C_NOERROR)
|
|
|
dd59ef |
@@ -2345,7 +2412,7 @@ main (int argc, char **argv)
|
|
|
dd59ef |
}
|
|
|
dd59ef |
}
|
|
|
dd59ef |
|
|
|
dd59ef |
- start_time = gethrxtime ();
|
|
|
dd59ef |
+ start_time = previous_time = gethrxtime ();
|
|
|
dd59ef |
|
|
|
dd59ef |
exit_status = dd_copy ();
|
|
|
dd59ef |
|
|
|
dd59ef |
diff --git a/tests/dd/misc.sh b/tests/dd/misc.sh
|
|
|
dd59ef |
index f877fdd..34dfba7 100755
|
|
|
dd59ef |
--- a/tests/dd/misc.sh
|
|
|
dd59ef |
+++ b/tests/dd/misc.sh
|
|
|
dd59ef |
@@ -35,9 +35,12 @@ dd status=none if=$tmp_in of=/dev/null 2> err || fail=1
|
|
|
dd59ef |
test -s err && { cat err; fail=1; }
|
|
|
dd59ef |
dd status=none if=$tmp_in skip=2 of=/dev/null 2> err || fail=1
|
|
|
dd59ef |
test -s err && { cat err; fail=1; }
|
|
|
dd59ef |
-# check status=none is cumulative with status=noxfer
|
|
|
dd59ef |
-dd status=none status=noxfer if=$tmp_in of=/dev/null 2> err || fail=1
|
|
|
dd59ef |
+# check later status=none overrides earlier status=noxfer
|
|
|
dd59ef |
+dd status=noxfer status=none if=$tmp_in of=/dev/null 2> err || fail=1
|
|
|
dd59ef |
test -s err && { cat err; fail=1; }
|
|
|
dd59ef |
+# check later status=noxfer overrides earlier status=none
|
|
|
dd59ef |
+dd status=none status=noxfer if=$tmp_in of=/dev/null 2> err || fail=1
|
|
|
dd59ef |
+compare /dev/null err && fail=1
|
|
|
dd59ef |
|
|
|
dd59ef |
dd if=$tmp_in of=$tmp_out 2> /dev/null || fail=1
|
|
|
dd59ef |
compare $tmp_in $tmp_out || fail=1
|
|
|
dd59ef |
diff --git a/tests/dd/stats.sh b/tests/dd/stats.sh
|
|
|
dd59ef |
new file mode 100755
|
|
|
dd59ef |
index 0000000..24b8c49 100755
|
|
|
dd59ef |
--- /dev/null
|
|
|
dd59ef |
+++ b/tests/dd/stats.sh
|
|
|
dd59ef |
@@ -0,0 +1,65 @@
|
|
|
dd59ef |
+#!/bin/sh
|
|
|
dd59ef |
+# Check stats output for SIG{INFO,USR1} and status=progress
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+# Copyright (C) 2014 Free Software Foundation, Inc.
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+# This program is free software: you can redistribute it and/or modify
|
|
|
dd59ef |
+# it under the terms of the GNU General Public License as published by
|
|
|
dd59ef |
+# the Free Software Foundation, either version 3 of the License, or
|
|
|
dd59ef |
+# (at your option) any later version.
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+# This program is distributed in the hope that it will be useful,
|
|
|
dd59ef |
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
dd59ef |
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
dd59ef |
+# GNU General Public License for more details.
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+# You should have received a copy of the GNU General Public License
|
|
|
dd59ef |
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
|
|
|
dd59ef |
+print_ver_ dd
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+env kill -l | grep '^INFO$' && SIGINFO='INFO' || SIGINFO='USR1'
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+# This to avoid races in the USR1 case
|
|
|
dd59ef |
+# as the dd process will terminate by default until
|
|
|
dd59ef |
+# it has its handler enabled.
|
|
|
dd59ef |
+trap '' $SIGINFO
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+mkfifo_or_skip_ fifo
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+for open in '' '1'; do
|
|
|
dd59ef |
+ # Run dd with the fullblock iflag to avoid short reads
|
|
|
dd59ef |
+ # which can be triggered by reception of signals
|
|
|
dd59ef |
+ dd iflag=fullblock if=/dev/zero of=fifo count=100 bs=5000000 2>err & pid=$!
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ # Note if we sleep here we give dd a chance to exec and block on open.
|
|
|
dd59ef |
+ # Otherwise we're probably testing SIG_IGN in the forked shell or early dd.
|
|
|
dd59ef |
+ test "$open" && sleep .1
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ # dd will block on open until fifo is opened for reading.
|
|
|
dd59ef |
+ # Timeout in case dd goes away erroneously which we check for below.
|
|
|
dd59ef |
+ timeout 10 sh -c 'wc -c < fifo > nwritten' &
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ # Send lots of signals immediately to ensure dd not killed due
|
|
|
dd59ef |
+ # to race setting handler, or blocking on open of fifo.
|
|
|
dd59ef |
+ # Many signals also check that short reads are handled.
|
|
|
dd59ef |
+ until ! kill -s $SIGINFO $pid 2>/dev/null; do
|
|
|
dd59ef |
+ sleep .01
|
|
|
dd59ef |
+ done
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ wait
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+ # Ensure all data processed and at least last status written
|
|
|
dd59ef |
+ grep '500000000 bytes .* copied' err || { cat err; fail=1; }
|
|
|
dd59ef |
+done
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+progress_output()
|
|
|
dd59ef |
+{
|
|
|
dd59ef |
+ { sleep "$1"; echo 1; } | dd bs=1 status=progress of=/dev/null 2>err
|
|
|
dd59ef |
+ # Progress output should be for "byte ... copied", while final is "bytes ..."
|
|
|
dd59ef |
+ grep 'byte .* copied' err
|
|
|
dd59ef |
+}
|
|
|
dd59ef |
+retry_delay_ progress_output 1 4 || { cat err; fail=1; }
|
|
|
dd59ef |
+
|
|
|
dd59ef |
+Exit $fail
|
|
|
dd59ef |
--
|
|
|
dd59ef |
cgit v0.9.0.2
|