[arch-projects] [initscripts] [PATCH 00/21] Remaining patches rebaised (again)
Did some reordering/spitting to move the most important and trivial fixes in front. Also rewrote most commit messages. Actually this is my second git rebase ever. Hopefully this one is a bit better then the first. Kurt J. Bosch (21): Fix whitespace functions: Fix indentation rc.sysinit: Fix writing to /dev/urandom rc.sysinit: Fix setting locale Fix '>|' not used allways when redirecting to files Fix local statements missing in ck_depends, ck_pidfile, do_unlock, kill_everything fuctions: Define $fsckret read-only because exposed to hook Add some comments functions: Simplify ck_depends() for statement functions: Simplify kill_everything() omit_pid handling Refactor to get rid of simple if-constucts rc.sysinit: Get rid of eval Move fsck executable check into fsck_all() for consistency Move activate_vgs and crypt stat_busy to the top for consistency functions: Make activate_vgs return 0 if noop for consistency Move export PATH into functions rc.sysinit: Refactor /etc/mtab symlink detection to avoid empty if clause rc.sysinit: Add status output for mtab and dmesg.log creation functions: Clean up positions of run_hook *_{pre,post}* where in pairs functions: Simplify LC_* unsetting Add install_file() for readability functions | 109 ++++++++++++++++++++++++++++------------------------------ rc.shutdown | 6 +-- rc.sysinit | 93 +++++++++++++++++++++++--------------------------- 3 files changed, 98 insertions(+), 110 deletions(-)
--- rc.shutdown | 2 +- rc.sysinit | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rc.shutdown b/rc.shutdown index 9eb0b31..6d43229 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -58,7 +58,7 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then stat_busy "Deactivating encrypted volumes:" # Maybe someone has LVM on an encrypted block device # executing an extra vgchange is errorless - [[ $USELVM = [Yy][Ee][Ss] ]] && vgchange --sysinit -a n &>/dev/null + [[ $USELVM = [Yy][Ee][Ss] ]] && vgchange --sysinit -a n &>/dev/null do_lock() { stat_append "${1}.." if $CS remove "$1" &>/dev/null; then diff --git a/rc.sysinit b/rc.sysinit index a2c775f..864d2c7 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -65,8 +65,8 @@ if [[ $HWCLOCK_PARAMS ]]; then # 2. Filesystem checks can depend on system time # 3. This also sets the kernel time zone, used by e.g. vfat # If TIMEZONE is not set in rc.conf, the timezone stored in /etc/localtime - # is used. If HARDWARECLOCK is not set in rc.conf, the value in - # /var/lib/hwclock/adjfile is used (in this case /var can not be a separate + # is used. If HARDWARECLOCK is not set in rc.conf, the value in + # /var/lib/hwclock/adjfile is used (in this case /var can not be a separate # partition). if TZ=$TIMEZONE hwclock $HWCLOCK_PARAMS; then stat_done @@ -270,9 +270,9 @@ set_consolefont if [[ -e /proc/sys/kernel/dmesg_restrict ]] && (( $(< /proc/sys/kernel/dmesg_restrict) == 1 )); then - install -Tm 0600 <( dmesg ) /var/log/dmesg.log + install -Tm 0600 <( dmesg ) /var/log/dmesg.log else - install -Tm 0644 <( dmesg ) /var/log/dmesg.log + install -Tm 0644 <( dmesg ) /var/log/dmesg.log fi run_hook sysinit_end -- 1.7.1
--- functions | 54 +++++++++++++++++++++++++++--------------------------- 1 files changed, 27 insertions(+), 27 deletions(-) diff --git a/functions b/functions index b64f78b..ef014e3 100644 --- a/functions +++ b/functions @@ -284,18 +284,18 @@ kill_everything() { # Terminate all processes stat_busy "Sending SIGTERM To Processes" - run_hook "$1_prekillall" - local pid k5args="" - for pid in ${omit_pids[@]}; do - k5args+=" -o $pid" - done - /sbin/killall5 -15 $k5args &>/dev/null - /bin/sleep 5 + run_hook "$1_prekillall" + local pid k5args="" + for pid in ${omit_pids[@]}; do + k5args+=" -o $pid" + done + /sbin/killall5 -15 $k5args &>/dev/null + /bin/sleep 5 stat_done stat_busy "Sending SIGKILL To Processes" - /sbin/killall5 -9 $k5args &>/dev/null - /bin/sleep 1 + /sbin/killall5 -9 $k5args &>/dev/null + /bin/sleep 1 stat_done run_hook "$1_postkillall" @@ -370,14 +370,14 @@ NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuse fsck_all() { stat_busy "Checking Filesystems" - FSCK_OUT=/dev/stdout - FSCK_ERR=/dev/stdout - FSCK_FD= - FORCEFSCK= - [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" - run_hook sysinit_prefsck - fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR - local fsckret=$? + FSCK_OUT=/dev/stdout + FSCK_ERR=/dev/stdout + FSCK_FD= + FORCEFSCK= + [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" + run_hook sysinit_prefsck + fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR + local fsckret=$? if (( fsckret > 1 )); then stat_fail else @@ -424,9 +424,9 @@ fsck_reboot() { mount_all() { stat_busy "Mounting Local Filesystems" - run_hook sysinit_premount - mount -a -t $NETFS -O no_netdev - run_hook sysinit_postmount + run_hook sysinit_premount + mount -a -t $NETFS -O no_netdev + run_hook sysinit_postmount stat_done } @@ -500,13 +500,13 @@ fi set_consolefont() { [[ $CONSOLEFONT ]] || return 0 stat_busy "Loading Console Font: $CONSOLEFONT" - #CONSOLEMAP in UTF-8 shouldn't be used - [[ $CONSOLEMAP && ${LOCALE,,} =~ utf ]] && CONSOLEMAP="" - local i - for i in /dev/tty[0-9]*; do - /usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ - $CONSOLEFONT -C ${i} &>/dev/null - done + #CONSOLEMAP in UTF-8 shouldn't be used + [[ $CONSOLEMAP && ${LOCALE,,} =~ utf ]] && CONSOLEMAP="" + local i + for i in /dev/tty[0-9]*; do + /usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ + $CONSOLEFONT -C ${i} &>/dev/null + done if (( $? )); then stat_fail elif [[ $CONSOLEMAP ]]; then -- 1.7.1
Note: The code status "$text" $command > $file writes nothing because there's a &>/dev/null within status(). --- rc.sysinit | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 864d2c7..fca8b43 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -219,7 +219,7 @@ status "Activating Swap" swapon -a RANDOM_SEED=/var/lib/misc/random-seed [[ -f $RANDOM_SEED ]] && status "Initializing Random Seed" \ - cat $RANDOM_SEED > /dev/urandom + cp $RANDOM_SEED /dev/urandom stat_busy "Removing Leftover Files" rm -rf /etc/{nologin,shutdownpid} /forcefsck /tmp/* /tmp/.* &>/dev/null -- 1.7.1
When using process substitution with status(), the resulting /dev/fd/* might get lost before it is actualy used. This happens in case a custom stat_busy() forks a subshell. --- rc.sysinit | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index fca8b43..a63da9b 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -238,8 +238,9 @@ stat_done eval 'echo "$HOSTNAME" > /proc/sys/kernel/hostname' # Flush old locale settings and set user defined locale -status "Setting Locale: ${LOCALE:=en_US}" \ - install -Tm 0755 <(echo "export LANG=$LOCALE") /etc/profile.d/locale.sh +stat_busy "Setting Locale: ${LOCALE:=en_US}" + echo "export LANG=$LOCALE" > /etc/profile.d/locale.sh && + chmod 0755 /etc/profile.d/locale.sh && stat_done || stat_fail if [[ ${LOCALE,,} =~ utf ]]; then stat_busy "Setting Consoles to UTF-8 mode" -- 1.7.1
This avoids errors if one should set the noclobber shell option somewhere (within a daemon script or some custom function). We already had this, but it seems gone lost mostly. --- functions | 4 ++-- rc.sysinit | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/functions b/functions index ef014e3..c6416d9 100644 --- a/functions +++ b/functions @@ -178,7 +178,7 @@ in_array() { add_daemon() { [[ -d /run/daemons ]] || /bin/mkdir -p /run/daemons - > /run/daemons/"$1" + >| /run/daemons/"$1" } rm_daemon() { @@ -376,7 +376,7 @@ fsck_all() { FORCEFSCK= [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" run_hook sysinit_prefsck - fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR + fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR local fsckret=$? if (( fsckret > 1 )); then stat_fail diff --git a/rc.sysinit b/rc.sysinit index a63da9b..f415895 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -251,7 +251,7 @@ if [[ ${LOCALE,,} =~ utf ]]; then kbd_mode -u < ${i} printf "\e%%G" > ${i} done - echo 1 > /sys/module/vt/parameters/default_utf8 + echo 1 >| /sys/module/vt/parameters/default_utf8 stat_done else stat_busy "Setting Consoles to legacy mode" @@ -260,7 +260,7 @@ else kbd_mode -a < ${i} printf "\e%%@" > ${i} done - echo 0 > /sys/module/vt/parameters/default_utf8 + echo 0 >| /sys/module/vt/parameters/default_utf8 stat_done fi [[ $KEYMAP ]] && -- 1.7.1
--- functions | 4 ++++ rc.sysinit | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/functions b/functions index c6416d9..6e4fc3a 100644 --- a/functions +++ b/functions @@ -210,6 +210,7 @@ start_daemon() { # Never use this function, it causes daemons to be stoped in the wrong order. # The only way to start a daemon at boot is to add it to the DAEMONS array. ck_depends() { + local daemon for daemon in "$@"; do ck_daemon "$daemon" && start_daemon "$daemon" done @@ -251,6 +252,7 @@ get_pid() { # Check if PID-file $1 is still the active PID-file for command $2 ck_pidfile() { if [[ -f "$1" ]]; then + local fpid ppid read -r fpid <"$1" ppid=$(get_pid $2) [[ "$fpid" = "$ppid" ]] && return 0 @@ -270,6 +272,7 @@ kill_everything() { # $1 = where we are being called from. # This is used to determine which hooks to run. # Find daemons NOT in the DAEMONS array. Shut these down first + local daemon for daemon in /run/daemons/*; do [[ -f $daemon ]] || continue daemon=${daemon##*/} @@ -277,6 +280,7 @@ kill_everything() { done # Shutdown daemons in reverse order + local i for (( i=${#DAEMONS[@]}-1; i>=0; i-- )); do [[ ${DAEMONS[i]} = '!'* ]] && continue ck_daemon ${DAEMONS[i]#@} || stop_daemon ${DAEMONS[i]#@} diff --git a/rc.sysinit b/rc.sysinit index f415895..9f9eb0c 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -137,12 +137,12 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then printf "\nOpening '$1' volume:\n" $CS $4 $open "$a" "$b" < /dev/console;; /dev*) - ckdev=${3%%:*} - cka=${3#*:} - ckb=${cka#*:} - cka=${cka%:*} - ckfile=/dev/ckfile - ckdir=/dev/ckdir + local ckdev=${3%%:*} + local cka=${3#*:} + local ckb=${cka#*:} + local cka=${cka%:*} + local ckfile=/dev/ckfile + local ckdir=/dev/ckdir case ${cka} in *[!0-9]*) # Use a file on the device -- 1.7.1
--- functions | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/functions b/functions index 6e4fc3a..46aebf2 100644 --- a/functions +++ b/functions @@ -381,7 +381,7 @@ fsck_all() { [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" run_hook sysinit_prefsck fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR - local fsckret=$? + local -r fsckret=$? if (( fsckret > 1 )); then stat_fail else -- 1.7.1
--- functions | 2 ++ rc.sysinit | 3 +++ 2 files changed, 5 insertions(+), 0 deletions(-) diff --git a/functions b/functions index 46aebf2..e71ee1f 100644 --- a/functions +++ b/functions @@ -372,6 +372,7 @@ read_crypttab() { NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs,nodavfs" +# Check local filesystems fsck_all() { stat_busy "Checking Filesystems" FSCK_OUT=/dev/stdout @@ -391,6 +392,7 @@ fsck_all() { return $fsckret } +# Single-user login and/or automatic reboot after fsck (if needed) fsck_reboot() { # $1 = exit code returned by fsck # Ignore conditions 'FS errors corrected' and 'Cancelled by the user' diff --git a/rc.sysinit b/rc.sysinit index 9f9eb0c..27e603b 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -90,6 +90,7 @@ udevd_modprobe sysinit [[ $USEBTRFS = [Yy][Ee][Ss] && -x $(type -P btrfs) ]] && status "Activating BTRFS volumes" btrfs device scan +# Activate LVM2 groups if any activate_vgs # Set up non-root encrypted partition mappings @@ -186,7 +187,9 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then fi if [[ -x $(type -P fsck) ]]; then + # Check filesystems fsck_all + # Single-user login and/or automatic reboot if needed fsck_reboot $? fi -- 1.7.1
--- functions | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/functions b/functions index e71ee1f..9d75fbf 100644 --- a/functions +++ b/functions @@ -211,7 +211,7 @@ start_daemon() { # The only way to start a daemon at boot is to add it to the DAEMONS array. ck_depends() { local daemon - for daemon in "$@"; do + for daemon; do ck_daemon "$daemon" && start_daemon "$daemon" done } -- 1.7.1
All credits go to: Dave Reisner <d@falconindy.com> --- functions | 8 ++------ 1 files changed, 2 insertions(+), 6 deletions(-) diff --git a/functions b/functions index 9d75fbf..ec82c6c 100644 --- a/functions +++ b/functions @@ -289,16 +289,12 @@ kill_everything() { # Terminate all processes stat_busy "Sending SIGTERM To Processes" run_hook "$1_prekillall" - local pid k5args="" - for pid in ${omit_pids[@]}; do - k5args+=" -o $pid" - done - /sbin/killall5 -15 $k5args &>/dev/null + /sbin/killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null /bin/sleep 5 stat_done stat_busy "Sending SIGKILL To Processes" - /sbin/killall5 -9 $k5args &>/dev/null + /sbin/killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null /bin/sleep 1 stat_done -- 1.7.1
--- functions | 27 +++++++-------------------- rc.sysinit | 18 ++++-------------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/functions b/functions index ec82c6c..4c4ca0e 100644 --- a/functions +++ b/functions @@ -237,11 +237,7 @@ status_stopped() { } ck_status() { - if ! ck_daemon "$1"; then - status_started - else - status_stopped - fi + ! ck_daemon "$1" && status_started || status_stopped } # Return PID of $1 @@ -315,9 +311,8 @@ udevd_modprobe() { stat_done # Load modules from the MODULES array defined in rc.conf - if [[ -f /proc/modules ]] && (( ${#MODULES[*]} )); then + [[ -f /proc/modules ]] && (( ${#MODULES[*]} )) && status "Loading Modules" modprobe -ab "${MODULES[@]}" - fi status "Waiting for UDev uevents to be processed" \ udevadm settle --timeout=${UDEV_TIMEOUT:-30} @@ -333,11 +328,8 @@ activate_vgs() { # Kernel 2.6.x, LVM2 groups /sbin/modprobe -q dm-mod 2>/dev/null stat_busy "Activating LVM2 groups" - if /sbin/vgchange --sysinit -a y >/dev/null; then - stat_done - else - stat_fail - fi + /sbin/vgchange --sysinit -a y >/dev/null + (( $? == 0 )) && stat_done || stat_fail } # Arch cryptsetup packages traditionally contained the binaries @@ -379,11 +371,7 @@ fsck_all() { run_hook sysinit_prefsck fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR local -r fsckret=$? - if (( fsckret > 1 )); then - stat_fail - else - stat_done - fi + (( fsckret <= 1 )) && stat_done || stat_fail run_hook sysinit_postfsck return $fsckret } @@ -392,9 +380,8 @@ fsck_all() { fsck_reboot() { # $1 = exit code returned by fsck # Ignore conditions 'FS errors corrected' and 'Cancelled by the user' - if (( ($1 | 33) == 33 )); then - return 0 - elif (( $1 & 2 )); then + (( ($1 | 33) == 33 )) && return 0 + if (( $1 & 2 )); then echo echo "********************** REBOOT REQUIRED *********************" echo "* *" diff --git a/rc.sysinit b/rc.sysinit index 27e603b..06b287c 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -68,11 +68,7 @@ if [[ $HWCLOCK_PARAMS ]]; then # is used. If HARDWARECLOCK is not set in rc.conf, the value in # /var/lib/hwclock/adjfile is used (in this case /var can not be a separate # partition). - if TZ=$TIMEZONE hwclock $HWCLOCK_PARAMS; then - stat_done - else - stat_fail - fi + TZ=$TIMEZONE hwclock $HWCLOCK_PARAMS && stat_done || stat_fail fi # Start/trigger UDev, load MODULES and settle UDev @@ -175,15 +171,9 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then return $failed } crypto_unlocked=0 - if read_crypttab do_unlock; then - stat_done - else - stat_fail - fi - if (( crypto_unlocked == 1 )); then - # Maybe someone has LVM on an encrypted block device - activate_vgs - fi + read_crypttab do_unlock && stat_done || stat_fail + # Maybe someone has LVM on an encrypted block device + (( crypto_unlocked == 1 )) && activate_vgs fi if [[ -x $(type -P fsck) ]]; then -- 1.7.1
--- rc.sysinit | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 06b287c..9b2a009 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -226,9 +226,10 @@ stat_busy "Removing Leftover Files" mkdir -m 1777 /tmp/.{X11,ICE}-unix stat_done -[[ $HOSTNAME ]] && - status "Setting Hostname: $HOSTNAME" \ - eval 'echo "$HOSTNAME" > /proc/sys/kernel/hostname' +if [[ $HOSTNAME ]]; then + stat_busy "Setting Hostname: $HOSTNAME" + echo "$HOSTNAME" >| /proc/sys/kernel/hostname && stat_done || stat_fail +fi # Flush old locale settings and set user defined locale stat_busy "Setting Locale: ${LOCALE:=en_US}" -- 1.7.1
--- functions | 1 + rc.sysinit | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/functions b/functions index 4c4ca0e..14b7a7b 100644 --- a/functions +++ b/functions @@ -362,6 +362,7 @@ NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuse # Check local filesystems fsck_all() { + [[ -x $(type -P fsck) ]] || return 0 stat_busy "Checking Filesystems" FSCK_OUT=/dev/stdout FSCK_ERR=/dev/stdout diff --git a/rc.sysinit b/rc.sysinit index 9b2a009..3fe7185 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -176,12 +176,10 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then (( crypto_unlocked == 1 )) && activate_vgs fi -if [[ -x $(type -P fsck) ]]; then - # Check filesystems - fsck_all - # Single-user login and/or automatic reboot if needed - fsck_reboot $? -fi +# Check filesystems +fsck_all +# Single-user login and/or automatic reboot if needed +fsck_reboot $? status "Remounting Root Read/Write" \ mount -n -o remount,rw / -- 1.7.1
--- functions | 2 +- rc.sysinit | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/functions b/functions index 14b7a7b..861fcbe 100644 --- a/functions +++ b/functions @@ -326,8 +326,8 @@ udevd_modprobe() { activate_vgs() { [[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return # Kernel 2.6.x, LVM2 groups - /sbin/modprobe -q dm-mod 2>/dev/null stat_busy "Activating LVM2 groups" + /sbin/modprobe -q dm-mod 2>/dev/null /sbin/vgchange --sysinit -a y >/dev/null (( $? == 0 )) && stat_done || stat_fail } diff --git a/rc.sysinit b/rc.sysinit index 3fe7185..b34d4ad 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -91,8 +91,8 @@ activate_vgs # Set up non-root encrypted partition mappings if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then - modprobe -q dm-crypt 2>/dev/null stat_busy "Unlocking encrypted volumes:" + modprobe -q dm-crypt 2>/dev/null do_unlock() { # $1 = requested name # $2 = source device -- 1.7.1
--- functions | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/functions b/functions index 861fcbe..2eb4f72 100644 --- a/functions +++ b/functions @@ -324,7 +324,7 @@ udevd_modprobe() { } activate_vgs() { - [[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return + [[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return 0 # Kernel 2.6.x, LVM2 groups stat_busy "Activating LVM2 groups" /sbin/modprobe -q dm-mod 2>/dev/null -- 1.7.1
Also sanitze the PATH for rc.single, rc.multi, rc.local and daemons. --- functions | 4 +++- rc.shutdown | 2 -- rc.sysinit | 3 --- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/functions b/functions index 2eb4f72..bcc97c1 100644 --- a/functions +++ b/functions @@ -2,7 +2,8 @@ # initscripts functions # -# width: +# sanitize PATH (will be overridden later when /etc/profile is sourced, but is useful for UDev) +export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" if [[ $1 == "start" ]]; then if [[ $STARTING ]]; then @@ -12,6 +13,7 @@ if [[ $1 == "start" ]]; then fi fi +# width: calc_columns () { STAT_COL=80 if [[ ! -t 1 ]]; then diff --git a/rc.shutdown b/rc.shutdown index 6d43229..fe42797 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -6,8 +6,6 @@ . /etc/rc.conf . /etc/rc.d/functions -export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - run_hook shutdown_start # avoid staircase effect diff --git a/rc.sysinit b/rc.sysinit index b34d4ad..89cbd55 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -13,9 +13,6 @@ printsep run_hook sysinit_start -# export standard PATH (will be overridden later when /etc/profile is sourced, but is useful for UDev) -export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" - # mount /proc, /sys, /run, /dev, /run/lock, /dev/pts, /dev/shm (the api filesystems) mountpoint -q /proc || mount -n -t proc proc /proc -o nosuid,noexec,nodev mountpoint -q /sys || mount -n -t sysfs sys /sys -o nosuid,noexec,nodev -- 1.7.1
--- rc.sysinit | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 89cbd55..7f1089e 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -182,12 +182,12 @@ status "Remounting Root Read/Write" \ mount -n -o remount,rw / # don't touch /etc/mtab if it is a symlink to /proc/self/mounts -if [[ -L /etc/mtab ]]; then - : -elif [[ -x $(type -P findmnt) && -e /proc/self/mountinfo ]]; then - findmnt -rnu -o SOURCE,TARGET,FSTYPE,OPTIONS >| /etc/mtab -else - cat /proc/mounts >| /etc/mtab +if [[ ! -L /etc/mtab ]]; then + if [[ -x $(type -P findmnt) && -e /proc/self/mountinfo ]]; then + findmnt -rnu -o SOURCE,TARGET,FSTYPE,OPTIONS >| /etc/mtab + else + cat /proc/mounts >| /etc/mtab + fi fi # now mount all the local filesystems -- 1.7.1
--- rc.sysinit | 26 +++++++++++++++----------- 1 files changed, 15 insertions(+), 11 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 7f1089e..7b086fa 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -183,11 +183,13 @@ status "Remounting Root Read/Write" \ # don't touch /etc/mtab if it is a symlink to /proc/self/mounts if [[ ! -L /etc/mtab ]]; then - if [[ -x $(type -P findmnt) && -e /proc/self/mountinfo ]]; then - findmnt -rnu -o SOURCE,TARGET,FSTYPE,OPTIONS >| /etc/mtab - else - cat /proc/mounts >| /etc/mtab - fi + stat_busy "Creating mtab" + if [[ -x $(type -P findmnt) && -e /proc/self/mountinfo ]]; then + findmnt -rnu -o SOURCE,TARGET,FSTYPE,OPTIONS >| /etc/mtab + else + cat /proc/mounts >| /etc/mtab + fi + (( $? == 0 )) && stat_done || stat_fail fi # now mount all the local filesystems @@ -258,12 +260,14 @@ fi # Set console font if required set_consolefont -if [[ -e /proc/sys/kernel/dmesg_restrict ]] && - (( $(< /proc/sys/kernel/dmesg_restrict) == 1 )); then - install -Tm 0600 <( dmesg ) /var/log/dmesg.log -else - install -Tm 0644 <( dmesg ) /var/log/dmesg.log -fi +stat_busy "Saving dmesg Log" + if [[ -e /proc/sys/kernel/dmesg_restrict ]] && + (( $(< /proc/sys/kernel/dmesg_restrict) == 1 )); then + install -Tm 0600 <( dmesg ) /var/log/dmesg.log + else + install -Tm 0644 <( dmesg ) /var/log/dmesg.log + fi +(( $? == 0 )) && stat_done || stat_fail run_hook sysinit_end -- 1.7.1
Make all pairs of run_hook *_{pre,post}* surround the object they refer to in their name which is one of: * A series of One or more status blocks performing one specific action. (like killall) * A single command like fsck/mount. Long story: Currently most run_hook calls are located out of any status blocks, but in some cases we need them to be inside. Example: Having the sysinit_prefsck hook _after_ the stat_busy allows us to save the message string before redirecting the fsck progress status into a splash status line and then restore the original message whenever fsck stops to output progress status (which is currently supported for ext[234] only AFAIK). This is actually done in fbsplash-extras (AUR). --- functions | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/functions b/functions index bcc97c1..2b513cc 100644 --- a/functions +++ b/functions @@ -285,8 +285,9 @@ kill_everything() { done # Terminate all processes + run_hook "$1_prekillall" + stat_busy "Sending SIGTERM To Processes" - run_hook "$1_prekillall" /sbin/killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null /bin/sleep 5 stat_done @@ -374,8 +375,8 @@ fsck_all() { run_hook sysinit_prefsck fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR local -r fsckret=$? + run_hook sysinit_postfsck (( fsckret <= 1 )) && stat_done || stat_fail - run_hook sysinit_postfsck return $fsckret } -- 1.7.1
--- functions | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/functions b/functions index 2b513cc..08cee4b 100644 --- a/functions +++ b/functions @@ -64,9 +64,7 @@ unset TERM_COLORS unset TZ # sanitize the locale settins -unset LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY \ - LC_MESSAGES LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE \ - LC_MEASUREMENT LC_IDENTIFICATION LC_ALL +unset "${!LC_@}" if [[ $DAEMON_LOCALE = [yY][eE][sS] && $LOCALE ]]; then export LANG="${LOCALE}" else -- 1.7.1
--- functions | 6 ++++++ rc.shutdown | 2 +- rc.sysinit | 11 +++++------ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/functions b/functions index 08cee4b..438b919 100644 --- a/functions +++ b/functions @@ -421,6 +421,12 @@ mount_all() { stat_done } +install_file() { + local file=$1 content=$2 # remaining args go to install directly + shift 2 + install -T "$@" <(printf '%s' "$content") "$file" +} + bootlogd_stop() { [[ -f /run/bootlogd.pid ]] || return 0 touch /var/log/boot diff --git a/rc.shutdown b/rc.shutdown index fe42797..e658142 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -21,7 +21,7 @@ kill_everything shutdown stat_busy "Saving Random Seed" RANDOM_SEED=/var/lib/misc/random-seed - install -TDm 0600 <(:) $RANDOM_SEED + install_file $RANDOM_SEED "" -m 0600 -D POOL_FILE=/proc/sys/kernel/random/poolsize if [[ -r $POOL_FILE ]]; then read POOL_SIZE < $POOL_FILE diff --git a/rc.sysinit b/rc.sysinit index 7b086fa..d66e0fe 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -218,7 +218,7 @@ stat_busy "Removing Leftover Files" [[ ! -L /var/run && ! -L /var/run/daemons ]] && rm -rf /var/run/daemons && ln -s /run/daemons /var/run/daemons - install -Tm 0664 -o root -g utmp <(:) /var/run/utmp + install_file /var/run/utmp "" -m 0664 -o root -g utmp # Keep {x,k,g}dm happy with xorg mkdir -m 1777 /tmp/.{X11,ICE}-unix stat_done @@ -229,9 +229,8 @@ if [[ $HOSTNAME ]]; then fi # Flush old locale settings and set user defined locale -stat_busy "Setting Locale: ${LOCALE:=en_US}" - echo "export LANG=$LOCALE" > /etc/profile.d/locale.sh && - chmod 0755 /etc/profile.d/locale.sh && stat_done || stat_fail +status "Setting Locale: ${LOCALE:=en_US}" \ + install_file /etc/profile.d/locale.sh "export LANG=$LOCALE"$'\n' -m 0755 if [[ ${LOCALE,,} =~ utf ]]; then stat_busy "Setting Consoles to UTF-8 mode" @@ -263,9 +262,9 @@ set_consolefont stat_busy "Saving dmesg Log" if [[ -e /proc/sys/kernel/dmesg_restrict ]] && (( $(< /proc/sys/kernel/dmesg_restrict) == 1 )); then - install -Tm 0600 <( dmesg ) /var/log/dmesg.log + install_file /var/log/dmesg.log "$( dmesg )" -m 0600 else - install -Tm 0644 <( dmesg ) /var/log/dmesg.log + install_file /var/log/dmesg.log "$( dmesg )" -m 0644 fi (( $? == 0 )) && stat_done || stat_fail -- 1.7.1
On Tue, Jun 28, 2011 at 3:27 PM, Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> wrote:
Did some reordering/spitting to move the most important and trivial fixes in front. Also rewrote most commit messages.
Actually this is my second git rebase ever. Hopefully this one is a bit better then the first.
Thanks for reworking these. They were much easier to review now! I pulled most of them, except the final three. I will have a look at them again next week (just about to go on holiday now). Cheers, Tom
Tom Gundersen, 2011-06-28 17:15:
On Tue, Jun 28, 2011 at 3:27 PM, Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> wrote:
Did some reordering/spitting to move the most important and trivial fixes in front. Also rewrote most commit messages.
Actually this is my second git rebase ever. Hopefully this one is a bit better then the first.
Thanks for reworking these. They were much easier to review now!
I pulled most of them, except the final three. I will have a look at them again next week (just about to go on holiday now).
Cheers,
Tom I wish you very much fun!
-- Kurt
participants (2)
-
Kurt J. Bosch
-
Tom Gundersen