[Pkg-sysvinit-devel] Bug#542953: sysvinit: fixes for GNU/kFreeBSD

Aurelien Jarno aurel32 at debian.org
Sat Aug 22 13:00:52 UTC 2009


Package: sysvinit
Version: 2.87dsf-2
Severity: important
Tags: patch

Since insserv is enabled by default, it is not possible to do GNU/kFreeBSD
specific initialisation in a dedicated script and ensure it is done at 
the right moment due to dependencies issue. This is especially true for
mtab.sh, which makes the system no bootable if /etc/mtab has not been yet
changed to a symlink, by mounting an empty tmpfs over /dev.

The patch below fixes the problem by having different initialisation on 
Linux and GNU/kFreeBSD. In case the systems is unknown, it switches to 
doing nothing by default, which is probaby the safest option. It also 
correctly detects available filesystem on GNU/kFreeBSD.


diff -u sysvinit-2.87dsf/debian/initscripts/lib/init/mount-functions.sh sysvinit-2.87dsf/debian/initscripts/lib/init/mount-functions.sh
--- sysvinit-2.87dsf/debian/initscripts/lib/init/mount-functions.sh
+++ sysvinit-2.87dsf/debian/initscripts/lib/init/mount-functions.sh
@@ -46,12 +46,31 @@
 	elif [ "$1" = tmpfs ]
 	then # always accept tmpfs, to mount /lib/init/rw before /proc
 		FSTYPE=$1
-	elif grep -E -qs "$1\$" /proc/filesystems
-	then
-		FSTYPE=$1
-	elif grep -E -qs "$2\$" /proc/filesystems
-	then
-		FSTYPE=$2
+	else 
+		case "$KERNEL" in 
+			Linux)
+				if grep -E -qs "$1\$" /proc/filesystems
+				then
+					FSTYPE=$1
+				elif grep -E -qs "$2\$" /proc/filesystems
+				then
+					FSTYPE=$2
+				fi
+				;;
+			GNU/kFreeBSD)
+				if kldstat -q -m "$1"
+				then
+					FSTYPE=$1
+				elif kldstat -q -m "$2"
+				then
+					FSTYPE=$2
+				fi
+				;;
+			*)
+				# On unknown systems, use the first FS type
+				FSTYPE=$1
+				;;
+		esac
 	fi
 
 	if [ ! "$FSTYPE" ]
diff -u sysvinit-2.87dsf/debian/initscripts/etc/init.d/mtab.sh sysvinit-2.87dsf/debian/initscripts/etc/init.d/mtab.sh
--- sysvinit-2.87dsf/debian/initscripts/etc/init.d/mtab.sh
+++ sysvinit-2.87dsf/debian/initscripts/etc/init.d/mtab.sh
@@ -63,7 +63,7 @@
 	fi
 }
 
-do_start () {
+do_start_linux () {
 	DO_MTAB=""
 	MTAB_PATH="$(readlink -f /etc/mtab || :)"
 	case "$MTAB_PATH" in
@@ -160,6 +160,30 @@
 	exec 0<&9 9<&-
 }
 
+do_start_kfreebsd () {
+	# On GNU/kFreeBSD mount does not update /etc/mtab, so
+	# we need to use a symlink
+	if [ "$(readlink -f /etc/mtab)" != "/proc/mounts" ] ; then
+		echo "Warning: replacing /etc/mtab with a symlink to /proc/mounts."
+		rm -f /etc/mtab
+		ln -s /proc/mounts /etc/mtab
+	fi
+}
+
+do_start () {
+	case "$KERNEL" in 
+		"Linux")
+			do_start_linux
+			;;
+		"GNU/kFreeBSD")
+			do_start_kfreebsd
+			;;
+		*)
+			# Doing nothing is the safest option
+			;;
+	esac
+}
+
 case "$1" in
   start|"")
 	do_start
diff -u sysvinit-2.87dsf/debian/initscripts/etc/init.d/mountkernfs.sh sysvinit-2.87dsf/debian/initscripts/etc/init.d/mountkernfs.sh
--- sysvinit-2.87dsf/debian/initscripts/etc/init.d/mountkernfs.sh
+++ sysvinit-2.87dsf/debian/initscripts/etc/init.d/mountkernfs.sh
@@ -19,6 +19,8 @@
 
 [ -f /etc/default/tmpfs ] && . /etc/default/tmpfs
 
