tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Why no SIGINFO?
On 1/4/12 4:06 PM, Daniel Loffgren wrote:
Some style nitpicks below.
> Index: cp.c
> ===================================================================
> RCS file: /cvsroot/src/bin/cp/cp.c,v
> retrieving revision 1.57
> diff -u -r1.57 cp.c
> --- cp.c 18 Aug 2011 08:11:58 -0000 1.57
> +++ cp.c 4 Jan 2012 15:00:46 -0000
> @@ -74,6 +74,7 @@
> #include <stdio.h>
> #include <string.h>
> #include <unistd.h>
> +#include <signal.h>
Sort signal.h alphabetically. (Not sure if the rest of the includes are
sorted, but the ones quoted in the diff chunk are.)
> #include "extern.h"
>
> @@ -88,6 +89,7 @@
> 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 };
>
> @@ -210,6 +212,9 @@
> /* Set end of argument list for fts(3). */
> argv[argc] = NULL;
>
> + pinfo = 0;
> + (void)signal(SIGINFO, progress);
> +
> /*
> * Cp has two distinct cases:
> *
> Index: extern.h
> ===================================================================
> RCS file: /cvsroot/src/bin/cp/extern.h,v
> retrieving revision 1.16
> diff -u -r1.16 extern.h
> --- extern.h 6 Feb 2011 12:37:49 -0000 1.16
> +++ extern.h 4 Jan 2012 15:00:46 -0000
> @@ -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>
>
> @@ -54,6 +55,7 @@
> int copy_special(struct stat *, int);
> int set_utimes(const char *, struct stat *);
> int setfile(struct stat *, int);
> +void progress(int unused);
Remove the parameter name for consistency.
> void usage(void) __attribute__((__noreturn__));
> __END_DECLS
>
> Index: utils.c
> ===================================================================
> RCS file: /cvsroot/src/bin/cp/utils.c,v
> retrieving revision 1.40
> diff -u -r1.40 utils.c
> --- utils.c 3 Aug 2011 04:11:15 -0000 1.40
> +++ utils.c 4 Jan 2012 15:00:46 -0000
> @@ -81,6 +81,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);
> @@ -220,6 +221,14 @@
> rval = 1;
> break;
> }
> + ptotal += wcount;
> + if (pinfo) {
> + pinfo = 0;
> + fprintf(stderr,
> + "%s => %s %zu/%zu bytes %d%% written\n",
> + entp->fts_path, to.p_path, ptotal,
> + (size_t)fs->st_size, (int)((100.0 *
> ptotal) / fs->st_size));
> + }
> }
> if (rcount < 0) {
> warn("%s", entp->fts_path);
> @@ -381,6 +390,12 @@
> }
>
> void
> +progress(int unused)
> +{
> + pinfo = 1;
Need a blank line before the assignment, per KNF.
> +}
> +
> +void
> usage(void)
> {
> (void)fprintf(stderr,
--
Julio Merino / @jmmv
Home |
Main Index |
Thread Index |
Old Index