sbin/hammer: Change fprintf/exit to err variants [2/2]
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Thu, 15 Dec 2016 07:56:17 +0000 (16:56 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Thu, 15 Dec 2016 19:07:49 +0000 (04:07 +0900)
Change
fprintf(stderr, ...); exit(1);
and
perror(...); exit(1);
to
err(1, ...) or errx(1, ...);
where possible for consistency.

This commit is just conversion to err(3) variants.
Messages themselves are not changed, except for removing
strerror(errno) for err(3), and removing trailing \n,
though err variants add program name in the messages.

err(3) and variants are non standard BSD functions, but HAMMER
userspace has been using BSD stuff aside from the existing
err/errx. Also note that err(3) is available in Linux as well.

15 files changed:
sbin/hammer/blockmap.c
sbin/hammer/cmd_dedup.c
sbin/hammer/cmd_history.c
sbin/hammer/cmd_info.c
sbin/hammer/cmd_mirror.c
sbin/hammer/cmd_pfs.c
sbin/hammer/cmd_recover.c
sbin/hammer/cmd_remote.c
sbin/hammer/cmd_softprune.c
sbin/hammer/cmd_strip.c
sbin/hammer/cmd_version.c
sbin/hammer/cmd_volume.c
sbin/hammer/hammer.c
sbin/newfs_hammer/newfs_hammer.c
usr.bin/undo/undo.c

index 6ef80bb..75712a4 100644 (file)
@@ -166,10 +166,8 @@ again:
                        HAMMER_BLOCKMAP_LAYER2_OFFSET(blockmap->next_offset);
        layer2 = get_buffer_data(layer2_offset, &buffer2, 0);
 
-       if (layer2->zone == HAMMER_ZONE_UNAVAIL_INDEX) {
-               fprintf(stderr, "alloc_blockmap: layer2 ran out of space!\n");
-               exit(1);
-       }
+       if (layer2->zone == HAMMER_ZONE_UNAVAIL_INDEX)
+               errx(1, "alloc_blockmap: layer2 ran out of space!");
 
        /*
         * If we are entering a new big-block assign ownership to our
index 1494e4e..f0a1837 100644 (file)
@@ -917,25 +917,18 @@ scan_pfs(char *filesystem, scan_pfs_cb_t func, const char *id)
                mirror.count = 0;
                mirror.pfs_id = glob_pfs.pfs_id;
                mirror.shared_uuid = glob_pfs.ondisk->shared_uuid;
-               if (ioctl(glob_fd, HAMMERIOC_MIRROR_READ, &mirror) < 0) {
-                       fprintf(stderr, "Mirror-read %s failed: %s\n",
-                               filesystem, strerror(errno));
-                       exit(1);
-               }
-               if (mirror.head.flags & HAMMER_IOC_HEAD_ERROR) {
-                       fprintf(stderr, "Mirror-read %s fatal error %d\n",
+               if (ioctl(glob_fd, HAMMERIOC_MIRROR_READ, &mirror) < 0)
+                       err(1, "Mirror-read %s failed", filesystem);
+               if (mirror.head.flags & HAMMER_IOC_HEAD_ERROR)
+                       errx(1, "Mirror-read %s fatal error %d",
                                filesystem, mirror.head.error);
-                       exit(1);
-               }
                if (mirror.count) {
                        offset = 0;
                        while (offset < mirror.count) {
                                mrec = (void *)((char *)buf + offset);
                                bytes = HAMMER_HEAD_DOALIGN(mrec->head.rec_size);
-                               if (offset + bytes > mirror.count) {
-                                       fprintf(stderr, "Misaligned record\n");
-                                       exit(1);
-                               }
+                               if (offset + bytes > mirror.count)
+                                       errx(1, "Misaligned record");
                                assert((mrec->head.type &
                                       HAMMER_MRECF_TYPE_MASK) ==
                                       HAMMER_MREC_TYPE_REC);
index 978ea00..adfee80 100644 (file)
@@ -160,18 +160,15 @@ parse_attr(const char *s, cmd_attr_t *ca)
        offset = strtoll(s + 1, &rptr, 0);
        if (test_strtoll(errno, offset)) {
                *rptr = '\0';  /* side effect */
-               printf("%s: %s\n", strerror(errno), s);
-               exit(1);
+               err(1, "%s", s);
        }
        ca->offset = offset;
 
        if (*rptr == ',') {
                errno = 0;  /* clear */
                length = strtol(rptr + 1, NULL, 0);
-               if (test_strtol(errno, length)) {
-                       printf("%s: %s\n", strerror(errno), rptr);
-                       exit(1);
-               }
+               if (test_strtol(errno, length))
+                       err(1, "%s", rptr);
                if (length >= 0)
                        ca->length = length;
        }
index e7b855a..d370eb1 100644 (file)
@@ -100,25 +100,19 @@ show_info(char *path)
        usedbytes = totalbytes = rsvbytes = freebytes = 0;
 
        fip = libhammer_get_fsinfo(path);
-       if (fip == NULL) {
-               perror("libhammer_get_fsinfo");
-               exit(EXIT_FAILURE);
-       }
+       if (fip == NULL)
+               errx(1, "libhammer_get_fsinfo");
 
        /* Find out the UUID strings */
        uuid_to_string(&fip->vol_fsid, &fsid, NULL);
 
        /* Get the volume paths */
-       if (hammer_fs_to_vol(path, &ioc) == -1) {
-               fprintf(stderr, "Failed to get volume paths\n");
-               exit(1);
-       }
+       if (hammer_fs_to_vol(path, &ioc) == -1)
+               errx(1, "Failed to get volume paths");
 
        /* Get the root volume path */
-       if (hammer_fs_to_rootvol(path, rootvol, sizeof(rootvol)) == -1) {
-               fprintf(stderr, "Failed to get root volume path\n");
-               exit(1);
-       }
+       if (hammer_fs_to_rootvol(path, rootvol, sizeof(rootvol)) == -1)
+               errx(1, "Failed to get root volume path");
 
        /* Volume information */
        printf("Volume identification\n");
