The best I can tell, fsck's errexit() is just a clone of errx() (less
the "progname: " prefix and the appended newline).

If we delete it from fsck_ffs, fsck_ext2fs, and fsck_msdos, we can
remove its definition in fsck. This diff is just for fsck_ffs.
(fsck_msdos has only one use.)

Another trivial diff, but deleting stdlib clones like this prevents
people from getting distracted when they're trying to get stuff done.


Index: dir.c
===================================================================
RCS file: /cvs/src/sbin/fsck_ffs/dir.c,v
retrieving revision 1.32
diff -u -p -r1.32 dir.c
--- dir.c       20 Jan 2015 18:22:21 -0000      1.32
+++ dir.c       19 Sep 2015 19:09:19 -0000
@@ -36,6 +36,7 @@
 #include <ufs/ufs/dir.h>
 #include <ufs/ffs/fs.h>
 
+#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -103,7 +104,7 @@ dirscan(struct inodesc *idesc)
        char dbuf[DIRBLKSIZ];
 
        if (idesc->id_type != DATA)
-               errexit("wrong type to dirscan %d\n", idesc->id_type);
+               errx(8, "wrong type to dirscan %d", idesc->id_type);
        if (idesc->id_entryno == 0 &&
            (idesc->id_filesize & (DIRBLKSIZ - 1)) != 0)
                idesc->id_filesize = roundup(idesc->id_filesize, DIRBLKSIZ);
Index: inode.c
===================================================================
RCS file: /cvs/src/sbin/fsck_ffs/inode.c,v
retrieving revision 1.46
diff -u -p -r1.46 inode.c
--- inode.c     20 Jan 2015 18:22:21 -0000      1.46
+++ inode.c     19 Sep 2015 19:09:19 -0000
@@ -38,6 +38,7 @@
 #ifndef SMALL
 #include <pwd.h>
 #endif
+#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -285,7 +286,7 @@ ginode(ino_t inumber)
        daddr_t iblk;
 
        if (inumber < ROOTINO || inumber > maxino)
-               errexit("bad inode number %llu to ginode\n",
+               errx(8, "bad inode number %llu to ginode",
                    (unsigned long long)inumber);
        if (startinum == 0 ||
            inumber < startinum || inumber >= startinum + INOPB(&sblock)) {
@@ -318,7 +319,7 @@ getnextinode(ino_t inumber)
        static caddr_t nextinop;
 
        if (inumber != nextino++ || inumber > maxino)
-               errexit("bad inode number %llu to nextinode %llu\n",
+               errx(8, "bad inode number %llu to nextinode %llu",
                    (unsigned long long)inumber,
                    (unsigned long long)nextino);
        if (inumber >= lastinum) {
@@ -371,15 +372,13 @@ setinodebuf(ino_t inum)
        }
        if (inodebuf == NULL &&
            (inodebuf = malloc((unsigned)inobufsize)) == NULL)
-               errexit("Cannot allocate space for inode buffer\n");
+               errx(8, "Cannot allocate space for inode buffer");
 }
 
 void
 freeinodebuf(void)
 {
-
-       if (inodebuf != NULL)
-               free(inodebuf);
+       free(inodebuf);
        inodebuf = NULL;
 }
 
@@ -404,7 +403,7 @@ cacheino(union dinode *dp, ino_t inumber
                blks = NDADDR + NIADDR;
        inp = malloc(sizeof(*inp) + (blks ? blks - 1 : 0) * sizeof(daddr_t));
        if (inp == NULL)
-               errexit("cannot allocate memory for inode cache\n");
+               errx(8, "cannot allocate memory for inode cache");
        inpp = &inphead[inumber % numdirs];
        inp->i_nexthash = *inpp;
        *inpp = inp;
@@ -427,7 +426,7 @@ cacheino(union dinode *dp, ino_t inumber
                newinpsort = reallocarray(inpsort,
                    (unsigned)newlistmax, sizeof(struct inoinfo *));
                if (newinpsort == NULL)
-                       errexit("cannot increase directory list");
+                       errx(8, "cannot increase directory list");
                inpsort = newinpsort;
                listmax = newlistmax;
        }
@@ -447,7 +446,7 @@ getinoinfo(ino_t inumber)
                        continue;
                return (inp);
        }
-       errexit("cannot find inode %llu\n", (unsigned long long)inumber);
+       errx(8, "cannot find inode %llu", (unsigned long long)inumber);
        return (NULL);
 }
 
@@ -571,7 +570,7 @@ blkerror(ino_t ino, char *type, daddr_t 
                return;
 
        default:
-               errexit("BAD STATE %d TO BLKERR\n", GET_ISTATE(ino));
+               errx(8, "BAD STATE %d TO BLKERR", GET_ISTATE(ino));
                /* NOTREACHED */
        }
 }
