Sat Jan 3 08:49:03 2009 UTC ()
* When testing whether the fdesc file system is mounted, parse the
  output from mount(8) rather than df(1), because mount is more likely
  to be available on install media.  mount is invoked in a way that
  always prints an error message, and the content of the error message
  tells us whether fdesc is mounted.
* Don't use negative variable names.  Instead of nofdesc=false, use
  fdesc_mounted=true.
* Add a comment explaining that MAKEDEV may be executed in an environment
  that is missing some common commands.


(apb)
diff -r1.118 -r1.119 src/etc/MAKEDEV.tmpl

cvs diff -r1.118 -r1.119 src/etc/MAKEDEV.tmpl (expand / switch to context diff)
--- src/etc/MAKEDEV.tmpl 2008/11/28 16:04:31 1.118
+++ src/etc/MAKEDEV.tmpl 2009/01/03 08:49:03 1.119
@@ -1,5 +1,5 @@
 #!/bin/sh -
-#	$NetBSD: MAKEDEV.tmpl,v 1.118 2008/11/28 16:04:31 joerg Exp $
+#	$NetBSD: MAKEDEV.tmpl,v 1.119 2009/01/03 08:49:03 apb Exp $
 #
 # Copyright (c) 2003,2007,2008 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -287,13 +287,20 @@
 
 
 #
-# Apart from a few lines right at the end, this file should consist
-# entirely of function definitions.
+# NOTE:
 #
-# This file is used both as a standalone script (via "sh ./MAKEDEV all"
-# or similar), and as a function library (via "MAKEDEV_AS_LIBRARY=1 .
-# MAKEDEV" from MAKEDEV.local).
+# * MAKEDEV is used both as a standalone script (via "sh ./MAKEDEV
+#   all" or similar), and as a function library for MAKEDEV.local (via
+#   "MAKEDEV_AS_LIBRARY=1 . MAKEDEV").  Because of this, the script
+#   should consist almost entirely of function definitions, apart from a
+#   few lines right at the end.
 #
+# * MAKEDEV may be executed in an environment that is missing some
+#   common commands.  For example, it may be executed from a minimal
+#   system used during installation, or it may be executed early in the
+#   boot sequence before most file systems have been mounted.  It may
+#   also be executed in a cross-build environment on a non-NetBSD host.
+#
 
 usage()
 {
@@ -476,14 +483,32 @@
 	# only allow read&write for owner by default
 	umask 077
 
-	# Check if we have fdesc mounted
+	# Set fdesc_mounted=true if the fdesc file system is mounted
+	# on the current directory (typically "/dev").
+	# Later, this will be used to suppress creation of device nodes
+	# that are supplied by the fdesc file system.
+	#
+	fdesc_mounted=false
 	if [ -d fd ]; then
-		case "$(df fd)" in
-		*fdesc*)	nofdesc=false;;
-		*)		nofdesc=true;;
+		# Parse the output from "mount -u -o nosuchoption .".
+		# We don't parse the output from df(1) because that's
+		# less likely to be available on install media.
+		#
+		# If the current directory is a mount point for the
+		# fdesc file system, then the expected output (whether
+		# or not the current user is root) is:
+		#	mount_fdesc: -o suchoption: option not supported.
+		#
+		# If the current directory is not a mount point, then
+		# the expected output is:
+		#	mount: .: unknown special file or file system.
+		#
+		# If we are not running on NetBSD, or mount(8) is not
+		# found, then we should get some other error message.
+		#
+		case "$({ LC_ALL=C mount -u -o nosuchoption . ; } 2>&1)" in
+		*mount_fdesc*)	fdesc_mounted=true ;;
 		esac
-	else
-		nofdesc=true
 	fi
 
 	# do_force requires mknod
@@ -782,7 +807,7 @@
 	mkdev		zero	c %mem_chr% 12	666
 	mkdev		klog	c %log_chr% 0	600
 	mkdev		ksyms	c %ksyms_chr% 0 444
-	if $nofdesc; then
+	if ! $fdesc_mounted; then
 		mkdev	tty	c %ctty_chr% 0		666
 		mkdev	stdin	c %filedesc_chr% 0	666
 		mkdev	stdout	c %filedesc_chr% 1	666
@@ -908,7 +933,7 @@
 	;;
 
 fd)
-	if $nofdesc; then
+	if ! $fdesc_mounted; then
 		makedir fd 755
 		n=0
 		while [ $n -lt 64 ]