index 686b25d..8fd69c1 100644 (file)
@@ -290,17 +290,13 @@ again:
                if (ioctl(fd, HAMMERIOC_MIRROR_READ, &mirror) < 0) {
                        score_printf(LINE3, "Mirror-read %s failed: %s",
                                     filesystem, strerror(errno));
-                       fprintf(stderr, "Mirror-read %s failed: %s\n",
-                               filesystem, strerror(errno));
-                       exit(1);
+                       err(1, "Mirror-read %s failed", filesystem);
                }
                if (mirror.head.flags & HAMMER_IOC_HEAD_ERROR) {
                        score_printf(LINE3, "Mirror-read %s fatal error %d",
                                     filesystem, mirror.head.error);
-                       fprintf(stderr,
-                               "Mirror-read %s fatal error %d\n",
+                       errx(1, "Mirror-read %s fatal error %d",
                                filesystem, mirror.head.error);
-                       exit(1);
                }
                if (mirror.count) {
                        if (BandwidthOpt) {
@@ -314,11 +310,8 @@ again:
                                             "Mirror-read %s failed: "
                                             "short write",
                                             filesystem);
-                               fprintf(stderr,
-                                       "Mirror-read %s failed: "
-                                       "short write\n",
-                               filesystem);
-                               exit(1);
+                               errx(1, "Mirror-read %s failed: short write",
+                                       filesystem);
                        }
                }
                total_bytes += mirror.count;
