Source-Changes-HG archive

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

[src/trunk]: src/sbin/dump Use getfsspecname() to fill the filesystem argumen...



details:   https://anonhg.NetBSD.org/src/rev/388abc53a8f0
branches:  trunk
changeset: 449279:388abc53a8f0
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Mar 01 16:42:11 2019 +0000

description:
Use getfsspecname() to fill the filesystem argument in dumpdates.
While here, make sure that the error strings terminate with newline
consistently, and add a function that adds the system error string.

diffstat:

 sbin/dump/dump.h      |   9 +++++----
 sbin/dump/ffs_inode.c |  13 +++++++------
 sbin/dump/itime.c     |  18 +++++++++---------
 sbin/dump/main.c      |  37 +++++++++++++++++++------------------
 sbin/dump/optr.c      |  36 +++++++++++++++++++++++++++++-------
 sbin/dump/tape.c      |  27 ++++++++++++++-------------
 sbin/dump/traverse.c  |   6 +++---
 7 files changed, 86 insertions(+), 60 deletions(-)

diffs (truncated from 508 to 300 lines):

diff -r 14ccbc992a1b -r 388abc53a8f0 sbin/dump/dump.h
--- a/sbin/dump/dump.h  Fri Mar 01 14:53:12 2019 +0000
+++ b/sbin/dump/dump.h  Fri Mar 01 16:42:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dump.h,v 1.55 2019/02/03 12:17:14 mrg Exp $    */
+/*     $NetBSD: dump.h,v 1.56 2019/03/01 16:42:11 christos Exp $       */
 
 /*-
  * Copyright (c) 1980, 1993
@@ -185,10 +185,11 @@
 /* operator interface functions */
 void   broadcast(const char *);
 void   lastdump(char);
-void   msg(const char *fmt, ...) __printflike(1, 2);
-void   msgtail(const char *fmt, ...) __printflike(1, 2);
+void   msg(const char *, ...) __printflike(1, 2);
+void   msgtail(const char *, ...) __printflike(1, 2);
 int    query(const char *);
-void   quit(const char *fmt, ...) __printflike(1, 2);
+void   quit(const char *, ...) __printflike(1, 2);
+void   quite(int, const char *, ...) __printflike(2, 3);
 time_t do_stats(void);
 void   statussig(int);
 void   timeest(void);
diff -r 14ccbc992a1b -r 388abc53a8f0 sbin/dump/ffs_inode.c
--- a/sbin/dump/ffs_inode.c     Fri Mar 01 14:53:12 2019 +0000
+++ b/sbin/dump/ffs_inode.c     Fri Mar 01 16:42:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ffs_inode.c,v 1.22 2013/06/23 02:06:04 dholland Exp $ */
+/*     $NetBSD: ffs_inode.c,v 1.23 2019/03/01 16:42:11 christos Exp $ */
 
 /*-
  * Copyright (c) 1980, 1991, 1993, 1994
@@ -36,7 +36,7 @@
 #endif /* not lint */
 
 #ifndef lint
