Module Name: src Committed By: christos Date: Fri Mar 1 16:42:11 UTC 2019
Modified Files: src/sbin/dump: dump.h ffs_inode.c itime.c main.c optr.c tape.c traverse.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 src/sbin/dump/dump.h cvs rdiff -u -r1.22 -r1.23 src/sbin/dump/ffs_inode.c cvs rdiff -u -r1.20 -r1.21 src/sbin/dump/itime.c cvs rdiff -u -r1.73 -r1.74 src/sbin/dump/main.c cvs rdiff -u -r1.42 -r1.43 src/sbin/dump/optr.c cvs rdiff -u -r1.54 -r1.55 src/sbin/dump/tape.c cvs rdiff -u -r1.51 -r1.52 src/sbin/dump/traverse.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/dump/dump.h diff -u src/sbin/dump/dump.h:1.55 src/sbin/dump/dump.h:1.56 --- src/sbin/dump/dump.h:1.55 Sun Feb 3 07:17:14 2019 +++ src/sbin/dump/dump.h Fri Mar 1 11:42:11 2019 @@ -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 @@ void fs_mapinodes(ino_t, u_int64_t *, in /* 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); Index: src/sbin/dump/ffs_inode.c diff -u src/sbin/dump/ffs_inode.c:1.22 src/sbin/dump/ffs_inode.c:1.23 --- src/sbin/dump/ffs_inode.c:1.22 Sat Jun 22 22:06:04 2013 +++ src/sbin/dump/ffs_inode.c Fri Mar 1 11:42:11 2019 @@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #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 @@ fs_read_sblock(char *superblock) 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 @@ fs_mapinodes(ino_t maxino __unused, u_in 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 @@ fs_mapinodes(ino_t maxino __unused, u_in */ 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 @@ getino(ino_t inum) 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; Index: src/sbin/dump/itime.c diff -u src/sbin/dump/itime.c:1.20 src/sbin/dump/itime.c:1.21 --- src/sbin/dump/itime.c:1.20 Fri Jun 14 21:27:19 2013 +++ src/sbin/dump/itime.c Fri Mar 1 11:42:11 2019 @@ -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 @@ initdumptimes(void) } (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 @@ putdumptime(void) 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 @@ putdumptime(void) 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 @@ putdumptime(void) 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 @@ dumprecout(FILE *file, struct dumpdates 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; Index: src/sbin/dump/main.c diff -u src/sbin/dump/main.c:1.73 src/sbin/dump/main.c:1.74 --- src/sbin/dump/main.c:1.73 Mon Aug 24 13:37:10 2015 +++ src/sbin/dump/main.c Fri Mar 1 11:42:11 2019 @@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19 #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 @@ main(int argc, char *argv[]) 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 @@ main(int argc, char *argv[]) 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 @@ main(int argc, char *argv[]) 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 @@ main(int argc, char *argv[]) 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 @@ main(int argc, char *argv[]) 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 @@ main(int argc, char *argv[]) * 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 @@ sig(int signo) 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 @@ xcalloc(size_t number, size_t size) 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 @@ xmalloc(size_t size) 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 @@ xstrdup(const char *str) p = strdup(str); if (p == NULL) - quit("%s\n", strerror(errno)); + quite(errno, "Can't copy %s", str); return (p); } Index: src/sbin/dump/optr.c diff -u src/sbin/dump/optr.c:1.42 src/sbin/dump/optr.c:1.43 --- src/sbin/dump/optr.c:1.42 Sun Sep 8 09:26:05 2013 +++ src/sbin/dump/optr.c Fri Mar 1 11:42:11 2019 @@ -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 @@ query(const char *question) firstprompt = time((time_t *)0); if ((mytty = fopen(_PATH_TTY, "r")) == NULL) - quit("fopen on %s fails: %s\n", _PATH_TTY, strerror(errno)); + quite(errno, "fopen on %s fails", _PATH_TTY); attnmessage = question; timeout = 0; alarmcatch(0); @@ -104,7 +104,7 @@ query(const char *question) if (fgets(replybuffer, 63, mytty) == NULL) { clearerr(mytty); if (++errcount > 30) /* XXX ugly */ - quit("excessive operator query failures\n"); + quit("excessive operator query failures"); } else if (replybuffer[0] == 'y' || replybuffer[0] == 'Y') { back = 1; } else if (replybuffer[0] == 'n' || replybuffer[0] == 'N') { @@ -295,6 +295,24 @@ msgtail(const char *fmt, ...) } void +quite(int e, const char *fmt, ...) +{ + va_list ap; + + (void) fprintf(stderr," DUMP: "); +#ifdef TDEBUG + (void) fprintf(stderr, "pid=%d ", getpid()); +#endif + va_start(ap, fmt); + (void) vfprintf(stderr, fmt, ap); + va_end(ap); + (void) fprintf(stderr, ": %s\n", strerror(e)); + (void) fflush(stdout); + (void) fflush(stderr); + dumpabort(0); +} + +void quit(const char *fmt, ...) { va_list ap; @@ -306,6 +324,7 @@ quit(const char *fmt, ...) va_start(ap, fmt); (void) vfprintf(stderr, fmt, ap); va_end(ap); + (void) fprintf(stderr, "\n"); (void) fflush(stdout); (void) fflush(stderr); dumpabort(0); @@ -324,10 +343,13 @@ allocfsent(const struct fstab *fs) new = xmalloc(sizeof (*fs)); new->fs_file = xstrdup(fs->fs_file); new->fs_type = xstrdup(fs->fs_type); - new->fs_spec = xstrdup(fs->fs_spec); + new->fs_spec = xmalloc(FILENAME_MAX); + if (getfsspecname(new->fs_spec, FILENAME_MAX, fs->fs_spec) == NULL) + quite(errno, "can't resolve mount point %s (%s)", + fs->fs_spec, new->fs_spec); new->fs_passno = fs->fs_passno; new->fs_freq = fs->fs_freq; - return (new); + return new; } struct pfstab { @@ -426,7 +448,7 @@ mntinfosearch(const char *key) char buf[MAXPATHLEN]; if ((mntbufc = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) - quit("Can't get mount list: %s", strerror(errno)); + quite(errno, "Can't get mount list"); for (fs = mntbuf, i = 0; i < mntbufc; i++, fs++) { #ifdef DUMP_LFS if (strcmp(fs->f_fstypename, "lfs") != 0) Index: src/sbin/dump/tape.c diff -u src/sbin/dump/tape.c:1.54 src/sbin/dump/tape.c:1.55 --- src/sbin/dump/tape.c:1.54 Mon Aug 24 13:37:10 2015 +++ src/sbin/dump/tape.c Fri Mar 1 11:42:11 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: tape.c,v 1.54 2015/08/24 17:37:10 bouyer Exp $ */ +/* $NetBSD: tape.c,v 1.55 2019/03/01 16:42:11 christos Exp $ */ /*- * Copyright (c) 1980, 1991, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)tape.c 8.4 (Berkeley) 5/1/95"; #else -__RCSID("$NetBSD: tape.c,v 1.54 2015/08/24 17:37:10 bouyer Exp $"); +__RCSID("$NetBSD: tape.c,v 1.55 2019/03/01 16:42:11 christos Exp $"); #endif #endif /* not lint */ @@ -196,7 +196,7 @@ tperror(int signo __unused) if (pipeout) { msg("write error on %s\n", tape); - quit("Cannot recover\n"); + quit("Cannot recover"); /* NOTREACHED */ } msg("write error %ld blocks into volume %d\n", blocksthisvol, tapeno); @@ -215,7 +215,7 @@ static void sigpipe(int signo __unused) { - quit("Broken pipe\n"); + quit("Broken pipe"); } /* @@ -284,7 +284,7 @@ flushtape(void) slp->req[trecno].count = 0; /* Sentinel */ if (atomic_write(slp->fd, slp->req, siz) != siz) - quit("error writing command pipe: %s\n", strerror(errno)); + quite(errno, "error writing command pipe"); slp->sent = 1; /* we sent a request, read the response later */ lastfirstrec = slp->firstrec; @@ -375,7 +375,7 @@ trewind(int eject) if (got != writesize) { msg("EOT detected in last 2 tape records!\n"); msg("Use a longer tape, decrease the size estimate\n"); - quit("or use no size estimate at all.\n"); + quit("or use no size estimate at all"); } } (void) close(slaves[f].fd); @@ -554,7 +554,7 @@ rollforward(void) slp->sent = 0; if (got != writesize) { - quit("EOT detected at start of the tape!\n"); + quit("EOT detected at start of the tape"); } } } @@ -768,8 +768,8 @@ enslave(void) if (socketpair(AF_LOCAL, SOCK_STREAM, 0, cmd) < 0 || (slaves[i].pid = fork()) < 0) - quit("too many slaves, %d (recompile smaller): %s\n", - i, strerror(errno)); + quite(errno, "too many slaves, %d (recompile smaller)", + i); slaves[i].fd = cmd[1]; slaves[i].sent = 0; @@ -822,14 +822,15 @@ doslave(int cmd, int slave_number __unus */ (void) close(diskfd); if ((diskfd = open(disk_dev, O_RDONLY)) < 0) - quit("slave couldn't reopen disk: %s\n", strerror(errno)); + quite(errno, "slave couldn't reopen disk"); /* * Need the pid of the next slave in the loop... */ if ((nread = atomic_read(cmd, &nextslave, sizeof nextslave)) != sizeof nextslave) { - quit("master/slave protocol botched - didn't get pid of next slave.\n"); + quit("master/slave protocol botched - didn't get pid" + " of next slave"); } /* @@ -847,7 +848,7 @@ doslave(int cmd, int slave_number __unus if (p->count != 1 || atomic_read(cmd, slp->tblock[trecno], TP_BSIZE) != TP_BSIZE) - quit("master/slave protocol botched.\n"); + quit("master/slave protocol botched"); } } @@ -924,7 +925,7 @@ doslave(int cmd, int slave_number __unus } printcachestats(); if (nread != 0) - quit("error reading command pipe: %s\n", strerror(errno)); + quite(errno, "error reading command pipe"); } /* Index: src/sbin/dump/traverse.c diff -u src/sbin/dump/traverse.c:1.51 src/sbin/dump/traverse.c:1.52 --- src/sbin/dump/traverse.c:1.51 Sun Feb 3 07:17:14 2019 +++ src/sbin/dump/traverse.c Fri Mar 1 11:42:11 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: traverse.c,v 1.51 2019/02/03 12:17:14 mrg Exp $ */ +/* $NetBSD: traverse.c,v 1.52 2019/03/01 16:42:11 christos Exp $ */ /*- * Copyright (c) 1980, 1988, 1991, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)traverse.c 8.7 (Berkeley) 6/15/95"; #else -__RCSID("$NetBSD: traverse.c,v 1.51 2019/02/03 12:17:14 mrg Exp $"); +__RCSID("$NetBSD: traverse.c,v 1.52 2019/03/01 16:42:11 christos Exp $"); #endif #endif /* not lint */ @@ -414,7 +414,7 @@ searchdir(ino_t dino, daddr_t blkno, lon dblk = malloc(size); if (dblk == NULL) - quit("searchdir: cannot allocate directory memory.\n"); + quit("%s: cannot allocate directory memory", __func__); bread(fsatoda(ufsib, blkno), dblk, (int)size); if (filesize < size) size = filesize;