@@ -391,9 +384,8 @@ done:
                if (mrec == NULL ||
                    mrec->head.type != HAMMER_MREC_TYPE_UPDATE ||
                    mrec->head.rec_size != sizeof(mrec->update)) {
-                       fprintf(stderr, "mirror_read: Did not get final "
-                                       "acknowledgement packet from target\n");
-                       exit(1);
+                       errx(1, "mirror_read: Did not get final "
+                               "acknowledgement packet from target");
                }
                if (interrupted) {
                        if (CyclePath) {
@@ -558,17 +550,11 @@ generate_histogram(int fd, const char *filesystem,
        chunkno = 0;
        for (;;) {
                mirror.count = 0;
-               if (ioctl(fd, HAMMERIOC_MIRROR_READ, &mirror) < 0) {
-                       fprintf(stderr, "Mirror-read %s failed: %s\n",
-                               filesystem, strerror(errno));
-                       exit(1);
-               }
-               if (mirror.head.flags & HAMMER_IOC_HEAD_ERROR) {
-                       fprintf(stderr,
-                               "Mirror-read %s fatal error %d\n",
+               if (ioctl(fd, HAMMERIOC_MIRROR_READ, &mirror) < 0)
+                       err(1, "Mirror-read %s failed", filesystem);
+               if (mirror.head.flags & HAMMER_IOC_HEAD_ERROR)
+                       errx(1, "Mirror-read %s fatal error %d",
                                filesystem, mirror.head.error);
-                       exit(1);
-               }
                for (off = 0;
                     off < mirror.count;
                     off += HAMMER_HEAD_DOALIGN(mrec->head.rec_size)) {
@@ -712,10 +698,8 @@ create_pfs(const char *filesystem, uuid_t *s_uuid)
                        "Do you want to create a new slave PFS? [y/n] ",
                        filesystem);
                fflush(stderr);
-               if (getyntty() != 1) {
-                       fprintf(stderr, "Aborting operation\n");
-                       exit(1);
-               }
+               if (getyntty() != 1)
+                       errx(1, "Aborting operation");
        }
 
        uint32_t status;
@@ -728,8 +712,7 @@ create_pfs(const char *filesystem, uuid_t *s_uuid)
        free(shared_uuid);
 
        if (cmd == NULL) {
-               fprintf(stderr, "Failed to alloc memory\n");
-               exit(1);
+               errx(1, "Failed to alloc memory");
        }
        if (system(cmd) != 0) {
                fprintf(stderr, "Failed to create PFS\n");
@@ -798,7 +781,7 @@ again:
        mrec = read_mrecord(0, &error, &pickup);
        if (mrec == NULL) {
                if (error == 0)
-                       fprintf(stderr, "validate_mrec_header: short read\n");
+                       errx(1, "validate_mrec_header: short read");
                exit(1);
        }
        /*
@@ -808,16 +791,11 @@ again:
                free(buf);
                return;
        }
-       if (mrec->head.type != HAMMER_MREC_TYPE_PFSD) {
-               fprintf(stderr, "validate_mrec_header: did not get expected "
-                               "PFSD record type\n");
-               exit(1);
-       }
-       if (mrec->head.rec_size != sizeof(mrec->pfs)) {
-               fprintf(stderr, "validate_mrec_header: unexpected payload "
-                               "size\n");
-               exit(1);
-       }
+       if (mrec->head.type != HAMMER_MREC_TYPE_PFSD)
+               errx(1, "validate_mrec_header: did not get expected "
+                       "PFSD record type");
+       if (mrec->head.rec_size != sizeof(mrec->pfs))
+               errx(1, "validate_mrec_header: unexpected payload size");
 
        /*
         * Create slave PFS if it doesn't yet exist
@@ -873,25 +851,17 @@ again:
                mirror.size = read_mrecords(0, buf, SERIALBUF_SIZE, &pickup);
                if (mirror.size <= 0)
                        break;
-               if (ioctl(fd, HAMMERIOC_MIRROR_WRITE, &mirror) < 0) {
-                       fprintf(stderr, "Mirror-write %s failed: %s\n",
-                               filesystem, strerror(errno));
-                       exit(1);
-               }
-               if (mirror.head.flags & HAMMER_IOC_HEAD_ERROR) {
-                       fprintf(stderr,
-                               "Mirror-write %s fatal error %d\n",
+               if (ioctl(fd, HAMMERIOC_MIRROR_WRITE, &mirror) < 0)
+                       err(1, "Mirror-write %s failed", filesystem);
+               if (mirror.head.flags & HAMMER_IOC_HEAD_ERROR)
+                       errx(1, "Mirror-write %s fatal error %d",
                                filesystem, mirror.head.error);
-                       exit(1);
-               }
 #if 0
                if (mirror.head.flags & HAMMER_IOC_HEAD_INTR) {
-                       fprintf(stderr,
-                               "Mirror-write %s interrupted by timer at"
-                               " %016llx\n",
+                       errx(1, "Mirror-write %s interrupted by timer at"
+                               " %016llx",
                                filesystem,
                                mirror.key_cur.obj_id);
-                       exit(0);
                }
 #endif
        }
@@ -913,11 +883,9 @@ again:
            (mrec->head.type != HAMMER_MREC_TYPE_SYNC &&
             mrec->head.type != HAMMER_MREC_TYPE_IDLE) ||
            mrec->head.rec_size != sizeof(mrec->sync)) {
-               fprintf(stderr, "Mirror-write %s: Did not get termination "
-                               "sync record, or rec_size is wrong rt=%d\n",
-                               filesystem,
-                               (mrec ? (int)mrec->head.type : -1));
-               exit(1);
+               errx(1, "Mirror-write %s: Did not get termination "
+                       "sync record, or rec_size is wrong rt=%d",
+                       filesystem, (mrec ? (int)mrec->head.type : -1));
        }
 
        /*
@@ -1005,10 +973,8 @@ again:
                while (offset < size) {
                        mrec = (void *)((char *)buf + offset);
                        bytes = HAMMER_HEAD_DOALIGN(mrec->head.rec_size);
-                       if (offset + bytes > size) {
-                               fprintf(stderr, "Misaligned record\n");
-                               exit(1);
-                       }
+                       if (offset + bytes > size)
+                               errx(1, "Misaligned record");
 
                        switch(mrec->head.type & HAMMER_MRECF_TYPE_MASK) {
                        case HAMMER_MREC_TYPE_REC_BADCRC:
@@ -1102,10 +1068,8 @@ hammer_cmd_mirror_copy(char **av, int ac, int streaming)
        signal(SIGPIPE, SIG_IGN);
 
 again:
-       if (pipe(fds) < 0) {
-               perror("pipe");
-               exit(1);
-       }
+       if (pipe(fds) < 0)
+               err(1, "pipe");
 
        /*
         * Source
@@ -1308,22 +1272,16 @@ read_mrecords(int fd, char *buf, u_int size, hammer_ioc_mrecord_head_t pickup)
                        }
                        if (n == 0)
                                break;
-                       if (n != HAMMER_MREC_HEADSIZE) {
-                               fprintf(stderr, "read_mrecords: short read on pipe\n");
-                               exit(1);
-                       }
-                       if (pickup->signature != HAMMER_IOC_MIRROR_SIGNATURE) {
-                               fprintf(stderr, "read_mrecords: malformed record on pipe, "
-                                       "bad signature\n");
-                               exit(1);
-                       }
+                       if (n != HAMMER_MREC_HEADSIZE)
+                               errx(1, "read_mrecords: short read on pipe");
+                       if (pickup->signature != HAMMER_IOC_MIRROR_SIGNATURE)
+                               errx(1, "read_mrecords: malformed record on pipe, "
+                                       "bad signature");
                }
                if (pickup->rec_size < HAMMER_MREC_HEADSIZE ||
-                   pickup->rec_size > sizeof(*mrec) + HAMMER_XBUFSIZE) {
-                       fprintf(stderr, "read_mrecords: malformed record on pipe, "
-                               "illegal rec_size\n");
-                       exit(1);
-               }
+                   pickup->rec_size > sizeof(*mrec) + HAMMER_XBUFSIZE)
+                       errx(1, "read_mrecords: malformed record on pipe, "
+                               "illegal rec_size");
 
                /*
                 * Stop if we have insufficient space for the record and data.
@@ -1355,10 +1313,8 @@ read_mrecords(int fd, char *buf, u_int size, hammer_ioc_mrecord_head_t pickup)
                        if (i <= 0)
                                break;
                }
-               if (n != bytes) {
-                       fprintf(stderr, "read_mrecords: short read on pipe\n");
-                       exit(1);
-               }
+               if (n != bytes)
+                       errx(1, "read_mrecords: short read on pipe");
 
                bcopy(pickup, buf + count, HAMMER_MREC_HEADSIZE);
                pickup->signature = 0;
@@ -1368,11 +1324,8 @@ read_mrecords(int fd, char *buf, u_int size, hammer_ioc_mrecord_head_t pickup)
                /*
                 * Validate the completed record
                 */
-               if (!hammer_crc_test_mrec_head(&mrec->head, mrec->head.rec_size)) {
-                       fprintf(stderr, "read_mrecords: malformed record "
-                                       "on pipe, bad crc\n");
-                       exit(1);
-               }
+               if (!hammer_crc_test_mrec_head(&mrec->head, mrec->head.rec_size))
+                       errx(1, "read_mrecords: malformed record on pipe, bad crc");
 
                /*
                 * If its a B-Tree record validate the data crc.
@@ -1385,10 +1338,8 @@ read_mrecords(int fd, char *buf, u_int size, hammer_ioc_mrecord_head_t pickup)
                if (type == HAMMER_MREC_TYPE_REC) {
                        if (mrec->head.rec_size <
                            sizeof(mrec->rec) + mrec->rec.leaf.data_len) {
-                               fprintf(stderr,
-                                       "read_mrecords: malformed record on "
-                                       "pipe, illegal element data_len\n");
-                               exit(1);
+                               errx(1, "read_mrecords: malformed record on "
+                                       "pipe, illegal element data_len");
                        }
                        if (mrec->rec.leaf.data_len &&
                            mrec->rec.leaf.data_offset &&
@@ -1490,18 +1441,12 @@ write_mrecord(int fdout, uint32_t type, hammer_ioc_mrecord_any_t mrec,
        mrec->head.type = type;
        mrec->head.rec_size = bytes;
        hammer_crc_set_mrec_head(&mrec->head, bytes);
-       if (write(fdout, mrec, bytes) != bytes) {
-               fprintf(stderr, "write_mrecord: error %d (%s)\n",
-                       errno, strerror(errno));
-               exit(1);
-       }
+       if (write(fdout, mrec, bytes) != bytes)
+               err(1, "write_mrecord");
        if (pad) {
                bzero(zbuf, pad);
-               if (write(fdout, zbuf, pad) != pad) {
-                       fprintf(stderr, "write_mrecord: error %d (%s)\n",
-                               errno, strerror(errno));
-                       exit(1);
-               }
+               if (write(fdout, zbuf, pad) != pad)
+                       err(1, "write_mrecord");
        }
 }
 
@@ -1518,14 +1463,10 @@ generate_mrec_header(int fd, int pfs_id,
        bzero(mrec_tmp, sizeof(*mrec_tmp));
        clrpfs(&pfs, &mrec_tmp->pfs.pfsd, pfs_id);
 
-       if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) != 0) {
-               fprintf(stderr, "Mirror-read: not a HAMMER fs/pseudofs!\n");
-               exit(1);
-       }
-       if (pfs.version != HAMMER_IOC_PSEUDOFS_VERSION) {
-               fprintf(stderr, "Mirror-read: HAMMER PFS version mismatch!\n");
-               exit(1);
-       }
+       if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) != 0)
+               err(1, "Mirror-read: not a HAMMER fs/pseudofs!");
+       if (pfs.version != HAMMER_IOC_PSEUDOFS_VERSION)
+               errx(1, "Mirror-read: HAMMER PFS version mismatch!");
        mrec_tmp->pfs.version = pfs.version;
 }
 
@@ -1549,19 +1490,15 @@ validate_mrec_header(int fd, int fdin, int is_target, int pfs_id,
         * Get the PFSD info from the target filesystem.
         */
        clrpfs(&pfs, &pfsd, pfs_id);
-       if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) != 0) {
-               fprintf(stderr, "mirror-write: not a HAMMER fs/pseudofs!\n");
-               exit(1);
-       }
-       if (pfs.version != HAMMER_IOC_PSEUDOFS_VERSION) {
-               fprintf(stderr, "mirror-write: HAMMER PFS version mismatch!\n");
-               exit(1);
-       }
+       if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) != 0)
+               err(1, "mirror-write: not a HAMMER fs/pseudofs!");
+       if (pfs.version != HAMMER_IOC_PSEUDOFS_VERSION)
+               errx(1, "mirror-write: HAMMER PFS version mismatch!");
 
        mrec = read_mrecord(fdin, &error, pickup);
        if (mrec == NULL) {
                if (error == 0)
-                       fprintf(stderr, "validate_mrec_header: short read\n");
+                       errx(1, "validate_mrec_header: short read");
                exit(1);
        }
        if (mrec->head.type == HAMMER_MREC_TYPE_TERM) {
@@ -1569,35 +1506,23 @@ validate_mrec_header(int fd, int fdin, int is_target, int pfs_id,
                return(-1);
        }
 
-       if (mrec->head.type != HAMMER_MREC_TYPE_PFSD) {
-               fprintf(stderr, "validate_mrec_header: did not get expected "
-                               "PFSD record type\n");
-               exit(1);
-       }
-       if (mrec->head.rec_size != sizeof(mrec->pfs)) {
-               fprintf(stderr, "validate_mrec_header: unexpected payload "
-                               "size\n");
-               exit(1);
-       }
-       if (mrec->pfs.version != pfs.version) {
-               fprintf(stderr, "validate_mrec_header: Version mismatch\n");
-               exit(1);
-       }
+       if (mrec->head.type != HAMMER_MREC_TYPE_PFSD)
+               errx(1, "validate_mrec_header: did not get expected "
+                       "PFSD record type");
+       if (mrec->head.rec_size != sizeof(mrec->pfs))
+               errx(1, "validate_mrec_header: unexpected payload size");
+       if (mrec->pfs.version != pfs.version)
+               errx(1, "validate_mrec_header: Version mismatch");
 
        /*
         * Whew.  Ok, is the read PFS info compatible with the target?
         */
        if (bcmp(&mrec->pfs.pfsd.shared_uuid, &pfsd.shared_uuid,
-                sizeof(pfsd.shared_uuid)) != 0) {
-               fprintf(stderr,
-                       "mirror-write: source and target have "
-                       "different shared-uuid's!\n");
-               exit(1);
-       }
-       if (is_target && hammer_is_pfs_master(&pfsd)) {
-               fprintf(stderr, "mirror-write: target must be in slave mode\n");
-               exit(1);
-       }
+               sizeof(pfsd.shared_uuid)) != 0)
+               errx(1, "mirror-write: source and target have "
+                       "different shared-uuid's!");
+       if (is_target && hammer_is_pfs_master(&pfsd))
+               errx(1, "mirror-write: target must be in slave mode");
        if (tid_begp)
                *tid_begp = mrec->pfs.pfsd.sync_beg_tid;
        if (tid_endp)
