Subject: Re: MAKEDEV/MAKEDEV.subr issues in today's i386/amd64 builds (2/2)
To: Alan Barrett <apb@cequrux.com>
From: Greg A. Woods <woods@planix.com>
List: current-users
Date: 03/01/2007 16:20:27
 		(void)execl(INIT_MOUNT_MFS, "mount_mfs",
 		    "-b", "4096", "-f", "512",
-		    "-s", fs_size, "-n", STR(NINODE),
+		    "-s", fs_size,
+		    "-i", "140",
 		    "-p", "0755",
 		    "swap", "/dev", NULL);
 		_exit(1);
@@ -1723,28 +1814,27 @@
 #endif
 		dev = makedev(0, 0);
 
-	/* Make a console for us, so we can see things happening */
+	/* Make a console, so user can see what's happening */
 	if (mknod(_PATH_CONSOLE, 0666 | S_IFCHR, dev) == -1)
 		return(-1);
 
 	(void)freopen(_PATH_CONSOLE, "a", stderr);
 
-	warnx("Creating mfs /dev (%d blocks, %d inodes)", FSSIZE, NINODE);
-
-	/* Create a MAKEDEV script in the mfs /dev */
-	writefile(&mfile[0]);
-
-	/* Create a MAKEDEV.local script in the mfs /dev */
-	writefile(&mfile[1]);
+	warnx("Creating mfs /dev (%d blocks)", FSSIZE);
 
 	/* Run the makedev script to create devices */
 	switch ((pid = fork())) {
 	case 0:
-		dup2(2, 1);	/* Give the script stdout */
-		if (chdir("/dev") == 0)
-			(void)execl(INIT_BSHELL, "sh",
-			    mfile[0].len ? "./MAKEDEV" : "/etc/MAKEDEV",
-			    "init", NULL); 
+		(void) dup2(STDERR_FILENO, STDOUT_FILENO); /* Give it stdout */
+		/* XXX what about STDIN too!?!?!?!?!?!?!?!?!?!?!? */
+		if (chdir("/dev") == 0) {
+			warn("Unable to 'chdir(/dev)' to run %s", _PATH_MAKEDEV);
+			return (-1);
+		}		
+		(void) execl(INIT_BSHELL, "sh",
+			     _PATH_MAKEDEV,
+			     "all",
+			     (char *) NULL); 
 		_exit(1);
 		/* NOTREACHED */
 
@@ -1760,7 +1850,7 @@
 		}
 		return 0;
 	}
-	warn("Unable to run MAKEDEV");
+	warn("Unable to run '%s %s all'", INIT_BSHELL, _PATH_MAKEDEV);
 	return (-1);
 }
 #endif
Index: sbin/init/pathnames.h
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/sbin/init/pathnames.h,v
retrieving revision 1.6
diff -u -r1.6 pathnames.h
--- sbin/init/pathnames.h	7 Aug 2003 10:04:25 -0000	1.6
+++ sbin/init/pathnames.h	14 Feb 2007 20:01:59 -0000
@@ -36,5 +36,5 @@
 
 #include <paths.h>
 
-#define	_PATH_SLOGGER	"/sbin/session_logger"
+#define	_PATH_MAKEDEV	"/sbin/MAKEDEV"
 #define	_PATH_RUNCOM	"/etc/rc"


Index: etc/etc.i386/MAKEDEV.conf
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/etc/etc.i386/MAKEDEV.conf,v
retrieving revision 1.10.4.2
diff -u -r1.10.4.2 MAKEDEV.conf
--- etc/etc.i386/MAKEDEV.conf	18 Feb 2007 14:05:35 -0000	1.10.4.2
+++ etc/etc.i386/MAKEDEV.conf	20 Feb 2007 19:48:04 -0000
@@ -1,27 +1,20 @@
 # $NetBSD: MAKEDEV.conf,v 1.10.4.2 2007/02/18 14:05:35 tron Exp $
 
