[arch-projects] [initscripts] [PATCH 0/2] Merge duplicated/similar code into functions
This should finally make rc.single as clean as posible. Kurt J. Bosch (2): rc.sysinit/rc.single: Merge UDev stuff into a function rc.multi/rc.single: Merge duplicated bootlogd stop code into a function functions | 36 ++++++++++++++++++++++++++++++++++++ rc.multi | 8 +------- rc.single | 27 ++++----------------------- rc.sysinit | 23 ++--------------------- 4 files changed, 43 insertions(+), 51 deletions(-)
rc.single changes (when coming from multi-user): * avoid settling UDev quietly as in rc.sysinit * modules defined in rc.conf are loaded if missing * minilogd is started before udevd as in rc.sysinit rc.sysinit behaviour is unchanged --- functions | 27 +++++++++++++++++++++++++++ rc.single | 19 +++---------------- rc.sysinit | 23 ++--------------------- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/functions b/functions index 4e184f6..0c34cb9 100644 --- a/functions +++ b/functions @@ -301,6 +301,33 @@ kill_everything() { run_hook "$1_postkillall" } +# Start/trigger UDev, load MODULES and settle UDev +udevd_modprobe() { + # $1 = where we are being called from. + # This is used to determine which hooks to run. + status "Starting UDev Daemon" udevd --daemon + + run_hook "${1}_udevlaunched" + + stat_busy "Triggering UDev uevents" + udevadm trigger --action=add --type=subsystems + udevadm trigger --action=add --type=devices + stat_done + + # Load modules from the MODULES array defined in rc.conf + if [[ -f /proc/modules ]] && (( ${#MODULES[*]} )); then + status "Loading Modules" modprobe -ab "${MODULES[@]}" + fi + + status "Waiting for UDev uevents to be processed" \ + udevadm settle --timeout=${UDEV_TIMEOUT:-30} + + run_hook "${1}_udevsettled" + + # in case loading a module changed the display mode + calc_columns +} + activate_vgs() { [[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return # Kernel 2.6.x, LVM2 groups diff --git a/rc.single b/rc.single index 74368fd..46b502c 100755 --- a/rc.single +++ b/rc.single @@ -13,24 +13,11 @@ run_hook single_start if [[ $PREVLEVEL != N ]]; then kill_everything single - status "Starting UDev Daemon" udevd --daemon - - run_hook single_udevlaunched - - # Trigger udev uevents - stat_busy "Triggering UDev uevents" - udevadm trigger --action=add --type=subsystems - udevadm trigger --action=add --type=devices - stat_done - - # Wait for udev uevents - status "Waiting for UDev uevents to be processed" \ - udevadm settle --quiet --timeout=${UDEV_TIMEOUT:-30} - - run_hook single_udevsettled - # start up our mini logger until syslog takes over minilogd + + # Start/trigger UDev, load MODULES and settle UDev + udevd_modprobe single fi run_hook single_end diff --git a/rc.sysinit b/rc.sysinit index 52d9d4b..0d99aa3 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -71,27 +71,8 @@ if [[ $HWCLOCK_PARAMS ]]; then fi fi -status "Starting UDev Daemon" udevd --daemon - -run_hook sysinit_udevlaunched - -stat_busy "Triggering UDev uevents" - udevadm trigger --action=add --type=subsystems - udevadm trigger --action=add --type=devices -stat_done - -# Load modules from the MODULES array defined in rc.conf -if [[ -f /proc/modules ]] && (( ${#MODULES[*]} )); then - status "Loading Modules" modprobe -ab "${MODULES[@]}" -fi - -status "Waiting for UDev uevents to be processed" \ - udevadm settle --timeout=${UDEV_TIMEOUT:-30} - -# in case loading a module changed the display mode -calc_columns - -run_hook sysinit_udevsettled +# Start/trigger UDev, load MODULES and settle UDev +udevd_modprobe sysinit # bring up the loopback interface [[ -d /sys/class/net/lo ]] && -- 1.7.1
--- functions | 9 +++++++++ rc.multi | 8 +------- rc.single | 8 +------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/functions b/functions index 0c34cb9..b64f78b 100644 --- a/functions +++ b/functions @@ -430,6 +430,15 @@ mount_all() { stat_done } +bootlogd_stop() { + [[ -f /run/bootlogd.pid ]] || return 0 + touch /var/log/boot + kill $(< /run/bootlogd.pid) + rm -f /run/bootlogd.pid + sed -i -r -e 's/\^\[\[[0-9]?;?[0-9]?[0-9]?;?[0-9]?[0-9]?[ms]//g' \ + -e 's/\^\[(\[151|%)G//g' /var/log/boot +} + ############################### # Custom hooks in initscripts # ############################### diff --git a/rc.multi b/rc.multi index 1160ab4..4b55a27 100755 --- a/rc.multi +++ b/rc.multi @@ -26,12 +26,6 @@ fi run_hook multi_end -if [[ -f /run/bootlogd.pid ]]; then - touch /var/log/boot - kill $(< /run/bootlogd.pid) - rm -f /run/bootlogd.pid - sed -i -r -e 's/\^\[\[[0-9]?;?[0-9]?[0-9]?;?[0-9]?[0-9]?[ms]//g' \ - -e 's/\^\[(\[151|%)G//g' /var/log/boot -fi +bootlogd_stop # vim: set ts=2 sw=2 noet: diff --git a/rc.single b/rc.single index 46b502c..d630736 100755 --- a/rc.single +++ b/rc.single @@ -22,13 +22,7 @@ fi run_hook single_end -if [[ -f /run/bootlogd.pid ]]; then - touch /var/log/boot - kill $(< /run/bootlogd.pid) - rm -f /run/bootlogd.pid - sed -i -r -e 's/\^\[\[[0-9]?;?[0-9]?[0-9]?;?[0-9]?[0-9]?[ms]//g' \ - -e 's/\^\[(\[151|%)G//g' /var/log/boot -fi +bootlogd_stop if [[ $RUNLEVEL = 1 ]]; then printsep -- 1.7.1
As those in the other thread, these can now be pulled from: https://github.com/kujub/initscripts
On Fri, Jun 24, 2011 at 6:10 PM, Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> wrote:
As those in the other thread, these can now be pulled from:
Thanks!
participants (2)
-
Kurt J. Bosch
-
Tom Gundersen