@@ -1613,16 +1538,13 @@ update_pfs_snapshot(int fd, hammer_tid_t snapshot_tid, int pfs_id)
        struct hammer_pseudofs_data pfsd;
 
        clrpfs(&pfs, &pfsd, pfs_id);
-       if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) != 0) {
-               perror("update_pfs_snapshot (read)");
-               exit(1);
-       }
+       if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) != 0)
+               err(1, "update_pfs_snapshot (read)");
+
        if (pfsd.sync_end_tid != snapshot_tid) {
                pfsd.sync_end_tid = snapshot_tid;
-               if (ioctl(fd, HAMMERIOC_SET_PSEUDOFS, &pfs) != 0) {
-                       perror("update_pfs_snapshot (rewrite)");
-                       exit(1);
-               }
+               if (ioctl(fd, HAMMERIOC_SET_PSEUDOFS, &pfs) != 0)
+                       err(1, "update_pfs_snapshot (rewrite)");
                if (VerboseOpt >= 2) {
                        fprintf(stderr,
                                "Mirror-write: Completed, updated snapshot "
@@ -1755,17 +1677,15 @@ hammer_check_restrict(const char *filesystem)
        if (RestrictTarget == NULL)
                return;
        rlen = strlen(RestrictTarget);
-       if (strncmp(filesystem, RestrictTarget, rlen) != 0) {
-               fprintf(stderr, "hammer-remote: restricted target\n");
-               exit(1);
-       }
+       if (strncmp(filesystem, RestrictTarget, rlen) != 0)
+               errx(1, "hammer-remote: restricted target");
+
        atslash = 1;
        while (filesystem[rlen]) {
                if (atslash &&
                    filesystem[rlen] == '.' &&
                    filesystem[rlen+1] == '.') {
-                       fprintf(stderr, "hammer-remote: '..' not allowed\n");
-                       exit(1);
+                       errx(1, "hammer-remote: '..' not allowed");
                }
                if (filesystem[rlen] == '/')
                        atslash = 1;
index 80462b4..59b10d2 100644 (file)
@@ -115,21 +115,17 @@ getpfs(struct hammer_ioc_pseudofs_rw *pfs, const char *path)
         * commands can take a regular file/directory (e.g. pfs-status).
         */
        fd = open(path, O_RDONLY);
-       if (fd < 0) {
-               fprintf(stderr, "Failed to open %s\n", path);
-               exit(1);
-       }
+       if (fd < 0)
+               err(1, "Failed to open %s", path);
 
        /*
         * If pfs.pfs_id has been set to non -1, the file descriptor fd
         * could be any fd of HAMMER inodes since HAMMERIOC_GET_PSEUDOFS
         * doesn't depend on inode attributes if it's set to a valid id.
         */
-       if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, pfs) < 0) {
-               fprintf(stderr, "Cannot access %s: %s\n",
-                       path, strerror(errno));
-               exit(1);
-       }
+       if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, pfs) < 0)
+               err(1, "Cannot access %s", path);
+
        return(fd);
 }
 