Index: main.c
===================================================================
RCS file: /cvs/src/sbin/fsck_ffs/main.c,v
retrieving revision 1.44
diff -u -p -r1.44 main.c
--- main.c      7 Feb 2015 02:09:13 -0000       1.44
+++ main.c      19 Sep 2015 19:09:19 -0000
@@ -38,6 +38,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include <err.h>
 #include <stdio.h>
 #include <unistd.h>
 
@@ -77,8 +78,7 @@ main(int argc, char *argv[])
                        skipclean = 0;
                        cvtlevel = argtoi('c', "conversion level", optarg, 10);
                        if (cvtlevel < 3)
-                               errexit("cannot do level %d conversion\n",
-                                   cvtlevel);
+                               errx(8, "cannot do level %d conversion", 
cvtlevel);
                        break;
 
                case 'd':
@@ -92,7 +92,7 @@ main(int argc, char *argv[])
                case 'm':
                        lfmode = argtoi('m', "mode", optarg, 8);
                        if (lfmode &~ 07777)
-                               errexit("bad mode to -m: %o\n", lfmode);
+                               errx(8, "bad mode to -m: %o", lfmode);
                        printf("** lost+found creation mode %o\n", lfmode);
                        break;
 
@@ -109,8 +109,8 @@ main(int argc, char *argv[])
                        break;
 
                default:
-                       errexit("usage: %s [-fnpy] [-b block#] [-c level] "
-                           "[-m mode] filesystem ...\n", __progname);
+                       errx(8, "usage: %s [-fnpy] [-b block#] [-c level] "
+                           "[-m mode] filesystem ...", __progname);
                }
        }
        argc -= optind;
@@ -139,7 +139,7 @@ argtoi(int flag, char *req, char *str, i
 
        ret = (int)strtol(str, &cp, base);
        if (cp == str || *cp)
-               errexit("-%c flag requires a %s\n", flag, req);
+               errx(8, "-%c flag requires a %s", flag, req);
        return (ret);
 }
 
Index: pass1.c
===================================================================
RCS file: /cvs/src/sbin/fsck_ffs/pass1.c,v
retrieving revision 1.43
diff -u -p -r1.43 pass1.c
--- pass1.c     22 Aug 2015 06:00:27 -0000      1.43
+++ pass1.c     19 Sep 2015 19:09:19 -0000
@@ -36,6 +36,7 @@
 #include <ufs/ufs/dir.h>
 #include <ufs/ffs/fs.h>
 
+#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -140,7 +141,7 @@ pass1(void)
                info = calloc((unsigned)inosused, sizeof(struct inostat));
                inospace = (unsigned)inosused * sizeof(struct inostat);
                if (info == NULL)