-__RCSID("$NetBSD: ffs_inode.c,v 1.22 2013/06/23 02:06:04 dholland Exp $");
+__RCSID("$NetBSD: ffs_inode.c,v 1.23 2019/03/01 16:42:11 christos Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -79,7 +79,7 @@
        sblock = (struct fs *)superblock;
        for (i = 0; ; i++) {
                if (sblock_try[i] == -1)
-                       quit("can't find superblock\n");
+                       quit("can't find superblock");
                rawread(sblock_try[i], (char *)superblock, MAXBSIZE);
 
                switch(sblock->fs_magic) {
@@ -169,7 +169,7 @@
        char *cp;
 
        if ((cgp = malloc(sblock->fs_cgsize)) == NULL)
-               quit("fs_mapinodes: cannot allocate memory.\n");
+               quite(errno, "fs_mapinodes: cannot allocate memory.");
 
        for (cg = 0; cg < sblock->fs_ncg; cg++) {
                ino = cg * sblock->fs_ipg;
@@ -190,7 +190,8 @@
                 */
                if (sblock->fs_flags & FS_DOSOFTDEP) {
                        if (!cg_chkmagic(cgp, 0))
-                               quit("mapfiles: cg %d: bad magic number\n", cg);
+                               quit("%s: cg %d: bad magic number\n",
+                                   __func__, cg);
                        cp = &cg_inosused(cgp, 0)[(inosused - 1) / CHAR_BIT];
                        for ( ; inosused > 0; inosused -= CHAR_BIT, cp--) {
                                if (*cp == 0)
@@ -225,7 +226,7 @@
        struct ufs2_dinode *dp2;
 
        if (inoblock == NULL && (inoblock = malloc(ufsib->ufs_bsize)) == NULL)
-               quit("cannot allocate inode memory.\n");
+               quite(errno, "cannot allocate inode memory.");
        curino = inum;
        if (inum >= minino && inum < maxino)
                goto gotit;
diff -r 14ccbc992a1b -r 388abc53a8f0 sbin/dump/itime.c
--- a/sbin/dump/itime.c Fri Mar 01 14:53:12 2019 +0000
+++ b/sbin/dump/itime.c Fri Mar 01 16:42:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: itime.c,v 1.20 2013/06/15 01:27:19 christos Exp $      */
+/*     $NetBSD: itime.c,v 1.21 2019/03/01 16:42:11 christos Exp $      */
 
 /*-
  * Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)itime.c    8.1 (Berkeley) 6/5/93";
 #else
-__RCSID("$NetBSD: itime.c,v 1.20 2013/06/15 01:27:19 christos Exp $");
+__RCSID("$NetBSD: itime.c,v 1.21 2019/03/01 16:42:11 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -87,8 +87,8 @@
                }
                (void) fclose(df);
                if ((df = fopen(dumpdates, "r")) == NULL) {
-                       quit("cannot read %s even after creating it: %s\n",
-                           dumpdates, strerror(errno));
+                       quite(errno, "cannot read %s even after creating it",
+                           dumpdates);
                        /* NOTREACHED */
                }
        }
@@ -175,7 +175,7 @@
        if(uflag == 0)
                return;
        if ((df = fopen(dumpdates, "r+")) == NULL)
-               quit("cannot rewrite %s: %s\n", dumpdates, strerror(errno));
+               quite(errno, "cannot rewrite %s", dumpdates);
        fd = fileno(df);
        (void) flock(fd, LOCK_EX);
        fname = disk;
@@ -184,7 +184,7 @@
        nddates = 0;
        readdumptimes(df);
        if (fseek(df, 0L, 0) < 0)
-               quit("fseek: %s\n", strerror(errno));
+               quite(errno, "can't fseek %s", dumpdates);
        spcl.c_ddate = 0;
        ITITERATE(i, dtwalk) {
                if (strncmp(fname, dtwalk->dd_name,
@@ -211,9 +211,9 @@
                dumprecout(df, dtwalk);
        }
        if (fflush(df))
-               quit("%s: %s\n", dumpdates, strerror(errno));
+               quite(errno, "can't flush %s", dumpdates);
        if (ftruncate(fd, ftell(df)))
-               quit("ftruncate (%s): %s\n", dumpdates, strerror(errno));
+               quite(errno, "can't ftruncate %s", dumpdates);
        (void) fclose(df);
        msg("level %c dump on %s", level,
                spcl.c_date == 0 ? "the epoch\n" : ctime(&dtfound->dd_ddate));
@@ -227,7 +227,7 @@
                    what->dd_name,
                    what->dd_level,
                    ctime(&what->dd_ddate)) < 0)
-               quit("%s: %s\n", dumpdates, strerror(errno));
+               quite(errno, "can't write %s", dumpdates);
 }
 
 int    recno;
diff -r 14ccbc992a1b -r 388abc53a8f0 sbin/dump/main.c
--- a/sbin/dump/main.c  Fri Mar 01 14:53:12 2019 +0000
+++ b/sbin/dump/main.c  Fri Mar 01 16:42:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.73 2015/08/24 17:37:10 bouyer Exp $ */
+/*     $NetBSD: main.c,v 1.74 2019/03/01 16:42:11 christos Exp $       */
 
 /*-
  * Copyright (c) 1980, 1991, 1993, 1994
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.6 (Berkeley) 5/1/95";
 #else
-__RCSID("$NetBSD: main.c,v 1.73 2015/08/24 17:37:10 bouyer Exp $");
+__RCSID("$NetBSD: main.c,v 1.74 2019/03/01 16:42:11 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -124,7 +124,7 @@
        temp = _PATH_DTMP;
        strcpy(labelstr, "none");       /* XXX safe strcpy. */
        if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0)
-               quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
+               quit("TP_BSIZE must be a multiple of DEV_BSIZE");
        level = '0';
        timestamp = 0;
 
@@ -286,11 +286,12 @@
                error = lstat(argv[i], &sb);
                if (Fflag || (!error && (S_ISCHR(sb.st_mode) || S_ISBLK(sb.st_mode)))) {
                        if (error)
-                               quit("Cannot stat %s: %s\n", argv[i], strerror(errno));
+                               quite(errno, "can't stat %s", argv[i]);
                        disk = argv[i];
  multicheck:
                        if (dirc != 0)
-                               quit("Can't dump a disk or image at the same time as a file list\n");
+                               quit("can't dump a disk or image at the same"
+                               " time as a file list");
                        break;
                }
                if ((dt = fstabsearch(argv[i])) != NULL) {
@@ -299,8 +300,7 @@
                        goto multicheck;
                }
                if (statvfs(argv[i], &fsbuf) == -1)
-                       quit("Cannot statvfs %s: %s\n", argv[i],
-                           strerror(errno));
+                       quite(errno, "can't statvfs %s", argv[i]);
                disk = fsbuf.f_mntfromname;
                if (strcmp(argv[i], fsbuf.f_mntonname) == 0)
                        goto multicheck;
@@ -318,7 +318,7 @@
                            mountpoint);
                } else {
                        if (strcmp(mountpoint, fsbuf.f_mntonname) != 0)
-                               quit("%s is not on %s\n", argv[i], mountpoint);
+                               quit("%s is not on %s", argv[i], mountpoint);
                }
                msg("Dumping file/directory %s\n", argv[i]);
                dirc++;