@@ -257,11 +253,9 @@ hammer_cmd_pseudofs_create(char **av, int ac, int is_slave)
                pseudofs_usage(1);
        path = av[0];
        if (lstat(path, &st) == 0) {
-               fprintf(stderr, "Cannot create %s, file exists!\n", path);
-               exit(1);
+               errx(1, "Cannot create %s, file exists!", path);
        } else if (path[strlen(path) - 1] == '/') {
-               fprintf(stderr, "Invalid PFS path %s with trailing /\n", path);
-               exit(1);
+               errx(1, "Invalid PFS path %s with trailing /", path);
        }
 
        /*
@@ -270,10 +264,8 @@ hammer_cmd_pseudofs_create(char **av, int ac, int is_slave)
         */
        dirpath = dirname(path);
        fd = open(dirpath, O_RDONLY);
-       if (fd < 0) {
-               fprintf(stderr, "Cannot open directory %s\n", dirpath);
-               exit(1);
-       }
+       if (fd < 0)
+               err(1, "Cannot open directory %s", dirpath);
 
        /*
         * Avoid foot-shooting.  Don't let the user create a PFS
@@ -297,21 +289,15 @@ hammer_cmd_pseudofs_create(char **av, int ac, int is_slave)
        for (pfs_id = 0; pfs_id < HAMMER_MAX_PFS; ++pfs_id) {
                clrpfs(&pfs, &pfsd, pfs_id);
                if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) < 0) {
-                       if (errno != ENOENT) {
-                               fprintf(stderr, "Cannot create %s, got %s during scan\n",
-                                       path, strerror(errno));
-                               exit(1);
-                       }
+                       if (errno != ENOENT)
+                               err(1, "Cannot create %s", path);
                        break;
                }
        }
        if (pfs_id == HAMMER_MAX_PFS) {
-               fprintf(stderr, "Cannot create %s, all PFSs in use\n", path);
-               exit(1);
+               errx(1, "Cannot create %s, all PFSs in use", path);
        } else if (pfs_id == HAMMER_ROOT_PFSID) {
-               fprintf(stderr, "Fatal error: PFS#%d must exist\n",
-                       HAMMER_ROOT_PFSID);
-               exit(1);
+               errx(1, "Fatal error: PFS#%d must exist", HAMMER_ROOT_PFSID);
        }
 
        /*
@@ -350,29 +336,23 @@ hammer_cmd_pseudofs_destroy(char **av, int ac)
                pseudofs_usage(1);
        fd = getpfs(&pfs, av[0]);
 
-       if (pfs.pfs_id == HAMMER_ROOT_PFSID) {
-               fprintf(stderr, "You cannot destroy PFS#0\n");
-               exit(1);
-       }
+       if (pfs.pfs_id == HAMMER_ROOT_PFSID)
+               errx(1, "You cannot destroy PFS#0");
+
        printf("You have requested that PFS#%d (%s) be destroyed\n",
                pfs.pfs_id, pfs.ondisk->label);
        printf("This will irrevocably destroy all data on this PFS!!!!!\n");
        printf("Do you really want to do this? [y/n] ");
        fflush(stdout);
-       if (getyn() == 0) {
-               fprintf(stderr, "No action taken on PFS#%d\n", pfs.pfs_id);
-               exit(1);
-       }
+       if (getyn() == 0)
+               errx(1, "No action taken on PFS#%d", pfs.pfs_id);
 
        if (hammer_is_pfs_master(pfs.ondisk)) {
                printf("This PFS is currently setup as a MASTER!\n");
                printf("Are you absolutely sure you want to destroy it? [y/n] ");
                fflush(stdout);
-               if (getyn() == 0) {
-                       fprintf(stderr, "No action taken on PFS#%d\n",
-                               pfs.pfs_id);
-                       exit(1);
-               }
+               if (getyn() == 0)
+                       errx(1, "No action taken on PFS#%d", pfs.pfs_id);
        }
 
        printf("Destroying PFS#%d (%s)", pfs.pfs_id, pfs.ondisk->label);
@@ -421,12 +401,10 @@ hammer_cmd_pseudofs_upgrade(char **av, int ac)
        fd = getpfs(&pfs, av[0]);
 
        if (pfs.pfs_id == HAMMER_ROOT_PFSID) {
-               fprintf(stderr, "You cannot upgrade PFS#0"
-                               " (It should already be a master)\n");
-               exit(1);
+               errx(1, "You cannot upgrade PFS#0"
+                       " (It should already be a master)");
        } else if (hammer_is_pfs_master(pfs.ondisk)) {
-               printf("It is already a master\n");
-               exit(1);
+               errx(1, "It is already a master");
        }
 
        if (ioctl(fd, HAMMERIOC_UPG_PSEUDOFS, &pfs) == 0) {
@@ -450,11 +428,9 @@ hammer_cmd_pseudofs_downgrade(char **av, int ac)
        fd = getpfs(&pfs, av[0]);
 
        if (pfs.pfs_id == HAMMER_ROOT_PFSID) {
-               fprintf(stderr, "You cannot downgrade PFS#0\n");
-               exit(1);
+               errx(1, "You cannot downgrade PFS#0");
        } else if (hammer_is_pfs_slave(pfs.ondisk)) {
-               printf("It is already a slave\n");
-               exit(1);
+               errx(1, "It is already a slave");
        }
 
        if (ioctl(fd, HAMMERIOC_DGD_PSEUDOFS, &pfs) == 0) {
@@ -484,25 +460,20 @@ hammer_cmd_pseudofs_update(char **av, int ac)
                parse_pfsd_options(av + 1, ac - 1, pfs.ondisk);
                if (hammer_is_pfs_slave(pfs.ondisk) &&
                    pfs.pfs_id == HAMMER_ROOT_PFSID) {
-                       printf("The real mount point cannot be made a PFS "
+                       errx(1, "The real mount point cannot be made a PFS "
                               "slave, only PFS sub-directories can be made "
-                              "slaves\n");
-                       exit(1);
+                              "slaves");
                }
                pfs.bytes = sizeof(*pfs.ondisk);
                if (ioctl(fd, HAMMERIOC_SET_PSEUDOFS, &pfs) == 0) {
                        if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) == 0) {
                                dump_pfsd(pfs.ondisk, fd);
                        } else {
-                               printf("Unable to retrieve PFS configuration "
-                                       "after successful update: %s\n",
-                                       strerror(errno));
-                               exit(1);
+                               err(1, "Unable to retrieve PFS configuration "
+                                       "after successful update");
                        }
                } else {
-                       printf("Unable to adjust PFS configuration: %s\n",
-                               strerror(errno));
-                       exit(1);
+                       err(1, "Unable to adjust PFS configuration");
                }
        }
        relpfs(fd, &pfs);
@@ -604,12 +575,8 @@ parse_pfsd_options(char **av, int ac, hammer_pseudofs_data_t pfsd)
                /*
                 * Basic assignment value test
                 */
