Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/gzip add SIGINFO support.



details:   https://anonhg.NetBSD.org/src/rev/bcdbf5511c8a
branches:  trunk
changeset: 825885:bcdbf5511c8a
user:      mrg <mrg%NetBSD.org@localhost>
date:      Fri Aug 04 07:27:08 2017 +0000

description:
add SIGINFO support.

diffstat:

 usr.bin/gzip/gzip.1    |   13 ++-
 usr.bin/gzip/gzip.c    |  238 ++++++++++++++++++++++++++++++++++++------------
 usr.bin/gzip/unbzip2.c |    4 +-
 usr.bin/gzip/unpack.c  |   10 +-
 usr.bin/gzip/unxz.c    |    7 +-
 5 files changed, 203 insertions(+), 69 deletions(-)

diffs (truncated from 727 to 300 lines):

diff -r ed4c9a6ac3d5 -r bcdbf5511c8a usr.bin/gzip/gzip.1
--- a/usr.bin/gzip/gzip.1       Fri Aug 04 07:19:35 2017 +0000
+++ b/usr.bin/gzip/gzip.1       Fri Aug 04 07:27:08 2017 +0000
@@ -1,6 +1,6 @@
-.\"    $NetBSD: gzip.1,v 1.28 2017/06/03 21:28:48 mrg Exp $
+.\"    $NetBSD: gzip.1,v 1.29 2017/08/04 07:27:08 mrg Exp $
 .\"
-.\" Copyright (c) 1997, 2003, 2004, 2008, 2009, 2015 Matthew R. Green
+.\" Copyright (c) 1997, 2003, 2004, 2008, 2009, 2015, 2017 Matthew R. Green
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -179,6 +179,13 @@
 utility exits 0 on success,
 1 on errors,
 and 2 if a warning occurs.
+.Sh SIGNALS
+.Nm
+responds to the following signals:
+.Bl -tag -width indent
+.It Dv SIGINFO
+Report progress to standard error.
+.El
 .Sh SEE ALSO
 .Xr bzip2 1 ,
 .Xr compress 1 ,
@@ -202,7 +209,7 @@
 This manual documents
 .Nx
 .Nm
-version 20150113.
+version 20170803.
 .Sh AUTHORS
 This implementation of
 .Nm
diff -r ed4c9a6ac3d5 -r bcdbf5511c8a usr.bin/gzip/gzip.c
--- a/usr.bin/gzip/gzip.c       Fri Aug 04 07:19:35 2017 +0000
+++ b/usr.bin/gzip/gzip.c       Fri Aug 04 07:27:08 2017 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: gzip.c,v 1.110 2017/06/03 21:28:48 mrg Exp $   */
+/*     $NetBSD: gzip.c,v 1.111 2017/08/04 07:27:08 mrg Exp $   */
 
 /*
- * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015
+ * Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008, 2009, 2010, 2011, 2015, 2017
  *    Matthew R. Green
  * All rights reserved.
  *
@@ -30,8 +30,8 @@
 #include <sys/cdefs.h>
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1997, 1998, 2003, 2004, 2006, 2008,\
- 2009, 2010, 2011, 2015 Matthew R. Green.  All rights reserved.");
-__RCSID("$NetBSD: gzip.c,v 1.110 2017/06/03 21:28:48 mrg Exp $");
+ 2009, 2010, 2011, 2015, 2017 Matthew R. Green.  All rights reserved.");
+__RCSID("$NetBSD: gzip.c,v 1.111 2017/08/04 07:27:08 mrg Exp $");
 #endif /* not lint */
 
 /*
@@ -161,7 +161,7 @@
 #define NUM_SUFFIXES (sizeof suffixes / sizeof suffixes[0])
 #define SUFFIX_MAXLEN  30
 
-static const char      gzip_version[] = "NetBSD gzip 20150113";
+static const char      gzip_version[] = "NetBSD gzip 20170803";
 
 static int     cflag;                  /* stdout mode */
 static int     dflag;                  /* decompress mode */
@@ -177,6 +177,7 @@
 static int     rflag;                  /* recursive mode */
 static int     tflag;                  /* test */
 static int     vflag;                  /* verbose mode */
+static sig_atomic_t print_info = 0;
 #else
 #define                qflag   0
 #define                tflag   0
@@ -184,7 +185,7 @@
 
 static int     exit_value = 0;         /* exit value */
 
-static char    *infile;                /* name of file coming in */
+static const char *infile;             /* name of file coming in */
 
 static void    maybe_err(const char *fmt, ...) __printflike(1, 2) __dead;
 #if !defined(NO_BZIP2_SUPPORT) || !defined(NO_PACK_SUPPORT) || \
@@ -213,8 +214,20 @@
 static ssize_t read_retry(int, void *, size_t);
 
 #ifdef SMALL
+#define infile_set(f,t) infile_set(f)
+#endif
+static void    infile_set(const char *newinfile, off_t total);
+
+#ifdef SMALL
 #define unlink_input(f, sb) unlink(f)
+#define check_siginfo() /* nothing */
+#define setup_signals() /* nothing */
+#define infile_newdata(t) /* nothing */
 #else
+static off_t   infile_total;           /* total expected to read/write */
+static off_t   infile_current;         /* current read/write */
+
+static void    check_siginfo(void);
 static off_t   cat_fd(unsigned char *, size_t, off_t *, int fd);
 static void    prepend_gzip(char *, int *, char ***);
 static void    handle_dir(char *);
@@ -222,6 +235,9 @@
 static void    print_test(const char *, int);
 static void    copymodes(int fd, const struct stat *, const char *file);
 static int     check_outfile(const char *outfile);
