Hi,

Our dd always prints these status lines to stderr after transfer.  
2+0 records in
2+0 records out
1024 bytes transferred in 0.000 secs (39384615 bytes/sec)

The output is annoying in some situations, so people redirect stderr
to /dev/null.  This approach also suppresses the error messages and
bugs in shell scripts remain undetected.

GNU dd has the status=noxfer and status=none switch to make it
quiet.  Their status=none disables some more warnings, we can add
that later if we want.

I would like to get rid of some 2>/dev/null.
Do we want the status=... feature in OpenBSD?

bluhm

Index: bin/dd/args.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/bin/dd/args.c,v
retrieving revision 1.21
diff -u -p -u -p -r1.21 args.c
--- bin/dd/args.c       11 Nov 2013 23:07:28 -0000      1.21
+++ bin/dd/args.c       9 Feb 2014 09:21:54 -0000
@@ -59,6 +59,7 @@ static void   f_obs(char *);
 static void    f_of(char *);
 static void    f_seek(char *);
 static void    f_skip(char *);
+static void    f_status(char *);
 static size_t  get_bsz(char *);
 static off_t   get_off(char *);
 
@@ -78,6 +79,7 @@ static const struct arg {
        { "of",         f_of,           C_OF,    C_OF },
        { "seek",       f_seek,         C_SEEK,  C_SEEK },
        { "skip",       f_skip,         C_SKIP,  C_SKIP },
+       { "status",     f_status,       C_STATUS,C_STATUS },
 };
 
 static char *oper;
@@ -247,6 +249,18 @@ f_skip(char *arg)
 {
 
        in.offset = get_off(arg);
+}
+
+static void
+f_status(char *arg)
+{
+
+       if (strcmp(arg, "none") == 0)
+               ddflags |= C_NOINFO;
+       else if (strcmp(arg, "noxfer") == 0)
+               ddflags |= C_NOXFER;
+       else
+               errx(1, "unknown status %s", arg);
 }
 
 
Index: bin/dd/dd.1
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/bin/dd/dd.1,v
retrieving revision 1.26
diff -u -p -u -p -r1.26 dd.1
--- bin/dd/dd.1 2 Feb 2014 22:43:40 -0000       1.26
+++ bin/dd/dd.1 9 Feb 2014 09:56:55 -0000
@@ -139,6 +139,21 @@ For all other devices, the correct numbe
 distinguishing between a partial or complete block being read.
 .It Xo
 .Sm off
+.Cm status= Ar value
+.Sm on
+.Xc
+Where
+.Ar value
+is one of the symbols from the following list.
+.Bl -tag -width unblock
+.It Cm noxfer
+Do not print the transfer statistics as the last line of status output.
+.It Cm none
+Do not print the status output.
+Error messages are shown, but no informational messages.
+.El
+.It Xo
+.Sm off
 .Cm conv= Ar value Oo ,
 .Sm on
 .Ar value ... Oc
Index: bin/dd/dd.h
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/bin/dd/dd.h,v
retrieving revision 1.5
diff -u -p -u -p -r1.5 dd.h
--- bin/dd/dd.h 2 Jun 2003 23:32:07 -0000       1.5
+++ bin/dd/dd.h 9 Feb 2014 09:16:03 -0000
@@ -93,3 +93,6 @@ typedef struct {
 #define        C_UCASE         0x40000
 #define        C_UNBLOCK       0x80000
 #define        C_OSYNC         0x100000
+#define        C_STATUS        0x200000
+#define        C_NOXFER        0x400000
+#define        C_NOINFO        0x800000
Index: bin/dd/misc.c
===================================================================
RCS file: /data/mirror/openbsd/cvs/src/bin/dd/misc.c,v
retrieving revision 1.17
diff -u -p -u -p -r1.17 misc.c
--- bin/dd/misc.c       16 Apr 2013 22:13:43 -0000      1.17
+++ bin/dd/misc.c       9 Feb 2014 09:27:25 -0000
@@ -58,6 +58,9 @@ summary(void)
        double microsecs;
        int i = 0;
 
+       if (ddflags & C_NOINFO)
+               return;
+
        (void)gettimeofday(&nowtv, (struct timezone *)NULL);
        timersub(&nowtv, &st.startv, &nowtv);
        microsecs = ((double)nowtv.tv_sec * 1000000) + nowtv.tv_usec;
@@ -85,13 +88,15 @@ summary(void)
                iov[i].iov_base = buf[2];
                iov[i++].iov_len = strlen(buf[2]);
        }
-       (void)snprintf(buf[3], sizeof(buf[3]),
-           "%qd bytes transferred in %lld.%03ld secs (%0.0f bytes/sec)\n",
-           (long long)st.bytes, (long long)nowtv.tv_sec, nowtv.tv_usec / 1000,
-           ((double)st.bytes * 1000000) / microsecs);
-
-       iov[i].iov_base = buf[3];
-       iov[i++].iov_len = strlen(buf[3]);
+       if (!(ddflags & C_NOXFER)) {
+               (void)snprintf(buf[3], sizeof(buf[3]),
+                   "%qd bytes transferred in %lld.%03ld secs "
+                   "(%0.0f bytes/sec)\n", (long long)st.bytes,
+                   (long long)nowtv.tv_sec, nowtv.tv_usec / 1000,
+                   ((double)st.bytes * 1000000) / microsecs);
+               iov[i].iov_base = buf[3];
+               iov[i++].iov_len = strlen(buf[3]);
+       }
 
        (void)writev(STDERR_FILENO, iov, i);
 }

Reply via email to