diff options
| author | mycroft <mycroft@NetBSD.org> | 1995-01-30 21:12:41 +0000 |
|---|---|---|
| committer | mycroft <mycroft@NetBSD.org> | 1995-01-30 21:12:41 +0000 |
| commit | bbfccb8f005ddc2a4b85ee9430d72afb06b2f356 (patch) | |
| tree | 6a11027fd071858d5d6ff1a39dae82b610283d68 /usr.sbin/dev_mkdb | |
| parent | 0c1f0c97eb2bbd90a7aca2a5f84334e3e714d7c4 (diff) | |
Merge with 4.4-Lite, and use libc err(3) and warn(3).
Diffstat (limited to 'usr.sbin/dev_mkdb')
| -rw-r--r-- | usr.sbin/dev_mkdb/Makefile | 4 | ||||
| -rw-r--r-- | usr.sbin/dev_mkdb/dev_mkdb.8 | 32 | ||||
| -rw-r--r-- | usr.sbin/dev_mkdb/dev_mkdb.c | 78 |
3 files changed, 59 insertions, 55 deletions
diff --git a/usr.sbin/dev_mkdb/Makefile b/usr.sbin/dev_mkdb/Makefile index 6820e68f837..c37786e5ee4 100644 --- a/usr.sbin/dev_mkdb/Makefile +++ b/usr.sbin/dev_mkdb/Makefile @@ -1,5 +1,5 @@ -# from: @(#)Makefile 5.1 (Berkeley) 2/12/91 -# $Id: Makefile,v 1.3 1994/12/22 11:34:08 cgd Exp $ +# from: @(#)Makefile 8.1 (Berkeley) 6/6/93 +# $Id: Makefile,v 1.4 1995/01/30 21:12:41 mycroft Exp $ PROG= dev_mkdb MAN= dev_mkdb.8 diff --git a/usr.sbin/dev_mkdb/dev_mkdb.8 b/usr.sbin/dev_mkdb/dev_mkdb.8 index c2899097227..36617aae728 100644 --- a/usr.sbin/dev_mkdb/dev_mkdb.8 +++ b/usr.sbin/dev_mkdb/dev_mkdb.8 @@ -1,5 +1,5 @@ -.\" Copyright (c) 1990 The Regents of the University of California. -.\" All rights reserved. +.\" Copyright (c) 1990, 1993 +.\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -29,10 +29,10 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" from: @(#)dev_mkdb.8 5.4 (Berkeley) 8/5/91 -.\" $Id: dev_mkdb.8,v 1.2 1993/08/01 07:25:17 mycroft Exp $ +.\" from: @(#)dev_mkdb.8 8.1 (Berkeley) 6/6/93 +.\" $Id: dev_mkdb.8,v 1.3 1995/01/30 21:12:43 mycroft Exp $ .\" -.Dd August 5, 1991 +.Dd June 6, 1993 .Os .Dt DEV_MKDB 8 .Sh NAME @@ -47,13 +47,19 @@ The .Nm dev_mkdb command creates a .Xr db 3 -database in +hash access method database in .Dq Pa /var/run/dev.db -which lists the name and -.Fa st_rdev -field of all of the character and block special files in the +which contains the names of all of the character and block special +files in the .Dq Pa /dev -directory. +directory, using the file type and the +.Fa st_rdev +field as the key. +.Pp +Keys are a structure containing a mode_t followed by a dev_t, +with any padding zero'd out. +The former is the type of the file (st_mode & S_IFMT), +the latter is the st_rdev field. .Sh FILES .Bl -tag -width /var/run/dev.db -compact .It Pa /dev @@ -63,12 +69,14 @@ Database file. .El .Sh SEE ALSO .Xr ps 1 , +.Xr stat 2 , .Xr db 3 , +.Xr devname 3 , .Xr kvm_nlist 3 , .Xr ttyname 3 , .Xr kvm_mkdb 8 .Sh HISTORY The .Nm dev_mkdb -command is -.Ud . +command appeared in +.Bx 4.4 . diff --git a/usr.sbin/dev_mkdb/dev_mkdb.c b/usr.sbin/dev_mkdb/dev_mkdb.c index b5bcbdbab44..3c01fa79b50 100644 --- a/usr.sbin/dev_mkdb/dev_mkdb.c +++ b/usr.sbin/dev_mkdb/dev_mkdb.c @@ -1,6 +1,6 @@ /*- - * Copyright (c) 1990 The Regents of the University of California. - * All rights reserved. + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -32,38 +32,39 @@ */ #ifndef lint -char copyright[] = -"@(#) Copyright (c) 1990 The Regents of the University of California.\n\ - All rights reserved.\n"; +static char copyright[] = +"@(#) Copyright (c) 1990, 1993\n\ + The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint -/*static char sccsid[] = "from: @(#)dev_mkdb.c 5.9 (Berkeley) 5/17/91";*/ -static char rcsid[] = "$Id: dev_mkdb.c,v 1.4 1993/10/22 10:38:33 mycroft Exp $"; +/*static char sccsid[] = "from: @(#)dev_mkdb.c 8.1 (Berkeley) 6/6/93";*/ +static char rcsid[] = "$Id: dev_mkdb.c,v 1.5 1995/01/30 21:12:44 mycroft Exp $"; #endif /* not lint */ #include <sys/param.h> #include <sys/stat.h> -#include <fcntl.h> -#undef DIRBLKSIZ -#include <dirent.h> -#include <nlist.h> -#include <kvm.h> + #include <db.h> +#include <dirent.h> +#include <err.h> #include <errno.h> -#include <unistd.h> -#include <stdio.h> +#include <fcntl.h> +#include <kvm.h> +#include <nlist.h> #include <paths.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> -void error(), usage(); +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; @@ -86,29 +87,34 @@ main(argc, argv) argc -= optind; argv += optind; + if (argc > 0) + usage(); + if (chdir(_PATH_DEV)) - error(_PATH_DEV); + err(1, "%s", _PATH_DEV); 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_RDWR|O_EXCL, DEFFILEMODE, DB_HASH, - (HASHINFO *)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_RDWR|O_TRUNC, + S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, DB_HASH, NULL); + if (db == NULL) + err(1, "%s", dbtmp); /* * Keys are a mode_t followed by a dev_t. The former is the type of - * the file (mode & S_IFMT), the latter is the st_rdev field. + * the file (mode & S_IFMT), the latter is the st_rdev field. Note + * that the structure may contain padding, so we have to clear it + * out here. */ + bzero(&bkey, sizeof(bkey)); key.data = &bkey; key.size = sizeof(bkey); data.data = buf; while (dp = readdir(dirp)) { if (lstat(dp->d_name, &sb)) { - (void)fprintf(stderr, "dev_mkdb: can't stat %s\n", - dp->d_name); + warn("%s", dp->d_name); continue; } @@ -129,28 +135,18 @@ main(argc, argv) buf[dp->d_namlen] = '\0'; data.size = dp->d_namlen + 1; if ((db->put)(db, &key, &data, 0)) - error(dbtmp); + err(1, "dbput %s", dbtmp); } (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(1, "rename %s to %s", dbtmp, dbname); exit(0); } void -error(n) - char *n; -{ - (void)fprintf(stderr, "dev_mkdb: %s: %s\n", n, strerror(errno)); - exit(1); -} - -void usage() { + (void)fprintf(stderr, "usage: dev_mkdb\n"); exit(1); } |
