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 <sethk@pike.osd.bsdi.com> MFC after: 1 week
This commit is contained in:
parent
56f7305f58
commit
00a2029a0e
@ -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 ,
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user