Source-Changes-HG archive

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

[src/trunk]: src/sbin/raidctl use warn/err appropriately.



details:   https://anonhg.NetBSD.org/src/rev/39cd4832a993
branches:  trunk
changeset: 751195:39cd4832a993
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Jan 27 18:34:02 2010 +0000

description:
use warn/err appropriately.

diffstat:

 sbin/raidctl/raidctl.c      |  67 ++++++++++++++------------------------------
 sbin/raidctl/rf_configure.c |  17 +++++------
 2 files changed, 29 insertions(+), 55 deletions(-)

diffs (202 lines):

diff -r 9f39b52203d2 -r 39cd4832a993 sbin/raidctl/raidctl.c
--- a/sbin/raidctl/raidctl.c    Wed Jan 27 17:02:06 2010 +0000
+++ b/sbin/raidctl/raidctl.c    Wed Jan 27 18:34:02 2010 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: raidctl.c,v 1.44 2010/01/27 17:02:06 pooka Exp $   */
+/*      $NetBSD: raidctl.c,v 1.45 2010/01/27 18:34:02 christos Exp $   */
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: raidctl.c,v 1.44 2010/01/27 17:02:06 pooka Exp $");
+__RCSID("$NetBSD: raidctl.c,v 1.45 2010/01/27 18:34:02 christos Exp $");
 #endif
 
 
@@ -270,21 +270,12 @@
 #else
        fd = opendisk(name, openmode, dev_name, sizeof(dev_name), 0);
 #endif
-       if (fd == -1) {
-               fprintf(stderr, "%s: unable to open device file: %s\n",
-                       getprogname(), name);
-               exit(1);
-       }
-       if (fstat(fd, &st) != 0) {
-               fprintf(stderr,"%s: stat failure on: %s\n",
-                       getprogname(), dev_name);
-               exit(1);
-       }
-       if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode)) {
-               fprintf(stderr,"%s: invalid device: %s\n",
-                       getprogname(), dev_name);
-               exit(1);
-       }
+       if (fd == -1)
+               err(1, "Unable to open device file: %s", name);
+       if (fstat(fd, &st) == -1)
+               err(1, "stat failure on: %s", dev_name);
+       if (!S_ISBLK(st.st_mode) && !S_ISCHR(st.st_mode))
+               err(1, "invalid device: %s", dev_name);
 
        raidID = DISKUNIT(st.st_rdev);
 
@@ -367,10 +358,8 @@
 void
 do_ioctl(int fd, unsigned long command, void *arg, const char *ioctl_name)
 {
-       if (ioctl(fd, command, arg) < 0) {
-               warn("ioctl (%s) failed", ioctl_name);
-               exit(1);
-       }
+       if (ioctl(fd, command, arg) == -1)
+               err(1, "ioctl (%s) failed", ioctl_name);
 }
 
 
@@ -380,11 +369,8 @@
        void *generic;
        RF_Config_t cfg;
 
-       if (rf_MakeConfig( config_file, &cfg ) != 0) {
-               fprintf(stderr,"%s: unable to create RAIDframe %s\n",
-                       getprogname(), "configuration structure");
-               exit(1);
-       }
+       if (rf_MakeConfig( config_file, &cfg ) != 0)
+               err(1, "Unable to create RAIDframe configuration structure");
        
        cfg.force = force;
 
@@ -394,7 +380,7 @@
         * the configuration structure. 
         */
 
-       generic = (void *) &cfg;
+       generic = &cfg;
        do_ioctl(fd, RAIDFRAME_CONFIGURE, &generic, "RAIDFRAME_CONFIGURE");
 }
 
@@ -579,11 +565,8 @@
 
                return;
                /* XXX the control flow here could be prettier. */
-       } else {
-               fprintf(stderr, "%s: \"%s\" is not a valid parity map command"
-                   "\n", getprogname(), parityconf);
-               exit(1);
-       }
+       } else
+               err(1, "`%s' is not a valid parity map command", parityconf);
 
        do_ioctl(fd, RAIDFRAME_PARITYMAP_SET_DISABLE, &dis,
            "RAIDFRAME_PARITYMAP_SET_DISABLE");
@@ -699,11 +682,8 @@
                }
        }
 
