FreeBSD Bugzilla – Attachment 194964 Details for
Bug 229615
[patch] bin/dd: add status=progress support
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch against CURRENT
dd-status-progress-current.patch (text/plain), 4.03 KB, created by
Thomas Hurst
on 2018-07-08 21:08:23 UTC
(
hide
)
Description:
Patch against CURRENT
Filename:
MIME Type:
Creator:
Thomas Hurst
Created:
2018-07-08 21:08:23 UTC
Size:
4.03 KB
patch
obsolete
>Index: args.c >=================================================================== >--- args.c (revision 336096) >+++ args.c (working copy) >@@ -306,6 +306,8 @@ > ddflags |= C_NOINFO; > else if (strcmp(arg, "noxfer") == 0) > ddflags |= C_NOXFER; >+ else if (strcmp(arg, "progress") == 0) >+ ddflags |= C_PROGRESS; > else > errx(1, "unknown status %s", arg); > } >Index: dd.1 >=================================================================== >--- dd.1 (revision 336096) >+++ dd.1 (working copy) >@@ -164,12 +164,14 @@ > Where > .Cm value > is one of the symbols from the following list. >-.Bl -tag -width "noxfer" >+.Bl -tag -width "progress" > .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; informational messages are not. >+.It Cm progress >+Print basic transfer statistics once per second. > .El > .It Cm conv Ns = Ns Ar value Ns Op , Ns Ar value ... > Where >Index: dd.c >=================================================================== >--- dd.c (revision 336096) >+++ dd.c (working copy) >@@ -54,6 +54,7 @@ > #include <sys/disklabel.h> > #include <sys/filio.h> > #include <sys/mtio.h> >+#include <sys/time.h> > > #include <assert.h> > #include <capsicum_helpers.h> >@@ -89,6 +90,7 @@ > char fill_char; /* Character to fill with if defined */ > size_t speed = 0; /* maximum speed, in bytes per second */ > volatile sig_atomic_t need_summary; >+volatile sig_atomic_t need_progress; > > int > main(int argc __unused, char *argv[]) >@@ -102,6 +104,7 @@ > err(1, "unable to enter capability mode"); > > (void)signal(SIGINFO, siginfo_handler); >+ (void)signal(SIGALRM, sigalrm_handler); > (void)signal(SIGINT, terminate); > > atexit(summary); >@@ -281,6 +284,14 @@ > ctab = casetab; > } > >+ if ((ddflags & C_PROGRESS)) { >+ struct itimerval timer = { >+ .it_interval = { .tv_sec = 1, .tv_usec = 0 }, >+ .it_value = { .tv_sec = 1, .tv_usec = 0 }, >+ }; >+ setitimer(ITIMER_REAL, &timer, NULL); >+ } >+ > if (clock_gettime(CLOCK_MONOTONIC, &st.start)) > err(1, "clock_gettime"); > } >@@ -461,6 +472,9 @@ > if (need_summary) { > summary(); > } >+ if (need_progress) { >+ progress(); >+ } > } > } > >Index: dd.h >=================================================================== >--- dd.h (revision 336096) >+++ dd.h (working copy) >@@ -100,5 +100,6 @@ > #define C_STATUS 0x08000000 > #define C_NOXFER 0x10000000 > #define C_NOINFO 0x20000000 >+#define C_PROGRESS 0x40000000 > > #define C_PARITY (C_PAREVEN | C_PARODD | C_PARNONE | C_PARSET) >Index: extern.h >=================================================================== >--- extern.h (revision 336096) >+++ extern.h (working copy) >@@ -46,7 +46,9 @@ > void pos_out(void); > double secs_elapsed(void); > void summary(void); >+void progress(void); > void siginfo_handler(int); >+void sigalrm_handler(int); > void terminate(int); > void unblock(void); > void unblock_close(void); >@@ -66,3 +68,4 @@ > extern u_char casetab[]; > extern char fill_char; > extern volatile sig_atomic_t need_summary; >+extern volatile sig_atomic_t need_progress; >Index: misc.c >=================================================================== >--- misc.c (revision 336096) >+++ misc.c (working copy) >@@ -56,6 +56,8 @@ > #include "dd.h" > #include "extern.h" > >+int need_newline = 0; >+ > double > secs_elapsed(void) > { >@@ -83,6 +85,9 @@ > if (ddflags & C_NOINFO) > return; > >+ if (need_newline && !need_summary) >+ fprintf(stderr, "\n"); >+ > secs = secs_elapsed(); > > (void)fprintf(stderr, >@@ -102,6 +107,29 @@ > need_summary = 0; > } > >+void >+progress(void) >+{ >+ double secs; >+ static int lastlen = 0; >+ >+ secs = secs_elapsed(); >+ >+ int len = fprintf(stderr, >+ "\r%ju bytes transferred in %.0f secs (%.0f bytes/sec)", >+ st.bytes, secs, st.bytes / secs); >+ >+ if (len > 0) >+ { >+ if (len < lastlen) >+ (void)fprintf(stderr, "%*s", len - lastlen, ""); >+ lastlen = len; >+ } >+ >+ need_newline = 1; >+ need_progress = 0; >+} >+ > /* ARGSUSED */ > void > siginfo_handler(int signo __unused) >@@ -112,6 +140,13 @@ > > /* ARGSUSED */ > void >+sigalrm_handler(int signo __unused) >+{ >+ need_progress = 1; >+} >+ >+/* ARGSUSED */ >+void > terminate(int sig) > { >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 229615
: 194964 |
194965