-# As of 2005-03-15, the "init" case must not create more than 1024 entries.
-init)
-	makedev std wscons wt0 fd0 fd1
+all_md)
+	makedev wscons wt0 fd0 fd1
 	makedev wd0 wd1 wd2 wd3 wd4 wd5 wd6 wd7
 	makedev sd0 sd1 sd2 sd3 sd4
 	makedev tty0 tty1
 	makedev st0 st1 ch0 cd0 cd1 mcd0 vnd0
-	makedev bpf
 	makedev ccd0 md0 ch0 random
 	makedev cgd0 cgd1
 	makedev amr0 iop0 mlx0 mly0 dpti0 dpt0 twe0 icp0
 	makedev ed0 ed1
-	makedev raid0 raid1 raid2 raid3
-	makedev ld0 ld1 ld2 ld3
+	makedev ld0 ld1 ld2 ld3 ld4 ld5 ld6 ld7
 	makedev xbd0 xbd1 xencons
 	makedev usbs
 	makedev ipty
-	makedev local
-	;;
-
-all_md)
-	makedev init
+	#
 	makedev tty2 tty3
 	makedev lpa0 lpa1 lpa2
 	makedev lpt0 lpt1 lpt2


Index: etc/Makefile
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/etc/Makefile,v
retrieving revision 1.337
diff -u -r1.337 Makefile
--- etc/Makefile	18 Sep 2006 22:39:37 -0000	1.337
+++ etc/Makefile	15 Feb 2007 15:41:51 -0000
@@ -248,7 +252,7 @@
 .endif
 
 CONFIGFILES+=		MAKEDEV.local
-FILESDIR_MAKEDEV.local=	/dev
+FILESDIR_MAKEDEV.local=	/etc
 FILESMODE_MAKEDEV.local=${BINMODE}
 
 CONFIGFILES+=		crontab
@@ -283,9 +287,13 @@
 	${_MKMSG_INSTALL} ${DESTDIR}/etc/ttys
 	${ETC_INSTALL_OBJ_FILE} -o ${BINOWN} -g ${BINGRP} -m 644 \
 	    ${.CURDIR}/etc.${MACHINE}/ttys ${DESTDIR}/etc
-	${_MKMSG_INSTALL} ${DESTDIR}/dev/MAKEDEV
+	${_MKMSG_INSTALL} ${DESTDIR}/sbin/MAKEDEV
 	${ETC_INSTALL_OBJ_FILE} -o ${BINOWN} -g ${BINGRP} -m 555 \
-	    MAKEDEV ${DESTDIR}/dev
+	    MAKEDEV ${DESTDIR}/sbin
+	${_MKMSG_INSTALL} ${DESTDIR}/dev/MAKEDEV
+	${INSTALL_SYMLINK} ../sbin/MAKEDEV ${DESTDIR}/dev
+	${_MKMSG_INSTALL} ${DESTDIR}/dev/MAKEDEV.local
+	${INSTALL_SYMLINK} ../etc/MAKEDEV.local ${DESTDIR}/dev
 .for owner group mode file in \
 		${BINOWN} operator	664	/etc/dumpdates  \
 		${BINOWN} operator	600	/etc/skeykeys \


Index: etc/MAKEDEV.tmpl
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/etc/MAKEDEV.tmpl,v
retrieving revision 1.67.2.2
diff -u -r1.67.2.2 MAKEDEV.tmpl
--- etc/MAKEDEV.tmpl	18 Feb 2007 14:05:36 -0000	1.67.2.2
+++ etc/MAKEDEV.tmpl	20 Feb 2007 19:48:00 -0000
@@ -919,7 +921,7 @@
 	mkdev enr$name$unit	c $chr $(($unit * 16 + 3)) 660 $g_operator
 	;;
 
-ses*|ch*|uk*)
+ses[0-9]*|ch[0-9]*|uk[0-9]*)
 	case $i in
 	ch*)	name=ch;	unit=${i#ch};	chr=%ch_chr%;;
 	uk*)	name=uk;	unit=${i#uk};	chr=%uk_chr%;;
@@ -1616,11 +1618,13 @@
 midevend)
 %MI_DEVICES_END%
 local)
