[BACK]Return to sysdb CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / etc / rc.d

File: [cvs.NetBSD.org] / src / etc / rc.d / sysdb (download)

Revision 1.24, Sun Jun 3 21:42:45 2012 UTC (7 years, 6 months ago) by joerg
Branch: MAIN
CVS Tags: yamt-pagecache-base9, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, tls-maxphys-base, tls-maxphys, tls-earlyentropy-base, tls-earlyentropy, riastradh-xf86-video-intel-2-7-1-pre-2-21-15, riastradh-drm2-base3, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, netbsd-7-nhusb-base-20170116, netbsd-7-nhusb-base, netbsd-7-nhusb, netbsd-7-base, netbsd-7-2-RELEASE, netbsd-7-1-RELEASE, netbsd-7-1-RC2, netbsd-7-1-RC1, netbsd-7-1-2-RELEASE, netbsd-7-1-1-RELEASE, netbsd-7-1, netbsd-7-0-RELEASE, netbsd-7-0-RC3, netbsd-7-0-RC2, netbsd-7-0-RC1, netbsd-7-0-2-RELEASE, netbsd-7-0-1-RELEASE, netbsd-7-0, netbsd-7, khorben-n900, agc-symver-base, agc-symver
Changes since 1.23: +2 -1 lines

Switch device database to cdb(5). Rework ttyname(3) and ttyname_r(3) to
depend on new devname_r(3) as heart. Add /dev/pts magic directly to
devname(3). While it can lead to returning non-existing paths, the
behavior is more consistent that way. Drop caching layer in devname(3),
it doesn't buy anything for the common case of having access to the
database. Teach devname(3) proper fallback behavior of scanning /dev.
Create both old-style and new-style database for now in /etc/rc.d/sysdb.

#!/bin/sh
#
# $NetBSD: sysdb,v 1.24 2012/06/03 21:42:45 joerg Exp $
#

# PROVIDE: sysdb
# REQUIRE: mountcritremote
# BEFORE:  DAEMON

$_rc_subr_loaded . /etc/rc.subr

name="sysdb"
rcvar=$name
start_cmd="sysdb_start"
stop_cmd=":"
extra_commands="devdb utmp services netgroup password"
devdb_cmd="build_devdb"
utmp_cmd="build_utmp"
services_cmd="build_services"
netgroup_cmd="build_netgroup"
password_cmd="build_password"
echo=:

sysdb_start()
{
	echo -n "Building databases:"
	echo=echo
	comma=" "
	$devdb_cmd
	$utmp_cmd
	$services_cmd
	$netgroup_cmd
	$password_cmd
	echo "."
}

check_file()
{
	local src="$1"
	local db="$2"

	shift 2
	if [ ! -e "$src" ]; then
		return
	fi
	if [ \( ! -f "$db" \) -o \( "$src" -nt "$db" \) ]; then
		$echo -n "$comma$(basename "$src")"
		comma=", "
		"$@"
	fi
}

build_services()
{
	check_file /etc/services /var/db/services.cdb services_mkdb -q
}

build_netgroup()
{
	check_file /etc/netgroup /var/db/netgroup.db netgroup_mkdb
}

build_devdb()
{
	check_file /dev /var/run/dev.db dev_mkdb
	check_file /dev /var/run/dev.cdb dev_mkdb
}

build_password()
{
	local p=/etc/master.passwd
	check_file $p /etc/spwd.db pwd_mkdb -w $p
}

build_utmp()
{
	#	Re-create /var/run/utmp and /var/run/utmpx, which are
	#	deleted by mountcritlocal but can't be recreated by it
	#	because install and chown may not be available then
	#	(possibly no /usr).
	#
	local i
	for i in "" x; do
		if [ ! -f /var/run/utmp$i ]; then
			$echo -n "${comma}utmp$i"
			comma=", "
			install -c -m 664 -g utmp /dev/null /var/run/utmp$i
		fi
	done
}

load_rc_config $name
run_rc_command "$1"