From 02aa0db84899fd91a6631852f9dbaea400933ff2 Mon Sep 17 00:00:00 2001 From: "Federico G. Schwindt" Date: Tue, 4 Sep 2007 01:05:21 +0000 Subject: Use err(3) functions. input and ok millert. --- usr.sbin/ypserv/mkalias/mkalias.c | 41 ++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'usr.sbin/ypserv') diff --git a/usr.sbin/ypserv/mkalias/mkalias.c b/usr.sbin/ypserv/mkalias/mkalias.c index 20bb9297f31..42374985af3 100644 --- a/usr.sbin/ypserv/mkalias/mkalias.c +++ b/usr.sbin/ypserv/mkalias/mkalias.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mkalias.c,v 1.19 2007/08/05 14:25:48 fgsch Exp $ */ +/* $OpenBSD: mkalias.c,v 1.20 2007/09/04 01:05:20 fgsch Exp $ */ /* * Copyright (c) 1997 Mats O Jansson @@ -27,7 +27,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: mkalias.c,v 1.19 2007/08/05 14:25:48 fgsch Exp $"; +static const char rcsid[] = "$OpenBSD: mkalias.c,v 1.20 2007/09/04 01:05:20 fgsch Exp $"; #endif #include @@ -42,6 +42,7 @@ static const char rcsid[] = "$OpenBSD: mkalias.c,v 1.19 2007/08/05 14:25:48 fgsc #include #include #include +#include #include "ypdb.h" #include "ypdef.h" @@ -206,17 +207,16 @@ main(int argc, char *argv[]) db = ypdb_open(input, O_RDONLY, 0444); if (db == NULL) { - fprintf(stderr, - "mkalias: Unable to open input database %s\n", - input); - exit(1); + err(1, "Unable to open input database %s", input); + /* NOTREACHED */ } if (output != NULL) { if (strlen(output) + strlen(YPDB_SUFFIX) > MAXPATHLEN) { - fprintf(stderr,"mkalias: %s: file name too long\n", - output); + errx(1, "%s: file name too long", output); + /* NOTREACHED */ } + snprintf(db_outfile, sizeof(db_outfile), "%s%s", output, YPDB_SUFFIX); @@ -230,9 +230,8 @@ main(int argc, char *argv[]) if (strlen(output) + strlen(mapname) + strlen(YPDB_SUFFIX) > MAXPATHLEN) { - fprintf(stderr,"mkalias: %s: directory name too long\n", - output); - exit(1); + errx(1, "%s: directory name too long", output); + /* NOTREACHED */ } snprintf(db_tempname, sizeof(db_tempname), "%s%s%s", output, @@ -250,10 +249,9 @@ main(int argc, char *argv[]) fail: if (fd != -1) unlink(db_tempname); - fprintf(stderr, - "mkalias: Unable to open output database %s\n", + err(1, "Unable to open output database %s", db_outfile); - exit(1); + /* NOTREACHED */ } } @@ -279,7 +277,7 @@ fail: split_address(val.dptr, val.dsize, user, host); if (eflag && check_host(val.dptr, val.dsize, host, dflag, uflag, Eflag)) { - printf("Invalid host %s in %*.*s:%*.*s\n", + warnx("Invalid host %s in %*.*s:%*.*s", host, key.dsize, key.dsize, key.dptr, val.dsize, val.dsize, val.dptr); continue; @@ -291,7 +289,7 @@ fail: if (new_db != NULL) { status = ypdb_store(new_db, val, key, YPDB_INSERT); if (status != 0) { - printf("mkalias: problem storing %*.*s %*.*s\n", + warnx("problem storing %*.*s %*.*s", val.dsize, val.dsize, val.dptr, key.dsize, key.dsize, key.dptr); } @@ -313,7 +311,7 @@ fail: val.dsize = strlen(datestr); status = ypdb_store(new_db, key, val, YPDB_INSERT); if (status != 0) { - printf("mkalias: problem storing %*.*s %*.*s\n", + warnx("problem storing %*.*s %*.*s", key.dsize, key.dsize, key.dptr, val.dsize, val.dsize, val.dptr); } @@ -327,7 +325,7 @@ fail: val.dsize = strlen(myname); status = ypdb_store(new_db, key, val, YPDB_INSERT); if (status != 0) { - printf("mkalias: problem storing %*.*s %*.*s\n", + warnx("problem storing %*.*s %*.*s", key.dsize, key.dsize, key.dptr, val.dsize, val.dsize, val.dptr); } @@ -338,10 +336,9 @@ fail: if (new_db != NULL) { ypdb_close(new_db); if (rename(db_tempname, db_outfile) < 0) { - perror("rename"); - fprintf(stderr,"rename %s -> %s failed!\n", - db_tempname, db_outfile); - exit(1); + err(1, "rename %s -> %s failed", db_tempname, + db_outfile); + /* NOTREACHED */ } } return(0); -- cgit v1.2.3