-       if (!found) {
-               fprintf(stderr,"%s: %s is not a component %s", getprogname(), 
-                       component_name, "of this device\n");
-               exit(1);
-       }
+       if (!found)
+               err(1,"%s is not a component of this device", component_name);
 }
 
 static void
@@ -1012,10 +992,8 @@
        char bar_buffer[1024];
        char eta_buffer[1024];
 
-       if (gettimeofday(&start_time,NULL)) {
-               fprintf(stderr,"%s: gettimeofday failed!?!?\n", getprogname());
-               exit(errno);
-       }
+       if (gettimeofday(&start_time,NULL) == -1)
+               err(1, "gettimeofday failed!?!?");
        memset(&progressInfo, 0, sizeof(RF_ProgressInfo_t));
        pInfoPtr=&progressInfo;
 
@@ -1082,11 +1060,8 @@
 
                sleep(2);
 
-               if (gettimeofday(&current_time,NULL)) {
-                       fprintf(stderr,"%s: gettimeofday failed!?!?\n",
-                               getprogname());
-                       exit(errno);
-               }
+               if (gettimeofday(&current_time,NULL) == -1)
+                       err(1, "gettimeofday failed!?!?");
 
                do_ioctl( fd, option, &pInfoPtr, "");
                
diff -r 9f39b52203d2 -r 39cd4832a993 sbin/raidctl/rf_configure.c
--- a/sbin/raidctl/rf_configure.c       Wed Jan 27 17:02:06 2010 +0000
+++ b/sbin/raidctl/rf_configure.c       Wed Jan 27 18:34:02 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_configure.c,v 1.24 2009/04/06 12:47:20 lukem Exp $  */
+/*     $NetBSD: rf_configure.c,v 1.25 2010/01/27 18:34:02 christos Exp $       */
 
 /*
  * Copyright (c) 1995 Carnegie-Mellon University.
@@ -49,7 +49,7 @@
 #include <sys/cdefs.h>
 
 #ifndef lint
-__RCSID("$NetBSD: rf_configure.c,v 1.24 2009/04/06 12:47:20 lukem Exp $");
+__RCSID("$NetBSD: rf_configure.c,v 1.25 2010/01/27 18:34:02 christos Exp $");
 #endif
 
 
@@ -57,6 +57,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <strings.h>
+#include <err.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -500,16 +501,14 @@
        table = malloc(req->TablesPerSpareRegion * 
                       sizeof(RF_SpareTableEntry_t *));
        if (table == NULL) {
-               fprintf(stderr,
-                       "rf_ReadSpareTable: Unable to allocate table\n");
+               warnx("rf_ReadSpareTable: Unable to allocate table");
                return (NULL);
        }
        for (i = 0; i < req->TablesPerSpareRegion; i++) {
                table[i] = malloc(req->BlocksPerTable * 
                                  sizeof(RF_SpareTableEntry_t));
                if (table[i] == NULL) {
-                       fprintf(stderr,
-                               "rf_ReadSpareTable: Unable to allocate table\n");
+                       warnx("rf_ReadSpareTable: Unable to allocate table");
                        return (NULL);  /* XXX should cleanup too! */
                }
                for (j = 0; j < req->BlocksPerTable; j++)
@@ -519,8 +518,7 @@
 
        /* 2.  open sparemap file, sanity check */
        if ((fp = fopen(fname, "r")) == NULL) {
-               fprintf(stderr,
-                   "rf_ReadSpareTable:  Can't open sparemap file %s\n", fname);
+               warn("rf_ReadSpareTable: Can't open sparemap file %s", fname);
                return (NULL);
        }
        if (rf_get_next_nonblank_line(buf, 1024, fp,
@@ -547,7 +545,8 @@
                numFound = fscanf(fp, " %d %d %d %d", &tableNum, &tupleNum,
                    &spareDisk, &spareBlkOffset);
                if (numFound != 4) {
-                       fprintf(stderr, "Sparemap file prematurely exhausted after %d of %d lines\n", i, linecount);
+                       warnx("Sparemap file prematurely exhausted after %d "
+                           "of %d lines", i, linecount);
                        fclose(fp);
                        return (NULL);
                }



Home | Main Index | Thread Index | Old Index