Add a SIGINFO handler.

This commit is contained in:
Matthew N. Dodd 2003-04-07 11:00:56 +00:00
parent 0c7dd12c30
commit 00d321a2b3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=113209
4 changed files with 45 additions and 0 deletions

View File

@ -225,6 +225,17 @@ options are ignored unless the
option is specified.
In addition, these options override each other and the
command's actions are determined by the last one specified.
.Pp
If
.Nm
receives a
.Dv SIGINFO
(see the
.Cm status
argument for
.Xr stty 1 )
signal, the current input and output file and the percentage complete
will be written to the standard output.
.Sh DIAGNOSTICS
.Ex -std
.Sh COMPATIBILITY

View File

@ -89,6 +89,9 @@ PATH_T to = { to.p_path, emptystring, "" };
int fflag, iflag, nflag, pflag, vflag;
static int Rflag, rflag;
int info;
static void siginfo (int notused __unused);
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
static int copy(char *[], enum op, int);
@ -173,6 +176,7 @@ main(int argc, char *argv[])
fts_options &= ~FTS_PHYSICAL;
fts_options |= FTS_LOGICAL | FTS_COMFOLLOW;
}
(void)signal(SIGINFO, siginfo);
/* Save the target base in "to". */
target = argv[--argc];
@ -501,3 +505,10 @@ mastercmp(const FTSENT * const *a, const FTSENT * const *b)
return (1);
return (0);
}
static void
siginfo (int notused __unused)
{
info = 1;
}

View File

@ -42,6 +42,7 @@ typedef struct {
extern PATH_T to;
extern int fflag, iflag, nflag, pflag, vflag;
extern int info;
__BEGIN_DECLS
int copy_fifo(struct stat *, int);

View File

@ -56,6 +56,7 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include "extern.h"
#define cp_pct(x,y) (int)(100.0 * (double)(x) / (double)(y))
int
copy_file(const FTSENT *entp, int dne)
@ -65,6 +66,7 @@ copy_file(const FTSENT *entp, int dne)
int ch, checkch, from_fd, rcount, rval, to_fd;
ssize_t wcount;
size_t wresid;
size_t wtotal;
char *bufp;
#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
char *p;
@ -137,9 +139,19 @@ copy_file(const FTSENT *entp, int dne)
warn("%s", entp->fts_path);
rval = 1;
} else {
wtotal = 0;
for (bufp = p, wresid = fs->st_size; ;
bufp += wcount, wresid -= (size_t)wcount) {
wcount = write(to_fd, bufp, wresid);
wtotal += wcount;
if (info) {
info = 0;
(void)fprintf(stderr,
"%s -> %s %3d%%\n",
entp->fts_path, to.p_path,
cp_pct(wtotal, fs->st_size));
}
if (wcount >= (ssize_t)wresid || wcount <= 0)
break;
}
@ -156,10 +168,20 @@ copy_file(const FTSENT *entp, int dne)
} else
#endif
{
wtotal = 0;
while ((rcount = read(from_fd, buf, MAXBSIZE)) > 0) {
for (bufp = buf, wresid = rcount; ;
bufp += wcount, wresid -= wcount) {
wcount = write(to_fd, bufp, wresid);
wtotal += wcount;
if (info) {
info = 0;
(void)fprintf(stderr,
"%s -> %s %3d%%\n",
entp->fts_path, to.p_path,
cp_pct(wtotal, fs->st_size));
}
if (wcount >= (ssize_t)wresid || wcount <= 0)
break;
}