From 098c1602c1902bb7fc729d5b9c2c58283273736b Mon Sep 17 00:00:00 2001 From: Victor Balada Diaz Date: Sat, 11 Nov 2006 12:05:36 +0000 Subject: [PATCH] Add support for SIGINFO. Submitted-By: Trevor Kendall --- bin/mv/mv.1 | 13 ++++++++++++- bin/mv/mv.c | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/bin/mv/mv.1 b/bin/mv/mv.1 index 5b8a913426..3e1f138877 100644 --- a/bin/mv/mv.1 +++ b/bin/mv/mv.1 @@ -34,7 +34,7 @@ .\" .\" @(#)mv.1 8.1 (Berkeley) 5/31/93 .\" $FreeBSD: src/bin/mv/mv.1,v 1.15.2.5 2003/01/24 02:29:13 keramida Exp $ -.\" $DragonFly: src/bin/mv/mv.1,v 1.3 2006/02/17 19:33:31 swildner Exp $ +.\" $DragonFly: src/bin/mv/mv.1,v 1.4 2006/11/11 12:05:36 victor Exp $ .\" .Dd July 9, 2002 .Dt MV 1 @@ -142,6 +142,17 @@ rm -f destination_path && \e cp -pRP source_file destination && \e rm -rf source_file .Ed +.Pp +If +.Nm +receives a +.Dv SIGINFO +(see the +.Cm status +argument for +.Xr stty 1 ) +signal, the current input and output file +will be written to standard error. .Sh DIAGNOSTICS .Ex -std .Sh COMPATIBILITY diff --git a/bin/mv/mv.c b/bin/mv/mv.c index 32302c3931..a615e24282 100644 --- a/bin/mv/mv.c +++ b/bin/mv/mv.c @@ -32,7 +32,7 @@ * @(#) Copyright (c) 1989, 1993, 1994 The Regents of the University of California. All rights reserved. * @(#)mv.c 8.2 (Berkeley) 4/2/94 * $FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/bin/mv/mv.c,v 1.24.2.6 2004/03/24 08:34:36 pjd Exp $ - * $DragonFly: src/bin/mv/mv.c,v 1.11 2005/06/04 20:35:06 liamfoy Exp $ + * $DragonFly: src/bin/mv/mv.c,v 1.12 2006/11/11 12:05:36 victor Exp $ */ #include @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -53,12 +54,16 @@ #include "pathnames.h" +#define mv_pct(x,y) (int)(100.0 * (double)(x) / (double)(y)) + static int fflg, iflg, nflg, vflg; +volatile sig_atomic_t info; static int copy(const char *, const char *); -static int do_move (const char *, const char *); -static int fastcopy (const char *, const char *, struct stat *); -static void usage (void); +static int do_move(const char *, const char *); +static int fastcopy(const char *, const char *, struct stat *); +static void siginfo(int); +static void usage(void); int main(int argc, char **argv) @@ -93,6 +98,8 @@ main(int argc, char **argv) argc -= optind; argv += optind; + signal(SIGINFO, siginfo); + if (argc < 2) usage(); @@ -242,6 +249,7 @@ fastcopy(const char *from, const char *to, struct stat *sbp) static char *bp; mode_t oldmode; int nread, from_fd, to_fd; + ssize_t wtotal = 0, wcount; if ((from_fd = open(from, O_RDONLY, 0)) < 0) { warn("%s", from); @@ -265,11 +273,22 @@ fastcopy(const char *from, const char *to, struct stat *sbp) close(from_fd); return (1); } - while ((nread = read(from_fd, bp, (size_t)blen)) > 0) - if (write(to_fd, bp, (size_t)nread) != nread) { + while ((nread = read(from_fd, bp, (size_t)blen)) > 0) { + wcount = write(to_fd, bp, (size_t)nread); + wtotal += wcount; + + if (wcount != nread) { warn("%s", to); goto err; } + + if (info) { + info = 0; + fprintf(stderr, "%s -> %s %3d%%\n", + from, to, + mv_pct(wtotal, sbp->st_size)); + } + } if (nread < 0) { warn("%s", from); err: if (unlink(to)) @@ -380,3 +399,9 @@ usage(void) " mv [-f | -i | -n] [-v] source ... directory"); exit(EX_USAGE); } + +static void +siginfo(int notused __unused) +{ + info = 1; +} -- 2.41.0