Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/bin/cp Add siginfo support from Daniel Loffgren.
details: https://anonhg.NetBSD.org/src/rev/2bd8fdf175f4
branches: trunk
changeset: 772458:2bd8fdf175f4
user: christos <christos%NetBSD.org@localhost>
date: Wed Jan 04 15:58:37 2012 +0000
description:
Add siginfo support from Daniel Loffgren.
diffstat:
bin/cp/cp.c | 20 +++++++++++++++-----
bin/cp/extern.h | 3 ++-
bin/cp/utils.c | 33 +++++++++++++++++++++++++++++++--
3 files changed, 48 insertions(+), 8 deletions(-)
diffs (164 lines):
diff -r ad0eec4e8615 -r 2bd8fdf175f4 bin/cp/cp.c
--- a/bin/cp/cp.c Wed Jan 04 15:56:18 2012 +0000
+++ b/bin/cp/cp.c Wed Jan 04 15:58:37 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cp.c,v 1.57 2011/08/18 08:11:58 manu Exp $ */
+/* $NetBSD: cp.c,v 1.58 2012/01/04 15:58:37 christos Exp $ */
/*
* Copyright (c) 1988, 1993, 1994
@@ -43,7 +43,7 @@
#if 0
static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95";
#else
-__RCSID("$NetBSD: cp.c,v 1.57 2011/08/18 08:11:58 manu Exp $");
+__RCSID("$NetBSD: cp.c,v 1.58 2012/01/04 15:58:37 christos Exp $");
#endif
#endif /* not lint */
@@ -70,6 +70,7 @@
#include <errno.h>
#include <fts.h>
#include <locale.h>
+#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -88,11 +89,18 @@
uid_t myuid;
int Hflag, Lflag, Rflag, Pflag, fflag, iflag, lflag, pflag, rflag, vflag, Nflag;
mode_t myumask;
+sig_atomic_t pinfo;
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
-int main(int, char *[]);
-int copy(char *[], enum op, int);
+static int copy(char *[], enum op, int);
+
+static void
+progress(int sig __unused)
+{
+
+ pinfo++;
+}
int
main(int argc, char *argv[])
@@ -210,6 +218,8 @@
/* Set end of argument list for fts(3). */
argv[argc] = NULL;
+ (void)signal(SIGINFO, progress);
+
/*
* Cp has two distinct cases:
*
@@ -310,7 +320,7 @@
return rv;
}
-int
+static int
copy(char *argv[], enum op type, int fts_options)
{
struct stat to_stat;
diff -r ad0eec4e8615 -r 2bd8fdf175f4 bin/cp/extern.h
--- a/bin/cp/extern.h Wed Jan 04 15:56:18 2012 +0000
+++ b/bin/cp/extern.h Wed Jan 04 15:58:37 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.16 2011/02/06 12:37:49 darcy Exp $ */
+/* $NetBSD: extern.h,v 1.17 2012/01/04 15:58:37 christos Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@@ -44,6 +44,7 @@
extern uid_t myuid;
extern int Rflag, rflag, Hflag, Lflag, Pflag, fflag, iflag, lflag, pflag, Nflag;
extern mode_t myumask;
+extern sig_atomic_t pinfo;
#include <sys/cdefs.h>
diff -r ad0eec4e8615 -r 2bd8fdf175f4 bin/cp/utils.c
--- a/bin/cp/utils.c Wed Jan 04 15:56:18 2012 +0000
+++ b/bin/cp/utils.c Wed Jan 04 15:58:37 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: utils.c,v 1.40 2011/08/03 04:11:15 manu Exp $ */
+/* $NetBSD: utils.c,v 1.41 2012/01/04 15:58:37 christos Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94";
#else
-__RCSID("$NetBSD: utils.c,v 1.40 2011/08/03 04:11:15 manu Exp $");
+__RCSID("$NetBSD: utils.c,v 1.41 2012/01/04 15:58:37 christos Exp $");
#endif
#endif /* not lint */
@@ -74,6 +74,22 @@
return (0);
}
+struct finfo {
+ const char *from;
+ const char *to;
+ size_t size;
+};
+
+static void
+progress(const struct finfo *fi, size_t written)
+{
+ int pcent = (int)((100.0 * written) / fi->size);
+
+ pinfo = 0;
+ (void)fprintf(stderr, "%s => %s %zu/%zu bytes %d%% written\n",
+ fi->from, fi->to, written, fi->size, pcent);
+}
+
int
copy_file(FTSENT *entp, int dne)
{
@@ -81,6 +97,7 @@
struct stat to_stat, *fs;
int ch, checkch, from_fd, rcount, rval, to_fd, tolnk, wcount;
char *p;
+ size_t ptotal = 0;
if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) {
warn("%s", entp->fts_path);
@@ -164,6 +181,12 @@
* now if it's empty, so let's not bother.
*/
if (fs->st_size > 0) {
+ struct finfo fi;
+
+ fi.from = entp->fts_path;
+ fi.to = to.p_path;
+ fi.size = (size_t)fs->st_size;
+
/*
* Mmap and write if less than 8M (the limit is so
* we don't totally trash memory on big files).
@@ -203,6 +226,9 @@
break;
}
remainder -= chunk;
+ ptotal += chunk;
+ if (pinfo)
+ progress(&fi, ptotal);
} while (remainder > 0);
if (munmap(p, fsize) < 0) {
@@ -220,6 +246,9 @@
rval = 1;
break;
}
+ ptotal += wcount;
+ if (pinfo)
+ progress(&fi, ptotal);
}
if (rcount < 0) {
warn("%s", entp->fts_path);
Home |
Main Index |
Thread Index |
Old Index