-                       errexit("cannot alloc %zu bytes for inoinfo", inospace);
+                       errx(8, "cannot alloc %zu bytes for inoinfo", inospace);
                inostathead[c].il_stat = info;
                /*
                 * Scan the allocated inodes.
@@ -302,7 +303,7 @@ checkinode(ino_t inumber, struct inodesc
                        pfatal("LINK COUNT TABLE OVERFLOW");
                        if (reply("CONTINUE") == 0) {
                                ckfini(0);
-                               errexit("%s", "");
+                               exit(8);
                        }
                } else {
                        zlnp->zlncnt = inumber;
@@ -365,7 +366,7 @@ pass1check(struct inodesc *idesc)
                                printf(" (SKIPPING)\n");
                        else if (reply("CONTINUE") == 0) {
                                ckfini(0);
-                               errexit("%s", "");
+                               exit(8);
                        }
                        return (STOP);
                }
@@ -385,7 +386,7 @@ pass1check(struct inodesc *idesc)
                                        printf(" (SKIPPING)\n");
                                else if (reply("CONTINUE") == 0) {
                                        ckfini(0);
-                                       errexit("%s", "");
+                                       exit(8);
                                }
                                return (STOP);
                        }
@@ -394,7 +395,7 @@ pass1check(struct inodesc *idesc)
                                pfatal("DUP TABLE OVERFLOW.");
                                if (reply("CONTINUE") == 0) {
                                        ckfini(0);
-                                       errexit("%s", "");
+                                       exit(8);
                                }
                                return (STOP);
                        }
Index: pass2.c
===================================================================
RCS file: /cvs/src/sbin/fsck_ffs/pass2.c,v
retrieving revision 1.37
diff -u -p -r1.37 pass2.c
--- pass2.c     20 Jan 2015 18:22:21 -0000      1.37
+++ pass2.c     19 Sep 2015 19:09:19 -0000
@@ -36,6 +36,7 @@
 #include <ufs/ufs/dir.h>
 #include <ufs/ffs/fs.h>
 
+#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -86,10 +87,10 @@ pass2(void)
                pfatal("ROOT INODE UNALLOCATED");
                if (reply("ALLOCATE") == 0) {
                        ckfini(0);
-                       errexit("%s", "");
+                       exit(8);
                }
                if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
-                       errexit("CANNOT ALLOCATE ROOT INODE\n");
+                       errx(8, "CANNOT ALLOCATE ROOT INODE");
                break;
 
        case DCLEAR:
@@ -97,12 +98,12 @@ pass2(void)
                if (reply("REALLOCATE")) {
                        freeino(ROOTINO);
                        if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
-                               errexit("CANNOT ALLOCATE ROOT INODE\n");
+                               errx(8, "CANNOT ALLOCATE ROOT INODE");
                        break;
                }
                if (reply("CONTINUE") == 0) {
                        ckfini(0);
-                       errexit("%s", "");
+                       exit(8);
                }
                break;
 
@@ -112,12 +113,12 @@ pass2(void)
                if (reply("REALLOCATE")) {
                        freeino(ROOTINO);
                        if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
-                               errexit("CANNOT ALLOCATE ROOT INODE\n");
+                               errx(8, "CANNOT ALLOCATE ROOT INODE");
                        break;
                }
                if (reply("FIX") == 0) {
                        ckfini(0);
-                       errexit("%s", "");
+                       exit(8);
                }
                dp = ginode(ROOTINO);
                DIP_SET(dp, di_mode, DIP(dp, di_mode) & ~IFMT);
@@ -129,7 +130,7 @@ pass2(void)
                break;
 
        default:
-               errexit("BAD STATE %d FOR ROOT INODE\n", GET_ISTATE(ROOTINO));
+               errx(8, "BAD STATE %d FOR ROOT INODE", GET_ISTATE(ROOTINO));
        }
        SET_ISTATE(ROOTINO, DFOUND);
        /*
@@ -453,7 +454,7 @@ again:
                        break;
 
                default:
-                       errexit("BAD STATE %d FOR INODE I=%llu\n",
+                       errx(8, "BAD STATE %d FOR INODE I=%llu",
                            GET_ISTATE(dirp->d_ino),
                            (unsigned long long)dirp->d_ino);
                }
Index: pass4.c
===================================================================
RCS file: /cvs/src/sbin/fsck_ffs/pass4.c,v
retrieving revision 1.24
diff -u -p -r1.24 pass4.c
--- pass4.c     20 Jan 2015 18:22:21 -0000      1.24
+++ pass4.c     19 Sep 2015 19:09:19 -0000
@@ -34,6 +34,7 @@
 #include <sys/time.h>
 #include <ufs/ufs/dinode.h>
 #include <ufs/ffs/fs.h>
+#include <err.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -110,7 +111,7 @@ pass4(void)
                                break;
 
                        default:
-                               errexit("BAD STATE %d FOR INODE I=%llu\n",
+                               errx(8, "BAD STATE %d FOR INODE I=%llu",
                                    GET_ISTATE(inumber),
                                    (unsigned long long)inumber);
                        }
Index: pass5.c
===================================================================
RCS file: /cvs/src/sbin/fsck_ffs/pass5.c,v
retrieving revision 1.48
diff -u -p -r1.48 pass5.c
--- pass5.c     20 Jan 2015 18:22:21 -0000      1.48
+++ pass5.c     19 Sep 2015 19:09:19 -0000
@@ -38,6 +38,7 @@
 #include <ufs/ufs/quota.h>
 #include <ufs/ufs/inode.h>
 #include <ufs/ffs/ffs_extern.h>
+#include <err.h>
 #include <stdio.h>
 #include <string.h>
 #include <limits.h>
@@ -162,7 +163,7 @@ pass5(void)
 
        default:
                inomapsize = blkmapsize = sumsize = 0;
-               errexit("UNKNOWN ROTATIONAL TABLE FORMAT %d\n",
+               errx(8, "UNKNOWN ROTATIONAL TABLE FORMAT %d",
                        fs->fs_postblformat);
        }
        memset(&idesc[0], 0, sizeof idesc);
@@ -250,7 +251,7 @@ pass5(void)
                        default:
                                if (j < ROOTINO)
                                        break;
-                               errexit("BAD STATE %d FOR INODE I=%llu\n",
+                               errx(8, "BAD STATE %d FOR INODE I=%llu",
                                    GET_ISTATE(j), (unsigned long long)j);
                        }
                }
Index: setup.c
===================================================================
RCS file: /cvs/src/sbin/fsck_ffs/setup.c,v
retrieving revision 1.57
diff -u -p -r1.57 setup.c
--- setup.c     20 Jan 2015 18:22:21 -0000      1.57
+++ setup.c     19 Sep 2015 19:09:19 -0000
@@ -40,6 +40,7 @@
 #include <sys/dkio.h>
 #include <sys/disklabel.h>
 
+#include <err.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -133,7 +134,7 @@ setup(char *dev)
        sblk.b_un.b_buf = malloc(SBSIZE);
        asblk.b_un.b_buf = malloc(SBSIZE);
        if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
-               errexit("cannot allocate space for superblock\n");
+               errx(8, "cannot allocate space for superblock");
        if ((lp = getdisklabel(NULL, fsreadfd)) != NULL)
                secsize = lp->d_secsize;
        else
@@ -377,7 +378,7 @@ found:
                        pfatal("BAD SUMMARY INFORMATION");
                        if (reply("CONTINUE") == 0) {
                                ckfini(0);
-                               errexit("%s", "");
+                               exit(8);
                        }
                        asked++;
                }
@@ -652,7 +653,7 @@ getdisklabel(char *s, int fd)
                if (s == NULL)
                        return (NULL);
                pwarn("ioctl (GCINFO): %s\n", strerror(errno));
-               errexit("%s: can't read disk label\n", s);
+               errx(8, "%s: can't read disk label", s);
        }
        return (&lab);
 }
Index: utilities.c
===================================================================
RCS file: /cvs/src/sbin/fsck_ffs/utilities.c,v
retrieving revision 1.50
diff -u -p -r1.50 utilities.c
--- utilities.c 5 Sep 2015 20:07:11 -0000       1.50
+++ utilities.c 19 Sep 2015 19:09:19 -0000
@@ -43,6 +43,7 @@
 #include <ctype.h>
 #include <unistd.h>
 #include <limits.h>
+#include <err.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <paths.h>
@@ -126,7 +127,7 @@ inoinfo(ino_t inum)
        int iloff;
 
        if (inum > maxino)
-               errexit("inoinfo: inumber %llu out of range",
+               errx(8, "inoinfo: inumber %llu out of range",
                    (unsigned long long)inum);
        ilp = &inostathead[inum / sblock.fs_ipg];
        iloff = inum % sblock.fs_ipg;
@@ -148,7 +149,7 @@ bufinit(void)
        pbp = pdirbp = NULL;
        bufp = malloc((unsigned int)sblock.fs_bsize);
        if (bufp == 0)
-               errexit("cannot allocate buffer pool\n");
+               errx(8, "cannot allocate buffer pool");
        cgblk.b_un.b_buf = bufp;
        initbarea(&cgblk);
        bufhead.b_next = bufhead.b_prev = &bufhead;
@@ -163,7 +164,7 @@ bufinit(void)
                        free(bufp);
                        if (i >= MINBUFS)
                                break;
-                       errexit("cannot allocate buffer pool\n");
+                       errx(8, "cannot allocate buffer pool");
                }
                bp->b_un.b_buf = bufp;
                bp->b_prev = &bufhead;
@@ -190,7 +191,7 @@ getdatablk(daddr_t blkno, long size)
                if ((bp->b_flags & B_INUSE) == 0)
                        break;
        if (bp == &bufhead)
-               errexit("deadlocked buffer pool\n");
+               errx(8, "deadlocked buffer pool");
        getblk(bp, blkno, size);
        /* FALLTHROUGH */
 foundit:
@@ -252,7 +253,7 @@ rwerror(char *mesg, daddr_t blk)
                printf("\n");
        pfatal("CANNOT %s: BLK %lld", mesg, (long long)blk);
        if (reply("CONTINUE") == 0)
-               errexit("Program terminated\n");
+               errx(8, "Program terminated");
 }
 
 void
@@ -304,7 +305,7 @@ ckfini(int markclean)
                free(bp);
        }
        if (bufhead.b_size != cnt)
-               errexit("Panic: lost %d buffers\n", bufhead.b_size - cnt);
+               errx(8, "Panic: lost %d buffers", bufhead.b_size - cnt);
        pbp = pdirbp = NULL;
        if (markclean && (sblock.fs_clean & FS_ISCLEAN) == 0) {
                /*
@@ -581,7 +582,7 @@ dofix(struct inodesc *idesc, char *msg)
                return (0);
 
        default:
-               errexit("UNKNOWN INODESC FIX MODE %d\n", idesc->id_fix);
+               errx(8, "UNKNOWN INODESC FIX MODE %d", idesc->id_fix);
        }
        /* NOTREACHED */
 }

Reply via email to