-               if (ptr == NULL) {
-                       fprintf(stderr,
-                               "option %s requires an assignment\n",
-                               cmd);
-                       exit(1);
-               }
+               if (ptr == NULL)
+                       errx(1, "option %s requires an assignment", cmd);
 
                status = uuid_s_ok;
                if (strcmp(cmd, "sync-beg-tid") == 0) {
@@ -626,10 +593,7 @@ parse_pfsd_options(char **av, int ac, hammer_pseudofs_data_t pfsd)
                                ptr[len-1] = 0;
                                ++ptr;
                        } else if (ptr[0] == '"') {
-                               fprintf(stderr,
-                                       "option %s: malformed string\n",
-                                       cmd);
-                               exit(1);
+                               errx(1, "option %s: malformed string", cmd);
                        }
                        snprintf(pfsd->label, sizeof(pfsd->label), "%s", ptr);
                } else if (strcmp(cmd, "snapshots") == 0) {
@@ -646,10 +610,8 @@ parse_pfsd_options(char **av, int ac, hammer_pseudofs_data_t pfsd)
                                exit(1);
                        }
                        if (len >= (int)sizeof(pfsd->snapshots)) {
-                               fprintf(stderr,
-                                       "option %s: path too long, %d "
-                                       "character limit\n", cmd, len);
-                               exit(1);
+                               errx(1, "option %s: path too long, %d "
+                                       "character limit", cmd, len);
                        }
                        snprintf(pfsd->snapshots, sizeof(pfsd->snapshots),
                                 "%s", ptr);
@@ -658,19 +620,14 @@ parse_pfsd_options(char **av, int ac, hammer_pseudofs_data_t pfsd)
                } else if (strcmp(cmd, "prune-min") == 0) {
                        pfsd->prune_min = timetosecs(ptr);
                        if (pfsd->prune_min < 0) {
-                               fprintf(stderr,
-                                       "option %s: illegal time spec, "
-                                       "use Nd or [Nd/]hh[:mm[:ss]]\n", ptr);
-                               exit(1);
+                               errx(1, "option %s: illegal time spec, "
+                                       "use Nd or [Nd/]hh[:mm[:ss]]", ptr);
                        }
                } else {
-                       fprintf(stderr, "invalid option: %s\n", cmd);
-                       exit(1);
+                       errx(1, "invalid option: %s", cmd);
                }
                if (status != uuid_s_ok) {
-                       fprintf(stderr, "option %s: error parsing uuid %s\n",
-                               cmd, ptr);
-                       exit(1);
+                       errx(1, "option %s: error parsing uuid %s", cmd, ptr);
                }
                --ac;
                ++av;
index a1f70f5..34a9c76 100644 (file)
@@ -135,10 +135,8 @@ hammer_cmd_recover(char **av, int ac)
        int full = 0;
        int quick = 0;
 