@@ -403,18 +403,18 @@
        mntinfo = mntinfosearch(disk);
        if ((dt = fstabsearch(disk)) != NULL) {
                if (getfsspecname(buf, sizeof(buf), dt->fs_spec) == NULL)
-                       quit("%s (%s)", buf, strerror(errno));
+                       quite(errno, "can't resolve mount %s (%s)", dt->fs_spec,
+                           buf);
                if (getdiskrawname(rbuf, sizeof(rbuf), buf) == NULL)
-                       quit("Can't get disk raw name for `%s' (%s)",
-                           buf, strerror(errno));
+                       quite(errno, "can't get disk raw name for %s", buf);
                disk = rbuf;
                mountpoint = dt->fs_file;
                msg("Found %s on %s in %s\n", disk, mountpoint, _PATH_FSTAB);
        } else if (mntinfo != NULL) {
                if (getdiskrawname(rbuf, sizeof(rbuf), mntinfo->f_mntfromname)
                    == NULL)
-                       quit("Can't get disk raw name for `%s' (%s)",
-                           mntinfo->f_mntfromname, strerror(errno));
+                       quite(errno, "can't get disk raw name for %s",
+                           mntinfo->f_mntfromname);
                disk = rbuf;
                mountpoint = mntinfo->f_mntonname;
                msg("Found %s on %s in mount table\n", disk, mountpoint);
@@ -592,7 +592,8 @@
         * Allocate tape buffer.
         */
        if (!alloctape())
-               quit("can't allocate tape buffers - try a smaller blocking factor.\n");
+               quit("can't allocate tape buffers - try a smaller"
+                   " blocking factor.");
 
        startnewtape(1);
        (void)time((time_t *)&(tstart_writing));
@@ -709,7 +710,7 @@
        case SIGTERM:
        case SIGTRAP:
                if (pipeout)
-                       quit("Signal on pipe: cannot recover\n");
+                       quit("Signal on pipe: cannot recover");
                msg("Rewriting attempted as response to signal %s.\n", sys_siglist[signo]);
                (void)fflush(stderr);
                (void)fflush(stdout);
@@ -805,7 +806,7 @@
 
        p = calloc(number, size);
        if (p == NULL)
-               quit("%s\n", strerror(errno));
+               quite(errno, "Can't allocate %zu bytes", size * number);
        return (p);
 }
 
@@ -816,7 +817,7 @@
 
        p = malloc(size);
        if (p == NULL)
-               quit("%s\n", strerror(errno));
+               quite(errno, "Can't allocate %zu bytes", size);
        return (p);
 }
 
@@ -827,6 +828,6 @@
 
        p = strdup(str);
        if (p == NULL)
-               quit("%s\n", strerror(errno));
+               quite(errno, "Can't copy %s", str);
        return (p);
 }
diff -r 14ccbc992a1b -r 388abc53a8f0 sbin/dump/optr.c
--- a/sbin/dump/optr.c  Fri Mar 01 14:53:12 2019 +0000
+++ b/sbin/dump/optr.c  Fri Mar 01 16:42:11 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: optr.c,v 1.42 2013/09/08 13:26:05 mlelstv Exp $        */
+/*     $NetBSD: optr.c,v 1.43 2019/03/01 16:42:11 christos Exp $       */
 
 /*-
  * Copyright (c) 1980, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)optr.c     8.2 (Berkeley) 1/6/94";
 #else
-__RCSID("$NetBSD: optr.c,v 1.42 2013/09/08 13:26:05 mlelstv Exp $");
+__RCSID("$NetBSD: optr.c,v 1.43 2019/03/01 16:42:11 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -94,7 +94,7 @@
        firstprompt = time((time_t *)0);
 
        if ((mytty = fopen(_PATH_TTY, "r")) == NULL)
-               quit("fopen on %s fails: %s\n", _PATH_TTY, strerror(errno));



Home | Main Index | Thread Index | Old Index