[arch-projects] [initscripts] [PATCH 00/18] Remaining patches rebased
Kurt J. Bosch (18): Add/simplify some comments Fix whitespace mtab, dmesg: show status crypt, lvm: move stat_busy to the top for consistency functions: fix indentation fsck_all, kill_everything: Clean up pre/post hook pairs run_hook positions ck_depends, ck_pidfile, do_unlock, kill_everything: add missing local statements Simplify ck_depends() for statement Move check on executable fsck into fsck_all() for consistency activate_vgs: return 0 if noop for consistency Get rid of simple if-constucts by using '&&' and '||' Simplify kill_everything() omit_pid handling Simplify LC_* unsetting Consequently Use '>|' when redirecting to files fsck_all: Define $fsckret local variable read-only because exposed to hook rc.sysinit: Fix writing to /dev/urandom by using cp Move export PATH into functions Introduce install_file() and write_file() for better readability functions | 120 ++++++++++++++++++++++++++++++---------------------------- rc.shutdown | 6 +-- rc.sysinit | 88 ++++++++++++++++++++----------------------- 3 files changed, 104 insertions(+), 110 deletions(-)
--- functions | 4 +++- rc.sysinit | 3 +++ 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/functions b/functions index b64f78b..6666acf 100644 --- a/functions +++ b/functions @@ -368,6 +368,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 @@ -387,6 +388,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' @@ -496,7 +498,7 @@ if (( RC_FUNCTIONS_HOOK_FUNCS_DEFINED != 1 )); then declare -r RC_FUNCTIONS_HOOK_FUNCS_DEFINED=1 fi -# Function for setting console font if required +# Set console font set_consolefont() { [[ $CONSOLEFONT ]] || return 0 stat_busy "Loading Console Font: $CONSOLEFONT" diff --git a/rc.sysinit b/rc.sysinit index a2c775f..50a8faf 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
--- 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 50a8faf..c665787 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 @@ -273,9 +273,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
--- rc.sysinit | 28 ++++++++++++++++------------ 1 files changed, 16 insertions(+), 12 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index c665787..0d94177 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -197,12 +197,14 @@ 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 + 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 @@ -271,12 +273,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
On Mon, Jun 27, 2011 at 07:11:09PM +0200, Kurt J. Bosch wrote:
--- rc.sysinit | 28 ++++++++++++++++------------ 1 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index c665787..0d94177 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -197,12 +197,14 @@ 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 + 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
There's nothing in the above hunk that has anything to do with the commit message.
# now mount all the local filesystems @@ -271,12 +273,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
Dave Reisner, 2011-06-27 19:47:
On Mon, Jun 27, 2011 at 07:11:09PM +0200, Kurt J. Bosch wrote:
--- rc.sysinit | 28 ++++++++++++++++------------ 1 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index c665787..0d94177 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -197,12 +197,14 @@ 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 + 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
There's nothing in the above hunk that has anything to do with the commit message.
So what commit message would you prefer for this then?
# now mount all the local filesystems @@ -271,12 +273,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
-- Kurt
--- rc.sysinit | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index c665787..2596fc1 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -197,12 +197,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 | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 2596fc1..0d94177 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -198,11 +198,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 + 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 @@ -271,12 +273,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
--- functions | 2 +- rc.sysinit | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/functions b/functions index 6666acf..61cf3dd 100644 --- a/functions +++ b/functions @@ -330,9 +330,9 @@ udevd_modprobe() { activate_vgs() { [[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return + stat_busy "Activating LVM2 groups" # 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 diff --git a/rc.sysinit b/rc.sysinit index 0d94177..fe7b58e 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -95,8 +95,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 | 56 ++++++++++++++++++++++++++++---------------------------- 1 files changed, 28 insertions(+), 28 deletions(-) diff --git a/functions b/functions index 61cf3dd..dcf6887 100644 --- a/functions +++ b/functions @@ -285,17 +285,17 @@ 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 + 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" @@ -331,8 +331,8 @@ udevd_modprobe() { activate_vgs() { [[ $USELVM = [yY][eE][sS] && -x $(type -P lvm) && -d /sys/block ]] || return stat_busy "Activating LVM2 groups" - # Kernel 2.6.x, LVM2 groups - /sbin/modprobe -q dm-mod 2>/dev/null + # Kernel 2.6.x, LVM2 groups + /sbin/modprobe -q dm-mod 2>/dev/null if /sbin/vgchange --sysinit -a y >/dev/null; then stat_done else @@ -371,14 +371,14 @@ NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuse # Check local filesystems 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 @@ -426,9 +426,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 } @@ -502,13 +502,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
Make all pairs of run_hook *_{pre,post}* surround the object they refer to in their name which are 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 dcf6887..cdb048a 100644 --- a/functions +++ b/functions @@ -283,8 +283,9 @@ kill_everything() { done # Terminate all processes - stat_busy "Sending SIGTERM To Processes" run_hook "$1_prekillall" + + stat_busy "Sending SIGTERM To Processes" local pid k5args="" for pid in ${omit_pids[@]}; do k5args+=" -o $pid" @@ -379,12 +380,12 @@ fsck_all() { run_hook sysinit_prefsck fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR local fsckret=$? + run_hook sysinit_postfsck if (( fsckret > 1 )); then stat_fail else stat_done fi - run_hook sysinit_postfsck return $fsckret } -- 1.7.1
--- functions | 4 ++++ rc.sysinit | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/functions b/functions index cdb048a..0776ae4 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 deamon 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 fe7b58e..d674e72 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -138,12 +138,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
On Mon, Jun 27, 2011 at 07:11:13PM +0200, Kurt J. Bosch wrote:
--- functions | 4 ++++ rc.sysinit | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/functions b/functions index cdb048a..0776ae4 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 deamon
typo here.
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 fe7b58e..d674e72 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -138,12 +138,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 | 4 ++++ rc.sysinit | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/functions b/functions index cdb048a..24ff5cb 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 fe7b58e..d674e72 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -138,12 +138,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 0776ae4..5ea732e 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
--- functions | 1 + rc.sysinit | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/functions b/functions index 5ea732e..e879d30 100644 --- a/functions +++ b/functions @@ -375,6 +375,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 d674e72..d51e88b 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -186,12 +186,10 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then fi 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 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/functions b/functions index e879d30..e30fcf0 100644 --- a/functions +++ b/functions @@ -334,7 +334,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 stat_busy "Activating LVM2 groups" # Kernel 2.6.x, LVM2 groups /sbin/modprobe -q dm-mod 2>/dev/null -- 1.7.1
--- functions | 27 +++++++-------------------- rc.sysinit | 18 ++++-------------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/functions b/functions index e30fcf0..d3da4e1 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 @@ -320,9 +316,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} @@ -338,11 +333,8 @@ activate_vgs() { stat_busy "Activating LVM2 groups" # Kernel 2.6.x, LVM2 groups /sbin/modprobe -q dm-mod 2>/dev/null - 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 @@ -386,11 +378,7 @@ fsck_all() { fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR local fsckret=$? run_hook sysinit_postfsck - if (( fsckret > 1 )); then - stat_fail - else - stat_done - fi + (( fsckret <= 1 )) && stat_done || stat_fail return $fsckret } @@ -398,9 +386,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 d51e88b..ee16c23 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 # Check filesystems -- 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 d3da4e1..88a7822 100644 --- a/functions +++ b/functions @@ -286,16 +286,12 @@ kill_everything() { run_hook "$1_prekillall" stat_busy "Sending SIGTERM To Processes" - 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 | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/functions b/functions index 88a7822..d24df8c 100644 --- a/functions +++ b/functions @@ -62,9 +62,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
On Mon, Jun 27, 2011 at 7:11 PM, Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> wrote:
--- functions | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/functions b/functions index 88a7822..d24df8c 100644 --- a/functions +++ b/functions @@ -62,9 +62,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
still against. -- Sébastien Luttringer www.seblu.net
This avoids errors if one should set the noclobber shell option somewhere (whithin a daemon script or some custom function). We already had this, but it seems gone lost mostly. --- functions | 4 ++-- rc.sysinit | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/functions b/functions index d24df8c..b3d2be4 100644 --- a/functions +++ b/functions @@ -176,7 +176,7 @@ in_array() { add_daemon() { [[ -d /run/daemons ]] || /bin/mkdir -p /run/daemons - > /run/daemons/"$1" + >| /run/daemons/"$1" } rm_daemon() { @@ -369,7 +369,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=$? run_hook sysinit_postfsck (( fsckret <= 1 )) && stat_done || stat_fail diff --git a/rc.sysinit b/rc.sysinit index ee16c23..adf276f 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -228,7 +228,7 @@ stat_done [[ $HOSTNAME ]] && status "Setting Hostname: $HOSTNAME" \ - eval 'echo "$HOSTNAME" > /proc/sys/kernel/hostname' + eval 'echo "$HOSTNAME" >| /proc/sys/kernel/hostname' # Flush old locale settings and set user defined locale status "Setting Locale: ${LOCALE:=en_US}" \ @@ -243,7 +243,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" @@ -252,7 +252,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 | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/functions b/functions index b3d2be4..186d703 100644 --- a/functions +++ b/functions @@ -370,7 +370,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=$? run_hook sysinit_postfsck (( fsckret <= 1 )) && stat_done || stat_fail return $fsckret -- 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 adf276f..ae0b5d3 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -212,7 +212,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
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 186d703..4c028df 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 ae0b5d3..1559652 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
These functions allow us to avoid: * the "Redirection to File not Working because of noclobber Pitfall" (tm) * the "Redirecting a Null-String only when using status() Pitfall" (tm) * the "Process Substitution File Descriptor lost in status() because of Custom stat_busy() Pitfall" (tm) * the "eval Word Splitting Pitfall" (tm) * the "eval Extra Quoting Ugliness" (tm) --- functions | 13 +++++++++++++ rc.shutdown | 2 +- rc.sysinit | 10 +++++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/functions b/functions index 4c028df..4d58064 100644 --- a/functions +++ b/functions @@ -421,6 +421,19 @@ 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" +} + +# install would fail because files can't be removed from /proc +# moreover we don't want to remove nodes from /dev +write_file() { + local file=$1 content=$2 + 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 1559652..cb19c91 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -218,18 +218,18 @@ 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 [[ $HOSTNAME ]] && status "Setting Hostname: $HOSTNAME" \ - eval 'echo "$HOSTNAME" >| /proc/sys/kernel/hostname' + write_file /proc/sys/kernel/hostname "$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 + 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" @@ -261,9 +261,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
These functions allow us to avoid: * the "Redirection to File not Working because of noclobber Pitfall" (tm) * the "Redirecting a Null-String only when using status() Pitfall" (tm) * the "Process Substitution File Descriptor lost in status() because of Custom stat_busy() Pitfall" (tm) * the "eval Word Splitting Pitfall" (tm) * the "eval Extra Quoting Ugliness" (tm) --- functions | 6 ++++++ rc.shutdown | 2 +- rc.sysinit | 8 ++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/functions b/functions index c61b5a2..949d1b0 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 1559652..889a0b9 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,7 +229,7 @@ stat_done # 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 + 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" @@ -261,9 +261,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
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. install_file() allows us to avoid this without using ugly eval. --- functions | 6 ++++++ rc.shutdown | 2 +- rc.sysinit | 8 ++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/functions b/functions index c61b5a2..949d1b0 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 1559652..889a0b9 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,7 +229,7 @@ stat_done # 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 + 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" @@ -261,9 +261,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
Just fixed the commit message. -- Kurt
--- rc.sysinit | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 889a0b9..3051684 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -223,9 +223,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 status "Setting Locale: ${LOCALE:=en_US}" \ -- 1.7.1
Fixed this on request from Seblu. -- Kurt
participants (3)
-
Dave Reisner
-
Kurt J. Bosch
-
Seblu