+static void    setup_signals(void);
+static void    infile_newdata(size_t newdata);
+static void    infile_clear(void);
 #endif
 
 #ifndef NO_BZIP2_SUPPORT
@@ -285,7 +301,7 @@
 #endif
        int ch;
 
-       /* XXX set up signals */
+       setup_signals();
 
 #ifndef SMALL
        if ((gzip = getenv("GZIP")) != NULL)
@@ -559,7 +575,7 @@
                origname = "";
        }
 
-       i = snprintf(outbufp, BUFLEN, "%c%c%c%c%c%c%c%c%c%c%s", 
+       i = snprintf(outbufp, BUFLEN, "%c%c%c%c%c%c%c%c%c%c%s",
                     GZIP_MAGIC0, GZIP_MAGIC1, Z_DEFLATED,
                     *origname ? ORIG_NAME : 0,
                     mtime & 0xff,
@@ -568,7 +584,7 @@
                     (mtime >> 24) & 0xff,
                     numflag == 1 ? 4 : numflag == 9 ? 2 : 0,
                     OS_CODE, origname);
-       if (i >= BUFLEN)     
+       if (i >= BUFLEN)
                /* this need PATH_MAX > BUFLEN ... */
                maybe_err("snprintf");
        if (*origname)
@@ -609,6 +625,7 @@
                        }
                        if (in_size == 0)
                                break;
+                       infile_newdata(in_size);
 
                        crc = crc32(crc, (const Bytef *)inbufp, (unsigned)in_size);
                        in_tot += in_size;
@@ -658,7 +675,7 @@
                goto out;
        }
 
-       i = snprintf(outbufp, BUFLEN, "%c%c%c%c%c%c%c%c", 
+       i = snprintf(outbufp, BUFLEN, "%c%c%c%c%c%c%c%c",
                 (int)crc & 0xff,
                 (int)(crc >> 8) & 0xff,
                 (int)(crc >> 16) & 0xff,
@@ -750,6 +767,7 @@
        out_tot = 0;
 
        for (;;) {
+               check_siginfo();
                if ((z.avail_in == 0 || needmore) && done_reading == 0) {
                        ssize_t in_size;
 
@@ -766,6 +784,7 @@
                        } else if (in_size == 0) {
                                done_reading = 1;
                        }
+                       infile_newdata(in_size);
 
                        z.avail_in += in_size;
                        needmore = 0;
@@ -1059,7 +1078,7 @@
 
                (void)fchmod(fd, DEFFILEMODE & ~mask);
                (void)umask(mask);
-               return; 
+               return;
        }
        sb = *sbp;
 
@@ -1164,8 +1183,50 @@
                return;
        unlink(file);
 }
+
+static void
+got_siginfo(int signo)
+{
+
+       print_info = 1;
+}
+
+static void
+setup_signals(void)
+{
+
+       signal(SIGINFO, got_siginfo);
+}
+
+static void
+infile_newdata(size_t newdata)
+{
+
+       infile_current += newdata;
+}
 #endif
 
+static void
+infile_set(const char *newinfile, off_t total)
+{
+
+       if (newinfile)
+               infile = newinfile;
+#ifndef SMALL
+       infile_total = total;
+#endif
+}
+
+static void
+infile_clear(void)
+{
+
+       infile = NULL;
+#ifndef SMALL
+       infile_total = infile_current = 0;
+#endif
+}
+
 static const suffixes_t *
 check_suffix(char *file, int xlate)
 {
@@ -1196,7 +1257,7 @@
 {
        int in;
        int out;
-       off_t size, insize;
+       off_t size, in_size;
 #ifndef SMALL
        struct stat isb, osb;
        const suffixes_t *suff;
@@ -1208,16 +1269,23 @@
                return -1;
        }
 
+#ifndef SMALL
+       if (fstat(in, &isb) != 0) {
+               close(in);
+               maybe_warn("can't stat %s", file);
+               return -1;
+       }
+       infile_set(file, isb.st_size);
+#endif
+
        if (cflag == 0) {
 #ifndef SMALL
-               if (fstat(in, &isb) == 0) {
-                       if (isb.st_nlink > 1 && fflag == 0) {
-                               maybe_warnx("%s has %d other link%s -- "
-                                           "skipping", file, isb.st_nlink - 1,
-                                           isb.st_nlink == 1 ? "" : "s");
-                               close(in);
-                               return -1;
-                       }
+               if (isb.st_nlink > 1 && fflag == 0) {
+                       maybe_warnx("%s has %d other link%s -- "
+                                   "skipping", file, isb.st_nlink - 1,
+                                   isb.st_nlink == 1 ? "" : "s");
+                       close(in);
+                       return -1;
                }
 
                if (fflag == 0 && (suff = check_suffix(file, 0))
@@ -1253,19 +1321,19 @@
        } else
                out = STDOUT_FILENO;
 
-       insize = gz_compress(in, out, &size, basename(file), (uint32_t)isb.st_mtime);
+       in_size = gz_compress(in, out, &size, basename(file), (uint32_t)isb.st_mtime);
 
        (void)close(in);
 
        /*
-        * If there was an error, insize will be -1.
+        * If there was an error, in_size will be -1.
         * If we compressed to stdout, just return the size.
         * Otherwise stat the file and check it is the correct size.
         * We only blow away the file if we can stat the output and it
         * has the expected size.
         */
        if (cflag != 0)
-               return insize == -1 ? -1 : size;
+               return in_size == -1 ? -1 : size;
 
 #ifndef SMALL
        if (fstat(out, &osb) != 0) {



Home | Main Index | Thread Index | Old Index