+KERNEL="$(uname -s)"
+
 do_start () {
 	#
 	# Get some writable area available before the root is checked
@@ -32,19 +34,37 @@
 	# Make pidfile omit directory for sendsigs
 	mkdir /lib/init/rw/sendsigs.omit.d/
 
-	#
-	# Mount proc filesystem on /proc
-	#
-	domount proc "" /proc proc -onodev,noexec,nosuid
-
-	#
-	# Mount sysfs on /sys
-	#
-	# Only mount sysfs if it is supported (kernel >= 2.6)
-	if grep -E -qs "sysfs\$" /proc/filesystems
-	then
-		domount sysfs "" /sys sysfs -onodev,noexec,nosuid
-	fi
+	case "$KERNEL" in 
+		"Linux")
+			#
+			# Mount proc filesystem on /proc
+			#
+			domount proc "" /proc proc -onodev,noexec,nosuid
+
+			#
+			# Mount sysfs on /sys
+			#
+			# Only mount sysfs if it is supported (kernel >= 2.6)
+			if grep -E -qs "sysfs\$" /proc/filesystems
+			then
+				domount sysfs "" /sys sysfs -onodev,noexec,nosuid
+			fi
+			;;
+		"GNU/kFreeBSD")
+			#
+			# Mount proc filesystem on /proc
+			#
+			domount linprocfs "" /proc linprocfs
+
+			#
+			# Mount sys filesystem on /sys
+			#
+			domount linsysfs "" /sys linsysfs
+			;;
+		*)
+			# Doing nothing is the safest option
+			;;
+	esac
 
 	# Mount /var/run and /var/lock as tmpfs if enabled
 	if [ yes = "$RAMRUN" ] ; then
diff -u sysvinit-2.87dsf/debian/initscripts/etc/init.d/mountdevsubfs.sh sysvinit-2.87dsf/debian/initscripts/etc/init.d/mountdevsubfs.sh
--- sysvinit-2.87dsf/debian/initscripts/etc/init.d/mountdevsubfs.sh
+++ sysvinit-2.87dsf/debian/initscripts/etc/init.d/mountdevsubfs.sh
@@ -27,7 +27,7 @@
 . /lib/lsb/init-functions
 . /lib/init/mount-functions.sh
 
-do_start () {
+do_start_linux () {
 	#
 	# Mount a tmpfs on /dev/shm
 	#
@@ -42,39 +42,57 @@
 	# mount devpts if it is compiled in (older devfs didn't require it
 	# to be compiled in at all).
 	#
-	if [ "$KERNEL" = Linux ]
+	#
+	# Since kernel 2.5.something, devfs doesn't include
+	# a standard /dev/pts directory anymore. So if devfs
+	# is mounted on /dev we need to create that directory
+	# manually.
+	#
+	if [ ! -d /dev/pts ]
 	then
-		#
-		# Since kernel 2.5.something, devfs doesn't include
-		# a standard /dev/pts directory anymore. So if devfs
-		# is mounted on /dev we need to create that directory
-		# manually.
-		#
-		if [ ! -d /dev/pts ]
+		if grep -qs '/dev devfs' /proc/mounts
 		then
-			if grep -qs '/dev devfs' /proc/mounts
-			then
-				mkdir --mode=755 /dev/pts
-				[ -x /sbin/restorecon ] && /sbin/restorecon /dev/pts
-			fi
+			mkdir --mode=755 /dev/pts
+			[ -x /sbin/restorecon ] && /sbin/restorecon /dev/pts
 		fi
-		if [ -d /dev/pts ]
+	fi
+	if [ -d /dev/pts ]
+	then
+		if [ ! -c /dev/ptmx ]
 		then
-			if [ ! -c /dev/ptmx ]
+			mknod --mode=666 /dev/ptmx c 5 2
+			ES=$?
+			if [ "$ES" != 0 ]
 			then
-				mknod --mode=666 /dev/ptmx c 5 2
-				ES=$?
-				if [ "$ES" != 0 ]
-				then
-					log_warning_msg "Failed making node /dev/ptmx with error code ${ES}."
-				fi
-				[ -x /sbin/restorecon ] && /sbin/restorecon /dev/ptmx
+				log_warning_msg "Failed making node /dev/ptmx with error code ${ES}."
 			fi
-			domount devpts "" /dev/pts devpts -onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE
+			[ -x /sbin/restorecon ] && /sbin/restorecon /dev/ptmx
 		fi
+		domount devpts "" /dev/pts devpts -onoexec,nosuid,gid=$TTYGRP,mode=$TTYMODE
 	fi
 }
 
+do_start_kfreebsd () {
+	#
+	# Mount /dev/fd
+	#
+	domount fdescfs "" /dev/fd fdescfs
+}
+
+do_start () {
+	case "$KERNEL" in 
+		"Linux")
+			do_start_linux
+			;;
+		"GNU/kFreeBSD")
+			do_start_kfreebsd
+			;;
+		*)
+			# Doing nothing is safe
+			;;
+	esac
+}
+
 case "$1" in
   "")
 	echo "Warning: mountdevsubfs should be called with the 'start' argument." >&2


-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: kfreebsd-amd64 (x86_64)

Kernel: kFreeBSD 7.2-1-amd64
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages sysvinit depends on:
ii  initscripts                  2.87dsf-2 scripts for initializing and shutt
ii  libc0.1                      2.9-25      GNU C Library: Shared libraries
ii  sysv-rc                      2.87dsf-2 System-V-like runlevel change mech
ii  sysvinit-utils               2.87dsf-2 System-V-like utilities

sysvinit recommends no packages.

sysvinit suggests no packages.

-- no debconf information





More information about the Pkg-sysvinit-devel mailing list