-	if [ -f "$0.local" ]; then
+	makedev_local=/etc/${0##*/}.local
+	if [ -f "$makedev_local" ]; then
 		umask 0
-		sh $0.local all
+		sh $makedev_local all
 		umask 077
 	fi
+	unset makedev_local
 	;;
 
 *)


Index: etc/etc.i386/MAKEDEV.conf
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/etc/etc.i386/MAKEDEV.conf,v
retrieving revision 1.10.4.2
diff -u -r1.10.4.2 MAKEDEV.conf
--- etc/etc.i386/MAKEDEV.conf	18 Feb 2007 14:05:35 -0000	1.10.4.2
+++ etc/etc.i386/MAKEDEV.conf	20 Feb 2007 19:48:04 -0000
@@ -1,27 +1,20 @@
 # $NetBSD: MAKEDEV.conf,v 1.10.4.2 2007/02/18 14:05:35 tron Exp $
 
-# As of 2005-03-15, the "init" case must not create more than 1024 entries.
-init)
-	makedev std wscons wt0 fd0 fd1
+all_md)
+	makedev wscons wt0 fd0 fd1
 	makedev wd0 wd1 wd2 wd3 wd4 wd5 wd6 wd7
 	makedev sd0 sd1 sd2 sd3 sd4
 	makedev tty0 tty1
 	makedev st0 st1 ch0 cd0 cd1 mcd0 vnd0
-	makedev bpf
 	makedev ccd0 md0 ch0 random
 	makedev cgd0 cgd1
 	makedev amr0 iop0 mlx0 mly0 dpti0 dpt0 twe0 icp0
 	makedev ed0 ed1
-	makedev raid0 raid1 raid2 raid3
-	makedev ld0 ld1 ld2 ld3
+	makedev ld0 ld1 ld2 ld3 ld4 ld5 ld6 ld7
 	makedev xbd0 xbd1 xencons
 	makedev usbs
 	makedev ipty
-	makedev local
-	;;
-
-all_md)
-	makedev init
+	#
 	makedev tty2 tty3
 	makedev lpa0 lpa1 lpa2
 	makedev lpt0 lpt1 lpt2


#
# note these diffs are against netbsd-1-6
#

Index: init.8
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/sbin/init/init.8,v
retrieving revision 1.24
diff -u -r1.24 init.8
--- init.8	16 Nov 2001 11:37:04 -0000	1.24
+++ init.8	15 Jun 2003 19:03:25 -0000
@@ -36,7 +36,7 @@
 .\"
 .\"     @(#)init.8	8.6 (Berkeley) 5/26/95
 .\"
-.Dd April 29, 2000
+.Dd June 15, 2003
 .Dt INIT 8
 .Os
 .Sh NAME
@@ -47,25 +47,42 @@
 .Sh DESCRIPTION
 The
 .Nm
-program is the last stage of the boot process (after the kernel loads
-and initializes all the devices).
-It normally begins multi-user operation.
-.Pp
-The following table describes the state machine used by
-.Nm "" :
-.Bl -enum
-.It
-Single user shell.
+program forms the last stage of the boot process (after the kernel loads
+and initializes all the devices).  It is started by the kernel as the
+first user-level process and always has a PID of one (1).  If it dies
+unexpectedly the kernel will panic and reboot.  During a normal
+administrator-initiated system reboot or halt it is told to ignore all
+future signals and then sit and twiddle its thumbs until the kernel
+reboots or halts or the machine is powered off.
+.Pp
 .Nm
-may be passed
+is essentially a specialized finite state machine.
+The following table describes the state machine it implements:
+.Bl -tag -width 00.
+.It 0.
+Start.  Given the
 .Fl s
