From e64280b8b30569ad6029e48f23d290e06a28d7ed Mon Sep 17 00:00:00 2001 From: "eike-hotplug@sf-tec.de" Date: Sat, 10 Jan 2004 01:19:57 -0800 Subject: [PATCH] [PATCH] LSB init script and other stuff I had too much time during the holidays, so I played a bit with udev. The changes are like last time mostly on the init stuff. I'm sending you this as a great diff which is just for comments. What it does: -fix a typo in Makefile -use only one "grep -v" instead of many -don't include BK-Files into release (shrinks the stuff to 30%!) -add a new init script which is LSB compliant -add some flags to choose which one to use -use /etc/udev/udev.conf in Redhat init script as the source for the udev directory. If this is not done then the init script may create a directory which udev itself isn't using (I changed /udev to /Udev to avoid collisions with /usr and ran into this) -first check for sysfs_dir before creating udev_root (maybe someone else has already fixed this, I saw this discussion on lkml) --- Makefile | 15 ++--- etc/init.d/udev | 11 ++-- etc/init.d/udev.init.LSB | 133 +++++++++++++++++++++++++++++++++++++++ extras/ide-devfs.sh | 2 +- udev.spec | 12 +++- 5 files changed, 159 insertions(+), 14 deletions(-) create mode 100644 etc/init.d/udev.init.LSB diff --git a/Makefile b/Makefile index ffd61c0400..36f0272d02 100644 --- a/Makefile +++ b/Makefile @@ -61,7 +61,7 @@ udevdir = ${prefix}/udev #USE_KLIBC = true # If you are running a cross compiler, you may want to set this -# to something more interesting, like "arm-linux-". I you want +# to something more interesting, like "arm-linux-". If you want # to compile vs uClibc, that can be done here as well. CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- CC = $(CROSS)gcc @@ -231,7 +231,7 @@ clean: -C $$target $@ ; \ done ; \ -DISTFILES = $(shell find . \( -not -name '.' \) -print | grep -v CVS | grep -v "\.tar\.gz" | grep -v "\/\." | grep -v releases | grep -v BitKeeper | grep -v SCCS | grep -v "\.tdb" | grep -v "test\/sys" | sort ) +DISTFILES = $(shell find . \( -not -name '.' \) -print | grep -v -e CVS -e "\.tar\.gz$" -e "\/\." -e releases -e BitKeeper -e SCCS -e "\.tdb$" -e test/sys | sort ) DISTDIR := $(RELEASE_NAME) srcdir = . release: clean @@ -292,13 +292,16 @@ install-config: $(GEN_CONFIGS) $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir); \ fi - - install: install-config install-dbus-policy all $(INSTALL) -d $(DESTDIR)$(udevdir) $(INSTALL) -d $(DESTDIR)$(hotplugdir) $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT) - $(INSTALL_PROGRAM) -D etc/init.d/udev $(DESTDIR)$(initdir)/udev + @if [ "x$(USE_LSB)" = "xtrue" ]; then \ + $(INSTALL_PROGRAM) -D etc/init.d/udev.init.LSB $(DESTDIR)$(initdir)/udev + ln -s $(DESTDIR)$(initdir)/udev $(sbin_dir)/rcudev + else + $(INSTALL_PROGRAM) -D etc/init.d/udev $(DESTDIR)$(initdir)/udev + fi $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8 - rm -f $(DESTDIR)$(hotplugdir)/udev.hotplug - ln -f -s $(sbindir)/$(ROOT) $(DESTDIR)$(hotplugdir)/udev.hotplug @@ -324,5 +327,3 @@ uninstall: uninstall-dbus-policy $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \ -C $$target $@ ; \ done ; \ - - diff --git a/etc/init.d/udev b/etc/init.d/udev index 0d26d07083..364a9aa5f7 100644 --- a/etc/init.d/udev +++ b/etc/init.d/udev @@ -7,7 +7,8 @@ . /etc/rc.d/init.d/functions -udev_dir=/udev +. /etc/udev/udev.conf + sysfs_dir=/sys bin=/sbin/udev @@ -42,12 +43,12 @@ run_udev () { case "$1" in start) - if [ ! -d $udev_dir ]; then - mkdir $udev_dir - fi if [ ! -d $sysfs_dir ]; then exit 1 fi + if [ ! -d $udev_root ]; then + mkdir $udev_root + fi # propogate /udev from /sys - we only need this while we do not # have initramfs and an early user-space with which to do early # device bring up @@ -62,7 +63,7 @@ case "$1" in run_udev ;; status) - if [ -d $udev_dir ]; then + if [ -d $udev_root ]; then echo "the udev device node directory exists" else echo "the udev device node directory does not exist" diff --git a/etc/init.d/udev.init.LSB b/etc/init.d/udev.init.LSB new file mode 100644 index 0000000000..0f5881c416 --- /dev/null +++ b/etc/init.d/udev.init.LSB @@ -0,0 +1,133 @@ +#! /bin/sh +# +# Author: Rolf Eike Beer +# derived from original RedHat udev init script +# based on the SuSE 9.0 template (c) 1995-2002 SuSE Linux AG +# +# /etc/init.d/udev +# and its symbolic link +# /(usr/)sbin/rcudev +# +# System startup script for udev +# +# LSB compatible service control script; see http://www.linuxbase.org/spec/ +# +### BEGIN INIT INFO +# Provides: udev +# Required-Start: +# Required-Stop: +# Default-Start: 1 2 3 5 +# Default-Stop: 0 6 +# Short-Description: manage user-space device nodes in /udev +# Description: Start udev to create the device files for all +# devices already present in system when script is +# called. All other devices files will be automatically +# created when udev is called via /sbin/hotplug. +# Requires at least a kernel 2.6 to work properly. +### END INIT INFO +# +# Note on script names: +# http://www.linuxbase.org/spec/refspecs/LSB_1.2.0/gLSB/scrptnames.html +# A registry has been set up to manage the init script namespace. +# http://www.lanana.org/ +# Please use the names already registered or register one or use a +# vendor prefix. + + +# Check for missing binaries (stale symlinks should not happen) +UDEV_BIN=/sbin/udev +test -x $UDEV_BIN || exit 5 + +# Check for existence of needed config file and read it +UDEV_CONFIG=/etc/udev/udev.conf +test -r $UDEV_CONFIG || exit 6 +. $UDEV_CONFIG + +# Directory where sysfs is mounted +SYSFS_DIR=/sys + +# Source LSB init functions +. /lib/lsb/init-functions + +run_udev () { + # handle block devices and their partitions + for i in ${SYSFS_DIR}/block/*; do + # add each drive + export DEVPATH=${i#${SYSFS_DIR}} + $UDEV_BIN block & + + # add each partition, on each device + for j in $i/*; do + if [ -f $j/dev ]; then + export DEVPATH=${j#${SYSFS_DIR}} + $UDEV_BIN block & + fi + done + done + # all other device classes + for i in ${SYSFS_DIR}/class/*; do + for j in $i/*; do + if [ -f $j/dev ]; then + export DEVPATH=${j#${SYSFS_DIR}} + CLASS=`echo ${i#${SYSFS_DIR}} | \ + cut --delimiter='/' --fields=3-` + $UDEV_BIN $CLASS & + fi + done + done +} + +case "$1" in + start) + if [ ! -d $SYSFS_DIR ]; then + log_failure_msg "${0}: SYSFS_DIR \"$SYSFS_DIR\" not found" + exit 1 + fi + if [ ! -d $udev_root ]; then + mkdir $udev_root || exit 4 + fi + # propogate /udev from /sys - we only need this while we do not + # have initramfs and an early user-space with which to do early + # device bring up + echo -n "Creating initial udev device nodes: " + export ACTION=add + run_udev + log_success_msg + ;; + stop) + # be careful + echo -n "Removing udev device nodes: " + export ACTION=remove + run_udev + rm -f $udev_db || exit 1 + rmdir $udev_root || exit 1 + log_success_msg + ;; + restart) + $0 stop + $0 start + + exit $? + ;; + force-reload) + echo -n "Reload udev " + $0 stop && $0 start + exit $? + ;; + reload) + exit 3 + ;; + status) + echo -n "Checking for udev root directory: " + if [ -d $udev_root ]; then + log_success_msg found + else + log_warning_msg "not found" + exit 3 + fi + ;; + *) + echo "Usage: $0 {start|stop|status|restart|force-reload|reload}" + exit 1 + ;; +esac diff --git a/extras/ide-devfs.sh b/extras/ide-devfs.sh index db96b5d299..57fb00b676 100644 --- a/extras/ide-devfs.sh +++ b/extras/ide-devfs.sh @@ -38,7 +38,7 @@ get_dev_number() { if [ -z "$3" ]; then MEDIA=`cat /proc/ide/${1}/media` if [ "${MEDIA}" = "cdrom" ]; then - echo ${1} ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/cd cdroms/cdrom`get_dev_number $1 cdrom` + echo $1 ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/cd cdroms/cdrom`get_dev_number $1 cdrom` elif [ "${MEDIA}" = "disk" ]; then echo $1 ide/host${HOST}/bus${BUS}/target${TARGET}/lun0/disc discs/disc`get_dev_number $1 disk`/disc fi diff --git a/udev.spec b/udev.spec index 9e301deb7c..4056025df8 100644 --- a/udev.spec +++ b/udev.spec @@ -16,6 +16,11 @@ # 1 - debugging enabled %define debug 0 +# if we want to use the LSB version of the init script or the Redhat one +# 0 - use Redhat version: etc/init.d/udev +# 1 - use LSB version: etc/init.d/udev.init.LSB +%define lsb 0 + Summary: A userspace implementation of devfs Name: udev Version: 012_bk @@ -52,6 +57,9 @@ make DESTDIR=$RPM_BUILD_ROOT install \ %if %{dbus} USE_DBUS=true %endif +%if %{lsb} + USE_LSB=true +%endif %post /sbin/chkconfig --add udev @@ -81,6 +89,9 @@ rm -rf $RPM_BUILD_ROOT %attr(0644,root,root) %{_mandir}/man8/udev.8* %changelog +* Mon Jan 05 2004 Rolf Eike Beer +- add defines to choose the init script (Redhat or LSB) + * Tue Dec 16 2003 Robert Love - install the initscript and run chkconfig on it @@ -96,4 +107,3 @@ rm -rf $RPM_BUILD_ROOT * Mon Jul 28 2003 Paul Mundt - Initial spec file for udev-0.2. -