From: Keith Bostic Date: Fri, 31 Jul 1992 07:30:31 +0000 (-0800) Subject: cleanups from Criag Leres, and minor upgrades for cleanliness X-Git-Tag: BSD-4_4-Snapshot-Development~5207 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/b64ddac9aaa4f561cd08661faa0577ed17660199 cleanups from Criag Leres, and minor upgrades for cleanliness SCCS-vsn: usr.sbin/dev_mkdb/dev_mkdb.c 5.11 --- diff --git a/usr/src/usr.sbin/dev_mkdb/dev_mkdb.c b/usr/src/usr.sbin/dev_mkdb/dev_mkdb.c index 250797b6ef..76171554e4 100644 --- a/usr/src/usr.sbin/dev_mkdb/dev_mkdb.c +++ b/usr/src/usr.sbin/dev_mkdb/dev_mkdb.c @@ -12,11 +12,12 @@ char copyright[] = #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)dev_mkdb.c 5.10 (Berkeley) %G%"; +static char sccsid[] = "@(#)dev_mkdb.c 5.11 (Berkeley) %G%"; #endif /* not lint */ #include #include + #include #undef DIRBLKSIZ #include @@ -30,13 +31,14 @@ static char sccsid[] = "@(#)dev_mkdb.c 5.10 (Berkeley) %G%"; #include #include -void error(), usage(); +void err __P((const char *, ...)); +void usage __P((void)); +int main(argc, argv) int argc; - char **argv; + char *argv[]; { - extern int optind; register DIR *dirp; register struct dirent *dp; struct stat sb; @@ -59,16 +61,20 @@ main(argc, argv) argc -= optind; argv += optind; + if (argc > 0) + usage(); + if (chdir(_PATH_DEV)) - error(_PATH_DEV); + err("%s: %s", _PATH_DEV, strerror(errno)); dirp = opendir("."); - (void)snprintf(dbtmp, sizeof(dbtmp), "%s/dev.tmp", _PATH_VARRUN); - (void)snprintf(dbname, sizeof(dbtmp), "%s/dev.db", _PATH_VARRUN); - db = dbopen(dbtmp, O_CREAT|O_WRONLY|O_EXCL, DEFFILEMODE, DB_HASH, NULL); - if (!db) - error(dbtmp); + (void)snprintf(dbtmp, sizeof(dbtmp), "%sdev.tmp", _PATH_VARRUN); + (void)snprintf(dbname, sizeof(dbtmp), "%sdev.db", _PATH_VARRUN); + db = dbopen(dbtmp, O_CREAT|O_EXLOCK|O_TRUNC|O_WRONLY, + S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, DB_HASH, NULL); + if (db == NULL) + err("%s: %s", dbtmp, strerror(errno)); /* * Keys are a mode_t followed by a dev_t. The former is the type of @@ -79,8 +85,8 @@ main(argc, argv) data.data = buf; while (dp = readdir(dirp)) { if (stat(dp->d_name, &sb)) { - (void)fprintf(stderr, "dev_mkdb: can't stat %s\n", - dp->d_name); + (void)fprintf(stderr, + "dev_mkdb: %s: %s\n", dp->d_name, strerror(errno)); continue; } @@ -101,28 +107,46 @@ main(argc, argv) buf[dp->d_namlen] = '\0'; data.size = dp->d_namlen + 1; if ((db->put)(db, &key, &data, 0)) - error(dbtmp); + err("dbput %s: %s\n", dbtmp, strerror(errno)); } (void)(db->close)(db); - if (rename(dbtmp, dbname)) { - (void)fprintf(stderr, "dev_mkdb: %s to %s: %s.\n", - dbtmp, dbname, strerror(errno)); - exit(1); - } + if (rename(dbtmp, dbname)) + err("rename %s to %s: %s", dbtmp, dbname, strerror(errno)); exit(0); } void -error(n) - char *n; +usage() { - (void)fprintf(stderr, "dev_mkdb: %s: %s\n", n, strerror(errno)); + (void)fprintf(stderr, "usage: dev_mkdb\n"); exit(1); } +#if __STDC__ +#include +#else +#include +#endif + void -usage() +#if __STDC__ +err(const char *fmt, ...) +#else +err(fmt, va_alist) + char *fmt; + va_dcl +#endif { - (void)fprintf(stderr, "usage: dev_mkdb\n"); + va_list ap; +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + (void)fprintf(stderr, "dev_mkdb: "); + (void)vfprintf(stderr, fmt, ap); + va_end(ap); + (void)fprintf(stderr, "\n"); exit(1); + /* NOTREACHED */ }