-       if (ac < 1) {
-               fprintf(stderr, "hammer recover <target_dir> [full|quick]\n");
-               exit(1);
-       }
+       if (ac < 1)
+               errx(1, "hammer recover <target_dir> [full|quick]");
 
        TargetDir = av[0];
        if (ac > 1) {
@@ -150,10 +148,8 @@ hammer_cmd_recover(char **av, int ac)
        assert(!full || !quick);
 
        if (mkdir(TargetDir, 0777) == -1) {
-               if (errno != EEXIST) {
-                       perror("mkdir");
-                       exit(1);
-               }
+               if (errno != EEXIST)
+                       err(1, "mkdir");
        }
 
        printf("Running %sraw scan of HAMMER image, recovering to %s\n",
index f41596d..1ef5a55 100644 (file)
@@ -46,10 +46,9 @@ hammer_cmd_sshremote(const char *cmd, const char *target)
        const char *av[REMOTE_MAXARGS + 1];
        int ac;
 
-       if ((env = getenv("SSH_ORIGINAL_COMMAND")) == NULL) {
-               fprintf(stderr, "SSH_ORIGINAL_COMMAND env missing\n");
-               exit(1);
-       }
+       if ((env = getenv("SSH_ORIGINAL_COMMAND")) == NULL)
+               errx(1, "SSH_ORIGINAL_COMMAND env missing");
+
        dup = env = strdup(env);
        av[0] = "hammer";
        av[1] = "-R";
@@ -59,14 +58,11 @@ hammer_cmd_sshremote(const char *cmd, const char *target)
        ac = 5;
 
        str = strsep(&env, " \t\r\n");
-       if (str == NULL) {
-               fprintf(stderr, "hammer-remote: null command\n");
-               exit(1);
-       }
-       if (strstr(str, "hammer") == NULL) {
-               fprintf(stderr, "hammer-remote: Command not 'hammer'\n");
-               exit(1);
-       }
+       if (str == NULL)
+               errx(1, "hammer-remote: null command");
+
+       if (strstr(str, "hammer") == NULL)
+               errx(1, "hammer-remote: Command not 'hammer'");
 
        while (ac < REMOTE_MAXARGS) {
                av[ac] = strsep(&env, " \t\r\n");
@@ -76,6 +72,5 @@ hammer_cmd_sshremote(const char *cmd, const char *target)
        }
        free(dup);
        execv("/sbin/hammer", (void *)av);
-       fprintf(stderr, "hammer-remote: execv failed\n");
-       exit(1);
+       err(1, "hammer-remote: execv failed");
 }
index a1f77bd..656ee44 100644 (file)
@@ -132,11 +132,9 @@ hammer_cmd_softprune(char **av, int ac, int everything_opt)
        /*
         * XXX future (need to store separate cycles for each filesystem)
         */
-       if (base->next) {
-               fprintf(stderr, "Currently only one HAMMER filesystem may "
-                               "be specified in the softlink scan\n");
-               exit(1);
-       }
+       if (base->next)
+               errx(1, "Currently only one HAMMER filesystem may "
+                       "be specified in the softlink scan");
 
        /*
         * Issue the prunes
index 7512396..979397e 100644 (file)
@@ -160,10 +160,8 @@ hammer_ask_yn(void)
        printf("Do you really want to do this? [y/n] ");
        fflush(stdout);
 
-       if (getyn() == 0) {
-               fprintf(stderr, "No action taken\n");
-               exit(1);
-       }
+       if (getyn() == 0)
+               errx(1, "No action taken");
 
        printf("Stripping HAMMER filesystem (%s)", vol->ondisk->vol_label);
 
index 07df6ae..605a68e 100644 (file)
@@ -52,21 +52,17 @@ hammer_cmd_get_version(char **av, int ac)
        if (ac != 1)
                errx(1, "hammer version - expected a single <fs> path arg");
         fd = open(av[0], O_RDONLY);
-       if (fd < 0) {
-               fprintf(stderr, "hammer version: unable to access %s: %s\n",
-                       av[0], strerror(errno));
-               exit(1);
-       }
+       if (fd < 0)
+               err(1, "hammer version: unable to access %s", av[0]);
 
        /*
         * version.cur_version must be set to 0 to retrieve current version
         * info.
         */
        bzero(&version, sizeof(version));
-       if (ioctl(fd, HAMMERIOC_GET_VERSION, &version) < 0) {
-               fprintf(stderr, "hammer version ioctl: %s\n", strerror(errno));
-               exit(1);
-       }
+       if (ioctl(fd, HAMMERIOC_GET_VERSION, &version) < 0)
+               err(1, "hammer version ioctl");
+
        snprintf(wip, 16, "%d", version.wip_version);
        printf("min=%d wip=%s max=%d current=%d description=\"%s\"\n",
                version.min_version,
@@ -105,49 +101,32 @@ hammer_cmd_set_version(char **av, int ac)
        int overs;
        int nvers;
 
-       if (ac < 2 || ac > 3 || (ac == 3 && strcmp(av[2], "force") != 0)) {
-               fprintf(stderr,
-                       "hammer version-upgrade: expected <fs> vers# [force]\n");
-               exit(1);
-       }
+       if (ac < 2 || ac > 3 || (ac == 3 && strcmp(av[2], "force") != 0))
+               errx(1, "hammer version-upgrade: expected <fs> vers# [force]");
 
         fd = open(av[0], O_RDONLY);
-       if (fd < 0) {
-               fprintf(stderr, "hammer version-upgrade: unable to access %s: %s\n",
-                       av[0], strerror(errno));
-               exit(1);
-       }
+       if (fd < 0)
+               err(1, "hammer version-upgrade: unable to access %s", av[0]);
 
        bzero(&version, sizeof(version));
-       if (ioctl(fd, HAMMERIOC_GET_VERSION, &version) < 0) {
-               fprintf(stderr, "hammer ioctl: %s\n", strerror(errno));
-               exit(1);
-       }
+       if (ioctl(fd, HAMMERIOC_GET_VERSION, &version) < 0)
+               err(1, "hammer ioctl");
        overs = version.cur_version;
 
        version.cur_version = strtol(av[1], NULL, 0);
        nvers = version.cur_version;
 
-       if (ioctl(fd, HAMMERIOC_GET_VERSION, &version) < 0) {
-               fprintf(stderr, "hammer ioctl: %s\n", strerror(errno));
-               exit(1);
-       }
-       if (version.cur_version >= version.wip_version && ac != 3) {
-               fprintf(stderr,
-                       "The requested version is a work-in-progress"
-                       " and requires the 'force' directive\n");
-               exit(1);
-       }
-       if (ioctl(fd, HAMMERIOC_SET_VERSION, &version) < 0) {
-               fprintf(stderr, "hammer version-upgrade ioctl: %s\n",
-                       strerror(errno));
-               exit(1);
-       }
-       if (version.head.error) {
-               fprintf(stderr, "hammer version-upgrade ioctl: %s\n",
-                       strerror(version.head.error));
-               exit(1);
-       }
+       if (ioctl(fd, HAMMERIOC_GET_VERSION, &version) < 0)
+               err(1, "hammer ioctl");
+       if (version.cur_version >= version.wip_version && ac != 3)
+               errx(1, "The requested version is a work-in-progress"
+                       " and requires the 'force' directive");
+
+       if (ioctl(fd, HAMMERIOC_SET_VERSION, &version) < 0)
+               err(1, "hammer version-upgrade ioctl");
+       if (version.head.error)
+               errx(1, "hammer version-upgrade ioctl");
+
        printf("hammer version-upgrade: succeeded\n");
        if (overs < 3 && nvers >= 3) {
                printf("NOTE!  Please run 'hammer cleanup' to convert the\n"
index 858288f..e1feaff 100644 (file)
@@ -56,30 +56,23 @@ hammer_cmd_volume_add(char **av, int ac)
        int fd;
        const char *device, *filesystem;
 
-       if (ac != 2) {
-               fprintf(stderr, "hammer volume-add <device> <filesystem>\n");
-               exit(1);
-       }
+       if (ac != 2)
+               errx(1, "hammer volume-add <device> <filesystem>");
 
        device = av[0];
        filesystem = av[1];
 
         fd = open(filesystem, O_RDONLY);
-       if (fd < 0) {
-               fprintf(stderr, "hammer volume-add: unable to access %s: %s\n",
-                       filesystem, strerror(errno));
-               exit(1);
-       }
+       if (fd < 0)
+               err(1, "hammer volume-add: unable to access %s", filesystem);
 
        /*
         * Initialize and check the device
         */
        vol = init_volume(device, O_RDONLY, -1);
        assert(vol->vol_no == -1);
-       if (strcmp(vol->type, "DEVICE")) {
-               fprintf(stderr, "Not a block device: %s\n", device);
-               exit(1);
-       }
+       if (strcmp(vol->type, "DEVICE"))
+               errx(1, "Not a block device: %s", device);
        close(vol->fd);
 
        /*
@@ -91,11 +84,8 @@ hammer_cmd_volume_add(char **av, int ac)
        ioc.boot_area_size = init_boot_area_size(0, ioc.vol_size);
        ioc.memory_log_size = init_memory_log_size(0, ioc.vol_size);
 
-       if (ioctl(fd, HAMMERIOC_ADD_VOLUME, &ioc) < 0) {
-               fprintf(stderr, "hammer volume-add ioctl: %s\n",
-                       strerror(errno));
-               exit(1);
-       }
+       if (ioctl(fd, HAMMERIOC_ADD_VOLUME, &ioc) < 0)
+               err(1, "hammer volume-add ioctl");
 
        close(fd);
        hammer_cmd_volume_list(av + 1, ac - 1);
@@ -108,23 +98,18 @@ void
 hammer_cmd_volume_del(char **av, int ac)
 {
        struct hammer_ioc_volume ioc;
-       int fd, error, retried = 0;
+       int fd, retried = 0;
        const char *device, *filesystem;
 
-       if (ac != 2) {
-               fprintf(stderr, "hammer volume-del <device> <filesystem>\n");
-               exit(1);
-       }
+       if (ac != 2)
+               errx(1, "hammer volume-del <device> <filesystem>");
 
        device = av[0];
        filesystem = av[1];
 
         fd = open(filesystem, O_RDONLY);
-       if (fd < 0) {
-               fprintf(stderr, "hammer volume-del: unable to access %s: %s\n",
-                       filesystem, strerror(errno));
-               exit(1);
-       }
+       if (fd < 0)
+               err(1, "hammer volume-del: unable to access %s", filesystem);
 
        /*
         * volume-del ioctl
@@ -135,8 +120,7 @@ hammer_cmd_volume_del(char **av, int ac)
                ioc.flag |= HAMMER_IOC_VOLUME_REBLOCK;
 retry:
        if (ioctl(fd, HAMMERIOC_DEL_VOLUME, &ioc) < 0) {
-               error = errno;
-               if ((error == ENOTEMPTY) && (retried++ == 0)) {
+               if ((errno == ENOTEMPTY) && (retried++ == 0)) {
                        printf("%s is not empty, ", device);
                        printf("do you want to reblock %s? [y/n] ", device);
                        fflush(stdout);
@@ -145,9 +129,7 @@ retry:
                                goto retry;
                        }
                }
-               fprintf(stderr, "hammer volume-del ioctl: %s\n",
-                       strerror(error));
-               exit(1);
+               err(1, "hammer volume-del ioctl");
        }
 
        close(fd);
@@ -164,15 +146,11 @@ hammer_cmd_volume_list(char **av, int ac)
        char *device_name;
        int vol_no, i;
 
-       if (ac < 1) {
-               fprintf(stderr, "hammer volume-list <filesystem>\n");
-               exit(1);
-       }
+       if (ac < 1)
+               errx(1, "hammer volume-list <filesystem>");
 
-       if (hammer_fs_to_vol(av[0], &ioc) == -1) {
-               fprintf(stderr, "hammer volume-list: failed\n");
-               exit(1);
-       }
+       if (hammer_fs_to_vol(av[0], &ioc) == -1)
+               errx(1, "hammer volume-list: failed");
 
        for (i = 0; i < ioc.nvols; i++) {
                device_name = ioc.vols[i].device_name;
@@ -198,15 +176,11 @@ hammer_cmd_volume_blkdevs(char **av, int ac)
        struct hammer_ioc_volume_list ioc;
        int i;
 
-       if (ac < 1) {
-               fprintf(stderr, "hammer volume-blkdevs <filesystem>\n");
-               exit(1);
-       }
+       if (ac < 1)
+               errx(1, "hammer volume-blkdevs <filesystem>");
 
-       if (hammer_fs_to_vol(av[0], &ioc) == -1) {
-               fprintf(stderr, "hammer volume-list: failed\n");
-               exit(1);
-       }
+       if (hammer_fs_to_vol(av[0], &ioc) == -1)
+               errx(1, "hammer volume-list: failed");
 
        for (i = 0; i < ioc.nvols; i++) {
                printf("%s", ioc.vols[i].device_name);
index 0a4547d..582c5d2 100644 (file)
@@ -241,11 +241,9 @@ main(int ac, char **av)
                        if (strcmp(av[0], elm) == 0)
                                break;
                }
-               if (elm == NULL) {
-                       fprintf(stderr, "hammer-remote: request does not match "
-                                       "restricted command\n");
-                       exit(1);
-               }
+               if (elm == NULL)
+                       errx(1, "hammer-remote: request does not match "
+                               "restricted command");
                free(dup);
        }
 
index b8c4e57..ccc16d9 100644 (file)
@@ -168,19 +168,11 @@ main(int ac, char **av)
                }
        }
 
-       if (nvols == 0) {
-               fprintf(stderr,
-                       "newfs_hammer: You must specify at least one "
-                       "special file (volume)\n");
-               exit(1);
-       }
-
-       if (nvols > HAMMER_MAX_VOLUMES) {
-               fprintf(stderr,
-                       "newfs_hammer: The maximum number of volumes is %d\n",
+       if (nvols == 0)
+               errx(1, "You must specify at least one special file (volume)");
+       if (nvols > HAMMER_MAX_VOLUMES)
+               errx(1, "The maximum number of volumes is %d",
                        HAMMER_MAX_VOLUMES);
-               exit(1);
-       }
 
        /*
         * Generate a filesystem id and lookup the filesystem type
index 246f2d7..4436eff 100644 (file)
@@ -48,6 +48,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <err.h>
 #include <vfs/hammer/hammer_disk.h>
 #include <vfs/hammer/hammer_ioctl.h>
 
@@ -495,10 +496,8 @@ dogenerate(const char *filename, int flags,
        switch(type) {
        case TYPE_FILE:
                buf = malloc(8192);
-               if (buf == NULL) {
-                       perror("malloc");
-                       exit(1);
-               }
+               if (buf == NULL)
+                       err(1, "malloc");
                if ((fi = fopen(ipath1, "r")) != NULL) {
                        while ((n = fread(buf, 1, 8192, fi)) > 0)
                                fwrite(buf, 1, n, fp);
@@ -661,10 +660,8 @@ _fopen(const char *filename, const char *mode)
        FILE *fp;
 
        fp = fopen(filename, mode);
-       if (fp == NULL) {
-               perror(filename);
-               exit(1);
-       }
+       if (fp == NULL)
+               err(1, "%s", filename);
        return(fp);
 }
 
@@ -690,8 +687,7 @@ runcmd(int fd, const char *cmd, ...)
        av[i] = NULL;
 
        if ((pid = fork()) < 0) {
-               perror("fork");
-               exit(1);
+               err(1, "fork");
        } else if (pid == 0) {
                if (fd != 1) {
                        dup2(fd, 1);