From 00a2029a0e3a03150ec602c46cb88bb45e7ba892 Mon Sep 17 00:00:00 2001 From: Ian Dowse Date: Sun, 18 Nov 2001 17:24:28 +0000 Subject: [PATCH] Allow the path for /dev and the location of the database file to be overridden on the command line. This is useful for setting up chroot/jail environments. PR: bin/23509 Submitted by: Seth Kingsley MFC after: 1 week --- usr.sbin/dev_mkdb/dev_mkdb.8 | 17 +++++++++++------ usr.sbin/dev_mkdb/dev_mkdb.c | 30 ++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/usr.sbin/dev_mkdb/dev_mkdb.8 b/usr.sbin/dev_mkdb/dev_mkdb.8 index d3861106c9d8..8071e14a8b64 100644 --- a/usr.sbin/dev_mkdb/dev_mkdb.8 +++ b/usr.sbin/dev_mkdb/dev_mkdb.8 @@ -42,17 +42,22 @@ database .Sh SYNOPSIS .Nm +.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 +.Ar file +.Pf ( Pa /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 +.Ar directory +.Pf ( Pa /dev +by default), using the file type and the .Fa st_rdev field as the key. .Pp @@ -63,9 +68,9 @@ the latter is the st_rdev field. .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 , diff --git a/usr.sbin/dev_mkdb/dev_mkdb.c b/usr.sbin/dev_mkdb/dev_mkdb.c index 0a0e2c1857a8..d79674ee7bb6 100644 --- a/usr.sbin/dev_mkdb/dev_mkdb.c +++ b/usr.sbin/dev_mkdb/dev_mkdb.c @@ -76,12 +76,18 @@ main(argc, argv) } bkey; DB *db; DBT data, key; - int ch; + int ch, fflag; u_char buf[MAXNAMLEN + 1]; char dbtmp[MAXPATHLEN + 1], dbname[MAXPATHLEN + 1]; + const char *dirname; - while ((ch = getopt(argc, argv, "")) != -1) + fflag = 0; + while ((ch = getopt(argc, argv, "f:")) != -1) switch((char)ch) { + case 'f': + strlcpy(dbname, optarg, sizeof(dbname)); + fflag = 1; + break; case '?': default: usage(); @@ -89,16 +95,24 @@ main(argc, argv) argc -= optind; argv += optind; - if (argc > 0) + if (argc > 1) usage(); + if (argc == 1) + dirname = argv[0]; + else + dirname = _PATH_DEV; - if (chdir(_PATH_DEV)) - err(1, "%s", _PATH_DEV); + if (!fflag) { + (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) @@ -148,6 +162,6 @@ main(argc, argv) static void usage() { - (void)fprintf(stderr, "usage: dev_mkdb\n"); + (void)fprintf(stderr, "usage: dev_mkdb [-f file] [directory]\n"); exit(1); }