-from the boot program to prevent the system from going multi-user and
-to instead execute a single user shell without starting the normal
-daemons.  The system is then quiescent for maintenance work and may
-later be made to go to state 2 (multi-user) by exiting the single-user
-shell (with ^D).
-.It
-Multi-user boot (default operation).
+flag, we start at state 1; otherwise state 2
+.It 1.
+Single-user mode
+.Pq Fn single_user .
+The system is quiescent for maintenance work with usually only the single-user shell process
+running.  The system may be
+made to go to state 2 (multi-user) by exiting the single-user shell
+(with, for example, the
+.Dv EOF
+special character
+.Pq Sq ^D ) .
+If
+the shell is killed with
+.Dv SIGKILL
+then
+.Nm
+will stop doing anything, ignore further signals, and wait for the
+kernel to halt or reboot.
+.It 2.
+Multi-user boot (default operation)
+.Pq Fn run_com .
 Executes
 .Pa /etc/rc
 (see
@@ -77,58 +94,88 @@
 .Sq autoboot .
 If
 .Pa /etc/rc
-exits with a non-zero (error) exit code, commence single user
-operation by giving the super-user a shell on the console by going
-to state 1 (single user).
+exits with a non-zero (error) exit code, go to state 1 (single user).
+If
+.Pa /etc/rc
+sends
+.Dv SIGTERM
+then turn off signal handlers and wait for the kernel to halt or reboot.
 Otherwise, proceed to state 3.
-.It
+.It 3.
 Setup ttys as specified in
-.Xr ttys 5 .
+.Xr ttys 5
+.Pq Fn read_ttys .
 See below for more information.
 On completion, continue to state 4.
-.It
-Multi-user operation.
-Depending upon the signal received, change state appropriately;
-on
-.Dv SIGTERM ,
-go to state 7;
-on
-.Dv SIGHUP ,
-go to state 5;
-on
-.Dv SIGTSTP ,
-go to state 6.
-.It
+.It 4.
+Multi-user operation
+.Pq Fn multi_user .
+Depending upon the signal received, change state appropriately:
+.Pp
+. Bl -tag -compact -width SIGTERM
+. It Dv SIGHUP
+go to state 5
+.Pq Fn clean_ttys ;
+. It Dv SIGINT
+go to state 1
+.Pq Fn single_user ;
+. It Dv SIGTSTP
+go to state 6
+.Pq Fn go_catatonic ;
+. It Dv SIGUSR1
+go to state 8
+.Pq Fn go_single_user ;
+. It Dv SIGTERM
+go to state 7
+.Pq Fn kill_ttys ;
+. El
+.It 5.
 Clean-up mode; re-read
-.Xr ttys 5 ,
-killing off the controlling processes on lines that are now
+.Xr ttys 5
+.Pq Fn clean_ttys .
+Kills off the controlling processes on lines that are now
 .Sq off ,
-and starting processes that are newly
+and start processes for all those that are newly turned
 .Sq on .
+Restore internal state of all unchanged lines to match external state.
 On completion, go to state 4.
-.It
+.It 6.
 .Sq Boring
-mode; no new sessions.
-Signals as per state 4.
-.It
-Shutdown mode.
+mode
+.Pq Fn go_catatonic .
+Internally mark all lines off.
+On completion, go to state 4.
+.It 7.
+Shutdown mode
+.Pq Fn kill_ttys .
 Send
 .Dv SIGHUP
 to all controlling processes, reap the processes for 30 seconds,
-and the go to state 1 (single user); warning if not all the processes died.
+warning if not all the sessions have terminated.
+Upon completion go to state 8.
+.It 8.
+Single-user transition mode
+.Pq Fn go_single_user .
+Internally mark all lines off and log single-user state transition in
+.Xr wtmp 5
+file.
+On completion, go to state 1.
 .El
 .Pp
 If the
 .Sq console
 entry in the
 .Xr ttys 5
-file is marked ``insecure'', then
+file is marked
+.Dq insecure ,
+then
 .Nm
 will require that the superuser password be
 entered before the system will start a single-user shell.
 The password check is skipped if the
 .Sq console
-is marked as ``secure''.
+is marked as
+.Dq secure .
 .Pp
 The kernel runs with four different levels of security.
 Any superuser process can raise the security level, but only
@@ -341,6 +388,7 @@
 .Xr kill 1 ,
 .Xr login 1 ,
 .Xr sh 1 ,
+.Xr logwtmp 2 ,
 .Xr options 4 ,
 .Xr ttys 5 ,
 .Xr config 8 ,