Date: Tue, 12 Dec 2000 14:30:45 -0800 (PST) From: Seth Kingsley <sethk@pike.osd.bsdi.com> To: FreeBSD-gnats-submit@freebsd.org Subject: bin/23509: Augment dev_mkdb to allow different directory and database paths. Message-ID: <200012122230.eBCMUji00204@pike.osd.bsdi.com> Resent-Message-ID: <200012122240.eBCMe1b14672@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 23509
>Category: bin
>Synopsis: Augment dev_mkdb to allow different directory and database paths.
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Tue Dec 12 14:40:01 PST 2000
>Closed-Date:
>Last-Modified:
>Originator: Seth Kingsley
>Release: FreeBSD 4.2-STABLE i386
>Organization:
>Environment:
FreeBSD 4.1.1-STABLE #2: Wed Nov 29 15:10:16 PST 2000
>Description:
dev_mkdb(1) has the pathnames /var/run/dev.db and /dev hardcoded into
it. In order to create device databases for devices that exist outside
of normal /dev (eg within a chroot()), you should be able to specify an
alternate directory to search for device nodes.
>How-To-Repeat:
N/A
>Fix:
Adds a -f option and an optional directory argument:
Index: dev_mkdb.8
===================================================================
RCS file: /ncvs/src/usr.sbin/dev_mkdb/dev_mkdb.8,v
retrieving revision 1.5
diff -u -r1.5 dev_mkdb.8
--- dev_mkdb.8 1999/12/27 08:01:11 1.5
+++ dev_mkdb.8 2000/12/12 22:14:56
@@ -42,17 +42,22 @@
database
.Sh SYNOPSIS
.Nm dev_mkdb
+.Op Fl f Ar file
+.Op Ar directory
.Sh DESCRIPTION
The
.Nm
command creates a
.Xr db 3
hash access method database in
-.Pa /var/run/dev.db
+.Pa file
+.Pf ( Fa /var/run/dev.db
+by default)
which contains the names of all of the character and block special
-files in the
-.Pa /dev
-directory, using the file type and the
+files in
+.Pa directory
+.Pf ( Fa /dev
+by default), using the file type and the
.Fa st_rdev
field as the key.
.Pp
@@ -63,9 +68,9 @@
.Sh FILES
.Bl -tag -width /var/run/dev.db -compact
.It Pa /dev
-Device directory.
+Default device directory.
.It Pa /var/run/dev.db
-Database file.
+Default database file.
.El
.Sh SEE ALSO
.Xr ps 1 ,
Index: dev_mkdb.c
===================================================================
RCS file: /ncvs/src/usr.sbin/dev_mkdb/dev_mkdb.c,v
retrieving revision 1.4
diff -u -r1.4 dev_mkdb.c
--- dev_mkdb.c 1999/08/28 01:16:04 1.4
+++ dev_mkdb.c 2000/12/12 20:42:03
@@ -76,12 +76,16 @@
} bkey;
DB *db;
DBT data, key;
- int ch;
+ int ch, ndbname = 0;
u_char buf[MAXNAMLEN + 1];
- char dbtmp[MAXPATHLEN + 1], dbname[MAXPATHLEN + 1];
+ char dbtmp[MAXPATHLEN + 1], dbname[MAXPATHLEN + 1], *dirname;
- while ((ch = getopt(argc, argv, "")) != -1)
+ while ((ch = getopt(argc, argv, "f:")) != -1)
switch((char)ch) {
+ case 'f':
+ strlcpy(dbname, optarg, sizeof(dbname));
+ ndbname = 1;
+ break;
case '?':
default:
usage();
@@ -89,16 +93,26 @@
argc -= optind;
argv += optind;
- if (argc > 0)
+ if (argc > 1)
usage();
+ else if (argc == 1)
+ dirname = argv[0];
+ else
+ dirname = _PATH_DEV;
- if (chdir(_PATH_DEV))
- err(1, "%s", _PATH_DEV);
+ if (!ndbname)
+ {
+ (void)snprintf(dbname, sizeof(dbtmp), "%sdev.db", _PATH_VARRUN);
+ (void)snprintf(dbtmp, sizeof(dbtmp), "%sdev.tmp", _PATH_VARRUN);
+ }
+ else
+ (void)snprintf(dbtmp, sizeof(dbtmp), "%s.tmp", dbname);
+ if (chdir(dirname))
+ err(1, "%s", dirname);
+
dirp = opendir(".");
- (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)
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200012122230.eBCMUji00204>
