Systemd/etc/init.d/udev.init.lfs
tao@kernel.org b9e3301c3b [PATCH] Minor POSIX-fixes for udev
The attached patch contains a few patches against udev, to remove
use of various XSI:isms and bash:isms, and to change two scripts form
/bin/bash to /bin/sh.  None of the bash-scripts in test/ uses any
bash-specific functions as far as I know, but I didn't touch them since
they aren't used runtime.

Rationale:
* Both of the /bin/bash-scripts are totally free from bashisms, hence they
  don't need to be /bin/bash; using /bin/sh instead helps (mainly)
  embedded-people

* local and source are bash:isms (well, they exist in several other
  shells as well, but they aren't part of POSIX or any of its extensions)

* -a in tests is an XSI-extension, not part of strict POSIX, and is
  easily replaced by &&
  | http://www.opengroup.org/onlinepubs/009695399/utilities/test.html

* Use of fgrep is deprecated in POSIX in favour of grep -F (though fgrep
  will remain in use for a long time...)
  | http://www.opengroup.org/onlinepubs/009695399/utilities/grep.html

The fgrep-change isn't really necessary, since fgrep can always be
implemented as a shell-script, but the rest of the changes would really
be appreciated.
2005-04-26 21:36:59 -07:00

96 lines
1.7 KiB
Bash

#!/bin/sh
#
# LinuxFromScratch udev init script
# derived from original RedHat udev init script
# 2003, 2004 by Michael Buesch <mbuesch@freenet.de>
#
. /etc/sysconfig/rc
. $rc_functions
. /etc/udev/udev.conf
sysfs_dir="/sys"
bin="/sbin/udev"
run_udev ()
{
# handle block devices and their partitions
for i in ${sysfs_dir}/block/*; do
# add each drive
export DEVPATH=${i#${sysfs_dir}}
$bin block &
# add each partition, on each device
for j in $i/*; do
if [ -f $j/dev ]; then
export DEVPATH=${j#${sysfs_dir}}
$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-`
$bin $CLASS &
fi
done
done
return 0
}
case "$1" in
start)
echo "Creating initial udev device nodes ..."
if [ ! -d $sysfs_dir ]; then
echo "sysfs_dir $sysfs_dir does not exist!"
print_status failure
exit 1
fi
if [ ! -d $udev_root ]; then
mkdir $udev_root
if [ $? -ne 0 ]; then
print_status failure
exit 1
fi
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
export ACTION=add
run_udev
evaluate_retval
;;
stop)
echo "Removing udev device nodes ..."
export ACTION=remove
run_udev
evaluate_retval
;;
reload)
# nothing to do here
;;
restart)
$0 stop
sleep 1
$0 start
;;
status)
if [ -d $udev_dir ]; then
echo "the udev device node directory exists"
else
echo "the udev device node directory does not exist"
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0