From owner-svn-src-stable@freebsd.org Wed Aug 29 02:18:16 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0747B109E005; Wed, 29 Aug 2018 02:18:16 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A4E1A771B7; Wed, 29 Aug 2018 02:18:15 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7FA0E16E20; Wed, 29 Aug 2018 02:18:15 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7T2IFNr045256; Wed, 29 Aug 2018 02:18:15 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7T2IDFt045248; Wed, 29 Aug 2018 02:18:13 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808290218.w7T2IDFt045248@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Wed, 29 Aug 2018 02:18:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r338364 - stable/11/bin/dd X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: stable/11/bin/dd X-SVN-Commit-Revision: 338364 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Aug 2018 02:18:16 -0000 Author: kevans Date: Wed Aug 29 02:18:13 2018 New Revision: 338364 URL: https://svnweb.freebsd.org/changeset/base/338364 Log: MFC r337505, r337865, r337869: dd status=progress r337505: dd: add status=progress support This reports the current status on a single line every second, mirroring similar functionality in GNU dd, and carefully interacts with SIGINFO. PR: 229615 r337865: dd: Incorporate some changes from imp for status=progress Notable changes from what landed in r337505: - sigalarm handler isn't setup unless we're actually using it - Humanized versions of the amount of data transferred in the progress update r337869: dd(1): Kill off duplicate progress definition following r337865 Modified: stable/11/bin/dd/Makefile stable/11/bin/dd/args.c stable/11/bin/dd/dd.1 stable/11/bin/dd/dd.c stable/11/bin/dd/dd.h stable/11/bin/dd/extern.h stable/11/bin/dd/misc.c stable/11/bin/dd/position.c Directory Properties: stable/11/ (props changed) Modified: stable/11/bin/dd/Makefile ============================================================================== --- stable/11/bin/dd/Makefile Tue Aug 28 23:56:52 2018 (r338363) +++ stable/11/bin/dd/Makefile Wed Aug 29 02:18:13 2018 (r338364) @@ -6,6 +6,7 @@ PACKAGE=runtime PROG= dd SRCS= args.c conv.c conv_tab.c dd.c misc.c position.c +LIBADD= util # # Test the character conversion functions. We have to be explicit about Modified: stable/11/bin/dd/args.c ============================================================================== --- stable/11/bin/dd/args.c Tue Aug 28 23:56:52 2018 (r338363) +++ stable/11/bin/dd/args.c Wed Aug 29 02:18:13 2018 (r338364) @@ -303,6 +303,8 @@ f_status(char *arg) 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); } Modified: stable/11/bin/dd/dd.1 ============================================================================== --- stable/11/bin/dd/dd.1 Tue Aug 28 23:56:52 2018 (r338363) +++ stable/11/bin/dd/dd.1 Wed Aug 29 02:18:13 2018 (r338364) @@ -32,7 +32,7 @@ .\" @(#)dd.1 8.2 (Berkeley) 1/13/94 .\" $FreeBSD$ .\" -.Dd April 2, 2017 +.Dd August 8, 2018 .Dt DD 1 .Os .Sh NAME @@ -164,12 +164,14 @@ bytes per second. 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 Modified: stable/11/bin/dd/dd.c ============================================================================== --- stable/11/bin/dd/dd.c Tue Aug 28 23:56:52 2018 (r338363) +++ stable/11/bin/dd/dd.c Wed Aug 29 02:18:13 2018 (r338364) @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -84,15 +85,22 @@ const u_char *ctab; /* conversion table */ 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[]) { + struct itimerval itv = { { 1, 0 }, { 1, 0 } }; /* SIGALARM every second, if needed */ + (void)setlocale(LC_CTYPE, ""); jcl(argv); setup(); (void)signal(SIGINFO, siginfo_handler); + if (ddflags & C_PROGRESS) { + (void)signal(SIGALRM, sigalarm_handler); + setitimer(ITIMER_REAL, &itv, NULL); + } (void)signal(SIGINT, terminate); atexit(summary); @@ -420,9 +428,10 @@ dd_in(void) in.dbp += in.dbrcnt; (*cfunc)(); - if (need_summary) { + if (need_summary) summary(); - } + if (need_progress) + progress(); } } Modified: stable/11/bin/dd/dd.h ============================================================================== --- stable/11/bin/dd/dd.h Tue Aug 28 23:56:52 2018 (r338363) +++ stable/11/bin/dd/dd.h Wed Aug 29 02:18:13 2018 (r338364) @@ -99,5 +99,6 @@ typedef struct { #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) Modified: stable/11/bin/dd/extern.h ============================================================================== --- stable/11/bin/dd/extern.h Tue Aug 28 23:56:52 2018 (r338363) +++ stable/11/bin/dd/extern.h Wed Aug 29 02:18:13 2018 (r338364) @@ -43,7 +43,9 @@ void jcl(char **); void pos_in(void); void pos_out(void); double secs_elapsed(void); +void progress(void); void summary(void); +void sigalarm_handler(int); void siginfo_handler(int); void terminate(int); void unblock(void); @@ -64,3 +66,4 @@ extern const u_char a2ibm_32V[], a2ibm_POSIX[]; extern u_char casetab[]; extern char fill_char; extern volatile sig_atomic_t need_summary; +extern volatile sig_atomic_t need_progress; Modified: stable/11/bin/dd/misc.c ============================================================================== --- stable/11/bin/dd/misc.c Tue Aug 28 23:56:52 2018 (r338363) +++ stable/11/bin/dd/misc.c Wed Aug 29 02:18:13 2018 (r338364) @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -81,6 +82,9 @@ summary(void) if (ddflags & C_NOINFO) return; + if (ddflags & C_PROGRESS) + fprintf(stderr, "\n"); + secs = secs_elapsed(); (void)fprintf(stderr, @@ -100,12 +104,45 @@ summary(void) need_summary = 0; } +void +progress(void) +{ + static int outlen; + char si[4 + 1 + 2 + 1]; /* 123 NUL */ + char iec[4 + 1 + 2 + 1]; /* 123 NUL */ + char persec[4 + 1 + 2 + 1]; /* 123 NUL */ + char *buf; + double secs; + + secs = secs_elapsed(); + humanize_number(si, sizeof(si), (int64_t)st.bytes, "B", HN_AUTOSCALE, + HN_DECIMAL | HN_DIVISOR_1000); + humanize_number(iec, sizeof(iec), (int64_t)st.bytes, "B", HN_AUTOSCALE, + HN_DECIMAL | HN_IEC_PREFIXES); + humanize_number(persec, sizeof(iec), (int64_t)(st.bytes / secs), "B", + HN_AUTOSCALE, HN_DECIMAL | HN_DIVISOR_1000); + asprintf(&buf, " %'ju bytes (%s, %s) transferred %.3fs, %s/s", + (uintmax_t)st.bytes, si, iec, secs, persec); + outlen = fprintf(stderr, "%-*s\r", outlen, buf); + fflush(stderr); + free(buf); + need_progress = 0; +} + /* ARGSUSED */ void siginfo_handler(int signo __unused) { need_summary = 1; +} + +/* ARGSUSED */ +void +sigalarm_handler(int signo __unused) +{ + + need_progress = 1; } /* ARGSUSED */ Modified: stable/11/bin/dd/position.c ============================================================================== --- stable/11/bin/dd/position.c Tue Aug 28 23:56:52 2018 (r338363) +++ stable/11/bin/dd/position.c Wed Aug 29 02:18:13 2018 (r338364) @@ -123,6 +123,8 @@ pos_in(void) --cnt; if (need_summary) summary(); + if (need_progress) + progress(); continue; }