summaryrefslogtreecommitdiff
path: root/usr.sbin/config
diff options
context:
space:
mode:
authorTheo Buehler <tb@cvs.openbsd.org>2016-10-16 17:50:01 +0000
committerTheo Buehler <tb@cvs.openbsd.org>2016-10-16 17:50:01 +0000
commit31dcef6aecdf49dc9f5f9931fecbcb6a386f26e0 (patch)
tree0fd9f206a2e47d00adcdf9622b8a73351f5af3ff /usr.sbin/config
parentf8ceee3cee6452bc381d693c209e8f360047f225 (diff)
Use the err(3) family of functions more consistently.
ok jca, improvements and ok millert, natano
Diffstat (limited to 'usr.sbin/config')
-rw-r--r--usr.sbin/config/main.c67
-rw-r--r--usr.sbin/config/mkheaders.c38
-rw-r--r--usr.sbin/config/mkioconf.c17
-rw-r--r--usr.sbin/config/mkmakefile.c15
-rw-r--r--usr.sbin/config/mkswap.c9
-rw-r--r--usr.sbin/config/ukc.c9
6 files changed, 57 insertions, 98 deletions
diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c
index 0de25dd8083..ad3da1a6785 100644
--- a/usr.sbin/config/main.c
+++ b/usr.sbin/config/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.55 2016/10/16 09:36:46 natano Exp $ */
+/* $OpenBSD: main.c,v 1.56 2016/10/16 17:50:00 tb Exp $ */
/* $NetBSD: main.c,v 1.22 1997/02/02 21:12:33 thorpej Exp $ */
/*
@@ -75,7 +75,7 @@ static void optiondelta(void);
int verbose;
-void
+__dead void
usage(void)
{
extern char *__progname;
@@ -169,19 +169,15 @@ main(int argc, char *argv[])
if (eflag) {
#ifdef MAKE_BOOTSTRAP
- fprintf(stderr, "config: UKC not available in this binary\n");
- exit(1);
+ errx(1, "UKC not available in this binary");
#else
return (ukc(argv[0], outfile, uflag, fflag));
#endif
}
conffile = (argc == 1) ? argv[0] : "CONFIG";
- if (firstfile(conffile)) {
- (void)fprintf(stderr, "config: cannot read %s: %s\n",
- conffile, strerror(errno));
- exit(2);
- }
+ if (firstfile(conffile))
+ err(2, "cannot read %s", conffile);
/*
* Init variables.
@@ -246,8 +242,7 @@ main(int argc, char *argv[])
defmaxusers);
maxusers = defmaxusers;
} else {
- (void)fprintf(stderr,
- "config: need \"maxusers\" line\n");
+ warnx("need \"maxusers\" line");
errors++;
}
}
@@ -269,7 +264,7 @@ main(int argc, char *argv[])
mkioconf())
stop();
optiondelta();
- exit(0);
+ return (0);
}
static int
@@ -278,11 +273,11 @@ mksymlink(const char *value, const char *path)
int ret = 0;
if (remove(path) && errno != ENOENT) {
- warn("config: remove(%s)", path);
+ warn("remove(%s)", path);
ret = 1;
}
if (symlink(value, path)) {
- warn("config: symlink(%s -> %s)", path, value);
+ warn("symlink(%s -> %s)", path, value);
ret = 1;
}
return (ret);
@@ -624,8 +619,7 @@ badstar(void)
continue;
foundstar:
if (ht_lookup(needcnttab, d->d_name)) {
- (void)fprintf(stderr,
- "config: %s's cannot be *'d until its driver is fixed\n",
+ warnx("%s's cannot be *'d until its driver is fixed",
d->d_name);
errs++;
continue;
@@ -662,26 +656,14 @@ setupdirs(void)
builddir = defbuilddir;
if (stat(builddir, &st) != 0) {
- if (mkdir(builddir, 0777)) {
- (void)fprintf(stderr, "config: cannot create %s: %s\n",
- builddir, strerror(errno));
- exit(2);
- }
- } else if (!S_ISDIR(st.st_mode)) {
- (void)fprintf(stderr, "config: %s is not a directory\n",
- builddir);
- exit(2);
- }
- if (chdir(builddir) != 0) {
- (void)fprintf(stderr, "config: cannot change to %s\n",
- builddir);
- exit(2);
- }
- if (stat(srcdir, &st) != 0 || !S_ISDIR(st.st_mode)) {
- (void)fprintf(stderr, "config: %s is not a directory\n",
- srcdir);
- exit(2);
- }
+ if (mkdir(builddir, 0777))
+ err(2, "cannot create %s", builddir);
+ } else if (!S_ISDIR(st.st_mode))
+ errc(2, ENOTDIR, "%s", builddir);
+ if (chdir(builddir) != 0)
+ errx(2, "cannot change to %s", builddir);
+ if (stat(srcdir, &st) != 0 || !S_ISDIR(st.st_mode))
+ errc(2, ENOTDIR, "%s", srcdir);
if (bflag) {
if (pledge("stdio rpath wpath cpath flock", NULL) == -1)
@@ -693,15 +675,10 @@ setupdirs(void)
goto reconfig;
fp = fopen("Makefile", "w");
- if (!fp) {
- (void)fprintf(stderr, "config: cannot create Makefile\n");
- exit(2);
- }
- if (fprintf(fp, ".include \"../Makefile.inc\"\n") < 0) {
- (void)fprintf(stderr, "config: cannot create Makefile\n");
- exit(2);
- }
- fclose(fp);
+ if (!fp)
+ errx(2, "cannot create Makefile");
+ if (fprintf(fp, ".include \"../Makefile.inc\"\n") < 0 || fclose(fp))
+ errx(2, "cannot write Makefile");
reconfig:
if (system("make obj") != 0)
diff --git a/usr.sbin/config/mkheaders.c b/usr.sbin/config/mkheaders.c
index 497dcc8e3d8..66a1b8dcbe6 100644
--- a/usr.sbin/config/mkheaders.c
+++ b/usr.sbin/config/mkheaders.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mkheaders.c,v 1.21 2015/01/16 06:40:16 deraadt Exp $ */
+/* $OpenBSD: mkheaders.c,v 1.22 2016/10/16 17:50:00 tb Exp $ */
/* $NetBSD: mkheaders.c,v 1.12 1997/02/02 21:12:34 thorpej Exp $ */
/*
@@ -42,6 +42,7 @@
*/
#include <ctype.h>
+#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -51,7 +52,7 @@
static int emitcnt(struct nvlist *);
static int emitopt(struct nvlist *);
-static int err(const char *, char *, FILE *);
+static int emitwarn(const char *, char *, FILE *);
static char *cntname(const char *);
/*
@@ -102,22 +103,19 @@ emitcnt(struct nvlist *head)
nv = nv->nv_next;
}
if (ferror(fp))
- return (err("read", fname, fp));
+ return (emitwarn("read", fname, fp));
(void)fclose(fp);
if (nv == NULL)
return (0);
writeit:
- if ((fp = fopen(fname, "w")) == NULL) {
- (void)fprintf(stderr, "config: cannot write %s: %s\n",
- fname, strerror(errno));
- return (1);
- }
+ if ((fp = fopen(fname, "w")) == NULL)
+ return (emitwarn("writ", fname, NULL));
for (nv = head; nv != NULL; nv = nv->nv_next)
if (fprintf(fp, "#define\t%s\t%d\n",
cntname(nv->nv_name), nv->nv_int) < 0)
- return (err("writ", fname, fp));
+ return (emitwarn("writ", fname, fp));
if (fclose(fp))
- return (err("writ", fname, NULL));
+ return (emitwarn("writ", fname, NULL));
return (0);
}
@@ -149,7 +147,7 @@ emitopt(struct nvlist *nv)
}
if (totlen < 0 || totlen >= sizeof new_contents) {
- fprintf(stderr, "config: string too long\n");
+ warnx("string too long");
return (1);
}
@@ -166,7 +164,7 @@ emitopt(struct nvlist *nv)
goto writeit;
}
if (ferror(fp))
- return (err("read", fname, fp));
+ return (emitwarn("read", fname, fp));
(void)fclose(fp);
if (nlines == 1)
return (0);
@@ -174,24 +172,20 @@ writeit:
/*
* They're different, or the file doesn't exist.
*/
- if ((fp = fopen(fname, "w")) == NULL) {
- (void)fprintf(stderr, "config: cannot write %s: %s\n",
- fname, strerror(errno));
- return (1);
- }
+ if ((fp = fopen(fname, "w")) == NULL)
+ return (emitwarn("writ", fname, NULL));
if (fprintf(fp, "%s", new_contents) < 0)
- return (err("writ", fname, fp));
+ return (emitwarn("writ", fname, fp));
if (fclose(fp))
- return (err("writ", fname, fp));
+ return (emitwarn("writ", fname, fp));
return (0);
}
static int
-err(const char *what, char *fname, FILE *fp)
+emitwarn(const char *what, char *fname, FILE *fp)
{
- (void)fprintf(stderr, "config: error %sing %s: %s\n",
- what, fname, strerror(errno));
+ warn("error %sing %s", what, fname);
if (fp)
(void)fclose(fp);
return (1);
diff --git a/usr.sbin/config/mkioconf.c b/usr.sbin/config/mkioconf.c
index bebb335612b..0abb3a94342 100644
--- a/usr.sbin/config/mkioconf.c
+++ b/usr.sbin/config/mkioconf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mkioconf.c,v 1.34 2015/09/11 07:13:58 miod Exp $ */
+/* $OpenBSD: mkioconf.c,v 1.35 2016/10/16 17:50:00 tb Exp $ */
/* $NetBSD: mkioconf.c,v 1.41 1996/11/11 14:18:49 mycroft Exp $ */
/*
@@ -41,6 +41,7 @@
* from: @(#)mkioconf.c 8.1 (Berkeley) 6/6/93
*/
+#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -77,8 +78,7 @@ mkioconf(void)
qsort(packed, npacked, sizeof *packed, cforder);
if ((fp = fopen("ioconf.c", "w")) == NULL) {
- (void)fprintf(stderr, "config: cannot write ioconf.c: %s\n",
- strerror(errno));
+ warn("cannot write ioconf.c");
return (1);
}
v = emithdr(fp);
@@ -86,9 +86,7 @@ mkioconf(void)
emitlocnames(fp) || emitpv(fp) || emitcfdata(fp) ||
emitroots(fp) || emitpseudo(fp)) {
if (v >= 0)
- (void)fprintf(stderr,
- "config: error writing ioconf.c: %s\n",
- strerror(errno));
+ warn("error writing ioconf.c");
(void)fclose(fp);
/* (void)unlink("ioconf.c"); */
return (1);
@@ -127,8 +125,7 @@ emithdr(FILE *ofp)
if (fwrite(buf, 1, n, ofp) != n)
return (1);
if (ferror(ifp)) {
- (void)fprintf(stderr, "config: error reading %s: %s\n",
- ifn, strerror(errno));
+ warn("error reading %s", ifn);
(void)fclose(ifp);
return (-1);
}
@@ -425,9 +422,7 @@ emitroots(FILE *fp)
continue;
if (i->i_unit != 0 &&
(i->i_unit != STAR || i->i_base->d_umax != 0))
- (void)fprintf(stderr,
- "config: warning: `%s at root' is not unit 0\n",
- i->i_name);
+ warnx("warning: `%s at root' is not unit 0", i->i_name);
if (fprintf(fp, "\t%2d /* %s */,\n",
i->i_cfindex, i->i_name) < 0)
return (1);
diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c
index 7d260aedb58..816bb19887e 100644
--- a/usr.sbin/config/mkmakefile.c
+++ b/usr.sbin/config/mkmakefile.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mkmakefile.c,v 1.41 2015/01/16 06:40:16 deraadt Exp $ */
+/* $OpenBSD: mkmakefile.c,v 1.42 2016/10/16 17:50:00 tb Exp $ */
/* $NetBSD: mkmakefile.c,v 1.34 1997/02/02 21:12:36 thorpej Exp $ */
/*
@@ -80,14 +80,12 @@ mkmakefile(void)
machine, machine);
ifname = sourcepath(buf);
if ((ifp = fopen(ifname, "r")) == NULL) {
- (void)fprintf(stderr, "config: cannot read %s: %s\n",
- ifname, strerror(errno));
+ warn("cannot read %s", ifname);
free(ifname);
return (1);
}
if ((ofp = fopen("Makefile", "w")) == NULL) {
- (void)fprintf(stderr, "config: cannot write Makefile: %s\n",
- strerror(errno));
+ warn("cannot write Makefile");
free(ifname);
(void)fclose(ifp);
return (1);
@@ -125,9 +123,7 @@ mkmakefile(void)
goto wrerror;
}
if (ferror(ifp)) {
- (void)fprintf(stderr,
- "config: error reading %s (at line %d): %s\n",
- ifname, lineno, strerror(errno));
+ warn("error reading %s (at line %d)", ifname, lineno);
goto bad;
}
if (fclose(ofp)) {
@@ -138,8 +134,7 @@ mkmakefile(void)
free(ifname);
return (0);
wrerror:
- (void)fprintf(stderr, "config: error writing Makefile: %s\n",
- strerror(errno));
+ warn("error writing Makefile");
bad:
if (ofp != NULL)
(void)fclose(ofp);
diff --git a/usr.sbin/config/mkswap.c b/usr.sbin/config/mkswap.c
index 9926034092b..ddd94d31ba3 100644
--- a/usr.sbin/config/mkswap.c
+++ b/usr.sbin/config/mkswap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mkswap.c,v 1.15 2015/01/16 06:40:16 deraadt Exp $ */
+/* $OpenBSD: mkswap.c,v 1.16 2016/10/16 17:50:00 tb Exp $ */
/* $NetBSD: mkswap.c,v 1.5 1996/08/31 20:58:27 mycroft Exp $ */
/*
@@ -43,6 +43,7 @@
#include <sys/param.h> /* NODEV */
+#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -89,8 +90,7 @@ mkoneswap(struct config *cf)
(void)snprintf(fname, sizeof fname, "swap%s.c", cf->cf_name);
if ((fp = fopen(fname, "w")) == NULL) {
- (void)fprintf(stderr, "config: cannot write %s: %s\n",
- fname, strerror(errno));
+ warn("cannot write %s", fname);
return (1);
}
if (fputs("\
@@ -125,8 +125,7 @@ mkoneswap(struct config *cf)
}
return (0);
wrerror:
- (void)fprintf(stderr, "config: error writing %s: %s\n",
- fname, strerror(errno));
+ warn("error writing %s", fname);
if (fp != NULL)
(void)fclose(fp);
/* (void)unlink(fname); */
diff --git a/usr.sbin/config/ukc.c b/usr.sbin/config/ukc.c
index 72e2f4b9751..adfe620d396 100644
--- a/usr.sbin/config/ukc.c
+++ b/usr.sbin/config/ukc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ukc.c,v 1.20 2015/10/12 04:43:30 deraadt Exp $ */
+/* $OpenBSD: ukc.c,v 1.21 2016/10/16 17:50:00 tb Exp $ */
/*
* Copyright (c) 1999-2001 Mats O Jansson. All rights reserved.
@@ -41,8 +41,8 @@
#include "ukc.h"
#include "exec.h"
-void init(void);
-void usage(void);
+void init(void);
+__dead void usage(void);
int ukc_mod_kernel = 0;
@@ -57,7 +57,6 @@ check_int(int idx, const char *name)
int
ukc(char *file, char *outfile, int uflag, int force)
{
- extern char *__progname;
int i;
kvm_t *kd;
char errbuf[_POSIX2_LINE_MAX];
@@ -65,7 +64,7 @@ ukc(char *file, char *outfile, int uflag, int force)
char history[1024], kversion[1024];
if (file == NULL) {
- fprintf(stderr, "%s: no file specified\n", __progname);
+ warnx("no file specified");
usage();
}