use warn/err appropriately.

This commit is contained in:
christos 2010-01-27 18:34:02 +00:00
parent 03fdf6b025
commit 13a5940614
2 changed files with 29 additions and 55 deletions

View File

@ -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 @@ main(int argc,char *argv[])
#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 @@ main(int argc,char *argv[])
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 @@ rf_configure(int fd, char *config_file, int force)
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 @@ rf_configure(int fd, char *config_file, int force)
* the configuration structure.
*/
generic = (void *) &cfg;
generic = &cfg;
do_ioctl(fd, RAIDFRAME_CONFIGURE, &generic, "RAIDFRAME_CONFIGURE");
}
@ -579,11 +565,8 @@ rf_pm_configure(int fd, int raidID, char *parityconf, int parityparams[])
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 @@ get_component_number(int fd, char *component_name, int *component_number,
}
}
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 @@ do_meter(int fd, u_long option)
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 @@ do_meter(int fd, u_long option)
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, "");

View File

@ -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 @@ __RCSID("$NetBSD: rf_configure.c,v 1.24 2009/04/06 12:47:20 lukem Exp $");
#include <stdlib.h>
#include <errno.h>
#include <strings.h>
#include <err.h>
#include <sys/types.h>
#include <sys/stat.h>
@ -500,16 +501,14 @@ rf_ReadSpareTable(RF_SparetWait_t *req, char *fname)
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 @@ rf_ReadSpareTable(RF_SparetWait_t *req, char *fname)
/* 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 @@ rf_ReadSpareTable(RF_SparetWait_t *req, char *fname)
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);
}