Add siginfo support from Daniel Loffgren.
This commit is contained in:
parent
2d0a8b25c8
commit
eb8f42a53b
20
bin/cp/cp.c
20
bin/cp/cp.c
|
@ -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 @@ __COPYRIGHT(
|
|||
#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 @@ __RCSID("$NetBSD: cp.c,v 1.57 2011/08/18 08:11:58 manu Exp $");
|
|||
#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 @@ PATH_T to = { .p_end = to.p_path, .target_end = empty };
|
|||
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 @@ main(int argc, char *argv[])
|
|||
/* Set end of argument list for fts(3). */
|
||||
argv[argc] = NULL;
|
||||
|
||||
(void)signal(SIGINFO, progress);
|
||||
|
||||
/*
|
||||
* Cp has two distinct cases:
|
||||
*
|
||||
|
@ -310,7 +320,7 @@ popdne(void)
|
|||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
static int
|
||||
copy(char *argv[], enum op type, int fts_options)
|
||||
{
|
||||
struct stat to_stat;
|
||||
|
|
|
@ -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 PATH_T to;
|
|||
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>
|
||||
|
||||
|
|
|
@ -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 @@ set_utimes(const char *file, struct stat *fs)
|
|||
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 @@ copy_file(FTSENT *entp, int dne)
|
|||
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 @@ copy_file(FTSENT *entp, int dne)
|
|||
* 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 @@ copy_file(FTSENT *entp, int dne)
|
|||
break;
|
||||
}
|
||||
remainder -= chunk;
|
||||
ptotal += chunk;
|
||||
if (pinfo)
|
||||
progress(&fi, ptotal);
|
||||
} while (remainder > 0);
|
||||
|
||||
if (munmap(p, fsize) < 0) {
|
||||
|
@ -220,6 +246,9 @@ copy_file(FTSENT *entp, int dne)
|
|||
rval = 1;
|
||||
break;
|
||||
}
|
||||
ptotal += wcount;
|
||||
if (pinfo)
|
||||
progress(&fi, ptotal);
|
||||
}
|
||||
if (rcount < 0) {
|
||||
warn("%s", entp->fts_path);
|
||||
|
|
Loading…
Reference in New Issue