[arch-projects] [initscripts] [PATCH 00/11] A new rag rug roll
* Clean up positions of hooks the way suggested by Tom Note: I eliminated the reason for the fsck_all exception in fbsplash-extras by simply duplicating the stat_busy message text. * Some more cleanup * Two nice and fresh tweaks for kill_everything * Finally the old two of three again Kurt J. Bosch (11): functions/rc.single: Clean up whitespace functions: Clean up positions of hooks relative to status functions: Use status in mount_all() functions: Get rid of superfluous braces in udevd_modprobe() functions/rc.sysinit: Use $1 for determining hooks in fsck_all/mount_all functions/rc.multi: Strip paths from binaries functions: Simplify ck_autostart() by refactoring using in_array() functions: Add stop_all_daemons() and related *_prestopdaemons hook functions: Speed up reboot/shutdown by recognizing killall5 exit code 2 Add install_file() for readability functions: Simplify LC_* unsetting functions | 137 ++++++++++++++++++++++++++++++++++++----------------------- rc.multi | 2 +- rc.shutdown | 2 +- rc.single | 4 +- rc.sysinit | 15 +++--- 5 files changed, 95 insertions(+), 65 deletions(-)
--- functions | 2 +- rc.single | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/functions b/functions index bcc97c1..f82110d 100644 --- a/functions +++ b/functions @@ -320,7 +320,7 @@ udevd_modprobe() { udevadm settle --timeout=${UDEV_TIMEOUT:-30} run_hook "${1}_udevsettled" - + # in case loading a module changed the display mode calc_columns } diff --git a/rc.single b/rc.single index d630736..d1efd41 100755 --- a/rc.single +++ b/rc.single @@ -12,10 +12,10 @@ run_hook single_start if [[ $PREVLEVEL != N ]]; then kill_everything single - + # start up our mini logger until syslog takes over minilogd - + # Start/trigger UDev, load MODULES and settle UDev udevd_modprobe single fi -- 1.7.1
Genaral scheme is: run_hook pre_foo if [[$WE_WANT_TO_DO_FOO]]]; then stat_busy "Doing foo" if [[$PRECONDITIONS_FOR_FOO_NOT_SATISFIED]]; then stat_fail else ... stat_done fi fi run hook post_foo Suggested-by: Tom Gundersen <teg@jklm.no> --- functions | 38 ++++++++++++++++++++++++-------------- 1 files changed, 24 insertions(+), 14 deletions(-) diff --git a/functions b/functions index f82110d..ba452d8 100644 --- a/functions +++ b/functions @@ -284,9 +284,10 @@ kill_everything() { ck_daemon ${DAEMONS[i]#@} || stop_daemon ${DAEMONS[i]#@} done + run_hook "$1_prekillall" + # Terminate all processes stat_busy "Sending SIGTERM To Processes" - run_hook "$1_prekillall" /sbin/killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null /bin/sleep 5 stat_done @@ -364,18 +365,25 @@ 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 - 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 -r fsckret=$? - (( fsckret <= 1 )) && stat_done || stat_fail + FSCK_OUT=/dev/stdout + FSCK_ERR=/dev/stdout + FSCK_FD= + FORCEFSCK= + [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" + + run_hook sysinit_prefsck + + if [[ -x $(type -P fsck) ]]; then + stat_busy "Checking Filesystems" + fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >|$FSCK_OUT 2>|$FSCK_ERR + local -r fsckret=$? + (( fsckret <= 1 )) && stat_done || stat_fail + else + local -r fsckret=0 + fi + run_hook sysinit_postfsck + return $fsckret } @@ -415,11 +423,13 @@ fsck_reboot() { } mount_all() { + run_hook sysinit_premount + stat_busy "Mounting Local Filesystems" - run_hook sysinit_premount mount -a -t $NETFS -O no_netdev - run_hook sysinit_postmount stat_done + + run_hook sysinit_postmount } bootlogd_stop() { -- 1.7.1
--- functions | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-) diff --git a/functions b/functions index ba452d8..66a8670 100644 --- a/functions +++ b/functions @@ -425,9 +425,8 @@ fsck_reboot() { mount_all() { run_hook sysinit_premount - stat_busy "Mounting Local Filesystems" + status "Mounting Local Filesystems" \ mount -a -t $NETFS -O no_netdev - stat_done run_hook sysinit_postmount } -- 1.7.1
--- functions | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/functions b/functions index 66a8670..853a6ae 100644 --- a/functions +++ b/functions @@ -306,7 +306,7 @@ udevd_modprobe() { # This is used to determine which hooks to run. status "Starting UDev Daemon" udevd --daemon - run_hook "${1}_udevlaunched" + run_hook "$1_udevlaunched" stat_busy "Triggering UDev uevents" udevadm trigger --action=add --type=subsystems @@ -320,7 +320,7 @@ udevd_modprobe() { status "Waiting for UDev uevents to be processed" \ udevadm settle --timeout=${UDEV_TIMEOUT:-30} - run_hook "${1}_udevsettled" + run_hook "$1_udevsettled" # in case loading a module changed the display mode calc_columns -- 1.7.1
We can't assume to be called from sysinit because we actually introduced the functions for customization. So just do it the same way as in kill_everything() and udevd_modprobe(). --- functions | 13 +++++++++---- rc.sysinit | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/functions b/functions index 853a6ae..96df7d0 100644 --- a/functions +++ b/functions @@ -365,13 +365,15 @@ NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuse # Check local filesystems fsck_all() { + # $1 = where we are being called from. + # This is used to determine which hooks to run. FSCK_OUT=/dev/stdout FSCK_ERR=/dev/stdout FSCK_FD= FORCEFSCK= [[ -f /forcefsck ]] || in_array forcefsck $(< /proc/cmdline) && FORCEFSCK="-- -f" - run_hook sysinit_prefsck + run_hook "$1_prefsck" if [[ -x $(type -P fsck) ]]; then stat_busy "Checking Filesystems" @@ -382,7 +384,7 @@ fsck_all() { local -r fsckret=0 fi - run_hook sysinit_postfsck + run_hook "$1_postfsck" return $fsckret } @@ -423,12 +425,15 @@ fsck_reboot() { } mount_all() { - run_hook sysinit_premount + # $1 = where we are being called from. + # This is used to determine which hooks to run. + + run_hook "$1_premount" status "Mounting Local Filesystems" \ mount -a -t $NETFS -O no_netdev - run_hook sysinit_postmount + run_hook "$1_postmount" } bootlogd_stop() { diff --git a/rc.sysinit b/rc.sysinit index 7b086fa..b6612ff 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -174,7 +174,7 @@ if [[ -f /etc/crypttab && $CS ]] && grep -q ^[^#] /etc/crypttab; then fi # Check filesystems -fsck_all +fsck_all sysinit # Single-user login and/or automatic reboot if needed fsck_reboot $? @@ -193,7 +193,7 @@ if [[ ! -L /etc/mtab ]]; then fi # now mount all the local filesystems -mount_all +mount_all sysinit # enable monitoring of lvm2 groups, now that the filesystems are mounted rw [[ $USELVM = [Yy][Ee][Ss] && -x $(type -P lvm) && -d /sys/block ]] && -- 1.7.1
Now that we set PATH in functions, we can use is everywhere. --- functions | 42 +++++++++++++++++++++--------------------- rc.multi | 2 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/functions b/functions index 96df7d0..11f8317 100644 --- a/functions +++ b/functions @@ -20,12 +20,12 @@ calc_columns () { USECOLOR="" elif [[ -t 0 ]]; then # stty will fail when stdin isn't a terminal - STAT_COL="$(/bin/stty size)" + STAT_COL="$(stty size)" # stty gives "rows cols"; strip the rows number, we just want columns STAT_COL="${STAT_COL##* }" - elif /bin/tput cols &>/dev/null; then + elif tput cols &>/dev/null; then # is /usr/share/terminfo already mounted, and TERM recognized? - STAT_COL=$(/bin/tput cols) + STAT_COL=$(tput cols) fi if (( STAT_COL == 0 )); then # if output was 0 (serial console), set default width to 80 @@ -50,7 +50,7 @@ calc_columns () { calc_columns # disable colors on broken terminals -TERM_COLORS="$(/bin/tput colors 2>/dev/null)" +TERM_COLORS="$(tput colors 2>/dev/null)" if (( $? != 3 )); then case $TERM_COLORS in *[!0-9]*) USECOLOR="";; @@ -75,17 +75,17 @@ fi # set colors if [[ $USECOLOR = [yY][eE][sS] ]]; then - if /bin/tput setaf 0 &>/dev/null; then + if tput setaf 0 &>/dev/null; then C_CLEAR="$(tput sgr0)" # clear text - C_MAIN="${C_CLEAR}$(/bin/tput bold)" # main text - C_OTHER="${C_MAIN}$(/bin/tput setaf 4)" # prefix & brackets - C_SEPARATOR="${C_MAIN}$(/bin/tput setaf 0)" # separator - C_BUSY="${C_CLEAR}$(/bin/tput setaf 6)" # busy - C_FAIL="${C_MAIN}$(/bin/tput setaf 1)" # failed + C_MAIN="${C_CLEAR}$(tput bold)" # main text + C_OTHER="${C_MAIN}$(tput setaf 4)" # prefix & brackets + C_SEPARATOR="${C_MAIN}$(tput setaf 0)" # separator + C_BUSY="${C_CLEAR}$(tput setaf 6)" # busy + C_FAIL="${C_MAIN}$(tput setaf 1)" # failed C_DONE="${C_MAIN}" # completed - C_BKGD="${C_MAIN}$(/bin/tput setaf 5)" # backgrounded + C_BKGD="${C_MAIN}$(tput setaf 5)" # backgrounded C_H1="${C_MAIN}" # highlight text 1 - C_H2="${C_MAIN}$(/bin/tput setaf 6)" # highlight text 2 + C_H2="${C_MAIN}$(tput setaf 6)" # highlight text 2 else C_CLEAR="\e[m" # clear text C_MAIN="\e[;1m" # main text @@ -179,12 +179,12 @@ in_array() { # daemons: add_daemon() { - [[ -d /run/daemons ]] || /bin/mkdir -p /run/daemons + [[ -d /run/daemons ]] || mkdir -p /run/daemons >| /run/daemons/"$1" } rm_daemon() { - /bin/rm -f /run/daemons/"$1" + rm -f /run/daemons/"$1" } ck_daemon() { @@ -288,13 +288,13 @@ kill_everything() { # Terminate all processes stat_busy "Sending SIGTERM To Processes" - /sbin/killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null - /bin/sleep 5 + killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null + sleep 5 stat_done stat_busy "Sending SIGKILL To Processes" - /sbin/killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null - /bin/sleep 1 + killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null + sleep 1 stat_done run_hook "$1_postkillall" @@ -330,8 +330,8 @@ activate_vgs() { [[ $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 - /sbin/vgchange --sysinit -a y >/dev/null + modprobe -q dm-mod 2>/dev/null + vgchange --sysinit -a y >/dev/null (( $? == 0 )) && stat_done || stat_fail } @@ -510,7 +510,7 @@ set_consolefont() { [[ $CONSOLEMAP && ${LOCALE,,} =~ utf ]] && CONSOLEMAP="" local i for i in /dev/tty[0-9]*; do - /usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ + setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ $CONSOLEFONT -C ${i} &>/dev/null done if (( $? )); then diff --git a/rc.multi b/rc.multi index b801fb6..16fa83a 100755 --- a/rc.multi +++ b/rc.multi @@ -9,7 +9,7 @@ run_hook multi_start # Load sysctl variables if sysctl.conf is present -[[ -r /etc/sysctl.conf ]] && /sbin/sysctl -q -p &>/dev/null +[[ -r /etc/sysctl.conf ]] && sysctl -q -p &>/dev/null # Start daemons for daemon in "${DAEMONS[@]}"; do -- 1.7.1
--- functions | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-) diff --git a/functions b/functions index 11f8317..a8ef211 100644 --- a/functions +++ b/functions @@ -198,11 +198,7 @@ have_daemon() { # Check if $1 is started at boot ck_autostart() { - local d - for d in "${DAEMONS[@]}"; do - [[ "$1" = ${d#@} ]] && return 1 - done - return 0 + in_array "$1" "${DAEMONS[@]}" && return 1 || return 0 } start_daemon() { -- 1.7.1
On Sat, Jul 02, 2011 at 08:44:25PM +0200, Kurt J. Bosch wrote:
--- functions | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-)
diff --git a/functions b/functions index 11f8317..a8ef211 100644 --- a/functions +++ b/functions @@ -198,11 +198,7 @@ have_daemon() {
# Check if $1 is started at boot ck_autostart() { - local d - for d in "${DAEMONS[@]}"; do - [[ "$1" = ${d#@} ]] && return 1 - done - return 0 + in_array "$1" "${DAEMONS[@]}" && return 1 || return 0
This isn't the same. You've completely ignored any daemon started in the background. You could naively trim the DAEMONS list: in_array "$1" "${DAEMONS[@]#@}" The return isn't necessary -- its implicitly provided by the return of in_array. dave
}
start_daemon() { -- 1.7.1
Dave Reisner, 2011-07-02 21:09:
On Sat, Jul 02, 2011 at 08:44:25PM +0200, Kurt J. Bosch wrote:
--- functions | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-)
diff --git a/functions b/functions index 11f8317..a8ef211 100644 --- a/functions +++ b/functions @@ -198,11 +198,7 @@ have_daemon() {
# Check if $1 is started at boot ck_autostart() { - local d - for d in "${DAEMONS[@]}"; do - [[ "$1" = ${d#@} ]]&& return 1 - done - return 0 + in_array "$1" "${DAEMONS[@]}"&& return 1 || return 0
This isn't the same. You've completely ignored any daemon started in the background. You could naively trim the DAEMONS list:
in_array "$1" "${DAEMONS[@]#@}"
The return isn't necessary -- its implicitly provided by the return of in_array.
dave
NACK http://projects.archlinux.org/initscripts.git/tree/functions#n167
}
start_daemon() { -- 1.7.1
-- Kurt
This allows splash systems etc. to get a list of daemons to be stopped by simply overriding stop_daemon(). --- functions | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-) diff --git a/functions b/functions index a8ef211..69f06eb 100644 --- a/functions +++ b/functions @@ -261,10 +261,10 @@ add_omit_pids() { omit_pids+=( $@ ) } - -kill_everything() { - # $1 = where we are being called from. - # This is used to determine which hooks to run. +# Stop all daemons +# This function should *never* ever perform any other actions beside calling stop_daemon()! +# It might be used by a splash system etc. to count or get a list of daemons to be stopped. +stop_all_daemons() { # Find daemons NOT in the DAEMONS array. Shut these down first local daemon for daemon in /run/daemons/*; do @@ -279,6 +279,15 @@ kill_everything() { [[ ${DAEMONS[i]} = '!'* ]] && continue ck_daemon ${DAEMONS[i]#@} || stop_daemon ${DAEMONS[i]#@} done +} + +kill_everything() { + # $1 = where we are being called from. + # This is used to determine which hooks to run. + + run_hook "$1_prestopdaemons" + + stop_all_daemons run_hook "$1_prekillall" -- 1.7.1
killall5 returns 2 if it didn't kill any processes. Using this avoids sleeping longer than needed. This saves another up to six seconds of reboot/shutdown/go-single time. --- functions | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-) diff --git a/functions b/functions index 69f06eb..401e323 100644 --- a/functions +++ b/functions @@ -293,13 +293,21 @@ kill_everything() { # Terminate all processes stat_busy "Sending SIGTERM To Processes" - killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null - sleep 5 + local i + for (( i=0; i<500; i+=25 )); do + killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null + (( $? == 2 )) && break + sleep .25 + done stat_done stat_busy "Sending SIGKILL To Processes" - killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null - sleep 1 + local i + for (( i=0; i<100; i+=25 )); do + killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null + (( $? == 2 )) && break + sleep .25 + done stat_done run_hook "$1_postkillall" -- 1.7.1
On Sat, Jul 02, 2011 at 08:44:27PM +0200, Kurt J. Bosch wrote:
killall5 returns 2 if it didn't kill any processes. Using this avoids sleeping longer than needed. This saves another up to six seconds of reboot/shutdown/go-single time. --- functions | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/functions b/functions index 69f06eb..401e323 100644 --- a/functions +++ b/functions @@ -293,13 +293,21 @@ kill_everything() {
# Terminate all processes stat_busy "Sending SIGTERM To Processes" - killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null - sleep 5 + local i + for (( i=0; i<500; i+=25 )); do + killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null + (( $? == 2 )) && break + sleep .25 + done
In the context of killall5, 'killed' means a signal was sent. This will cause a zombie process to hang shutdown for 2 minutes.
stat_done
stat_busy "Sending SIGKILL To Processes" - killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null - sleep 1 + local i + for (( i=0; i<100; i+=25 )); do + killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null + (( $? == 2 )) && break + sleep .25 + done
Ideally, this never kills anything, because all our processes exited nicely in the loop above. However, if it does successfully send a signal to a process, then we just spent the past 125 seconds waiting on the above SIGTERM spam to time out. When it does time out, we're going to spend another 25 seconds here waiting for the same process to be spammed with SIGKILL.
stat_done
run_hook "$1_postkillall" -- 1.7.1
There's probably a handful of programs who don't appreciate receiving SIGTERM every 1/4 of a second. dave
Dave Reisner, 2011-07-02 21:05:
On Sat, Jul 02, 2011 at 08:44:27PM +0200, Kurt J. Bosch wrote:
killall5 returns 2 if it didn't kill any processes. Using this avoids sleeping longer than needed. This saves another up to six seconds of reboot/shutdown/go-single time. --- functions | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/functions b/functions index 69f06eb..401e323 100644 --- a/functions +++ b/functions @@ -293,13 +293,21 @@ kill_everything() {
# Terminate all processes stat_busy "Sending SIGTERM To Processes" - killall5 -15 ${omit_pids[@]/#/-o }&>/dev/null - sleep 5 + local i + for (( i=0; i<500; i+=25 )); do + killall5 -15 ${omit_pids[@]/#/-o }&>/dev/null + (( $? == 2 ))&& break + sleep .25 + done
In the context of killall5, 'killed' means a signal was sent. This will cause a zombie process to hang shutdown for 2 minutes.
Sorry, but i can't see how sending multiple SIGTERM to a zombie should cause any problem. Why 2 minutes? Could you please explain this a bit more?
stat_done
stat_busy "Sending SIGKILL To Processes" - killall5 -9 ${omit_pids[@]/#/-o }&>/dev/null - sleep 1 + local i + for (( i=0; i<100; i+=25 )); do + killall5 -9 ${omit_pids[@]/#/-o }&>/dev/null + (( $? == 2 ))&& break + sleep .25 + done
Ideally, this never kills anything, because all our processes exited nicely in the loop above. However, if it does successfully send a signal to a process, then we just spent the past 125 seconds waiting on the above SIGTERM spam to time out. When it does time out, we're going to spend another 25 seconds here waiting for the same process to be spammed with SIGKILL.
We would spend up to 5 seconds for waiting above - not more as without the patch, but maybe less. Here we spend up to 1 second as before. Note: Time is measured in centiseconds here.
stat_done
run_hook "$1_postkillall" -- 1.7.1
There's probably a handful of programs who don't appreciate receiving SIGTERM every 1/4 of a second.
dave
Works good here. Would you recommend some longer interval? -- Kurt
On Sat, Jul 02, 2011 at 09:56:34PM +0200, Kurt J. Bosch wrote:
Dave Reisner, 2011-07-02 21:05:
On Sat, Jul 02, 2011 at 08:44:27PM +0200, Kurt J. Bosch wrote:
killall5 returns 2 if it didn't kill any processes. Using this avoids sleeping longer than needed. This saves another up to six seconds of reboot/shutdown/go-single time. --- functions | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/functions b/functions index 69f06eb..401e323 100644 --- a/functions +++ b/functions @@ -293,13 +293,21 @@ kill_everything() {
# Terminate all processes stat_busy "Sending SIGTERM To Processes" - killall5 -15 ${omit_pids[@]/#/-o }&>/dev/null - sleep 5 + local i + for (( i=0; i<500; i+=25 )); do + killall5 -15 ${omit_pids[@]/#/-o }&>/dev/null + (( $? == 2 ))&& break + sleep .25 + done
In the context of killall5, 'killed' means a signal was sent. This will cause a zombie process to hang shutdown for 2 minutes.
Sorry, but i can't see how sending multiple SIGTERM to a zombie should cause any problem. Why 2 minutes? Could you please explain this a bit more?
A zombie will receive signals but will never act on them. Therefore, killall5 will never give you the exit value of 2 that is needed to break this loop early. See note below about centiseconds...
stat_done
stat_busy "Sending SIGKILL To Processes" - killall5 -9 ${omit_pids[@]/#/-o }&>/dev/null - sleep 1 + local i + for (( i=0; i<100; i+=25 )); do + killall5 -9 ${omit_pids[@]/#/-o }&>/dev/null + (( $? == 2 ))&& break + sleep .25 + done
Ideally, this never kills anything, because all our processes exited nicely in the loop above. However, if it does successfully send a signal to a process, then we just spent the past 125 seconds waiting on the above SIGTERM spam to time out. When it does time out, we're going to spend another 25 seconds here waiting for the same process to be spammed with SIGKILL.
We would spend up to 5 seconds for waiting above - not more as without the patch, but maybe less. Here we spend up to 1 second as before. Note: Time is measured in centiseconds here.
I failed to notice the i+=25 bit. But why? ((i=0; i<4; i++)) or even {1..4} is much more readable and accomplishes the same. Barring that, a comment would be nice here for those skimming the code.
stat_done
run_hook "$1_postkillall" -- 1.7.1
There's probably a handful of programs who don't appreciate receiving SIGTERM every 1/4 of a second.
dave
Works good here. Would you recommend some longer interval?
Spamming signals until you get a magical return value seems like a hack solution. It's not that I disagree with the interval so much as I disagree with the approach. dave
killall5 returns 2 if it didn't find any processes to send to. Using this avoids sleeping longer than needed. This saves another up to six seconds of reboot/shutdown/go-single time. --- functions | 17 +++++++++++++++-- 1 files changed, 15 insertions(+), 2 deletions(-) diff --git a/functions b/functions index 69f06eb..067d61d 100644 --- a/functions +++ b/functions @@ -292,14 +292,27 @@ kill_everything() { run_hook "$1_prekillall" # Terminate all processes + # and wait until timeout or killall5 reports all done + # Unfortunately killall5 does not support the 0 signal, so just + # use SIGCONT for checking (which should be ignored). stat_busy "Sending SIGTERM To Processes" killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null - sleep 5 + local i + for (( i=0; i<20; i++ )); do + killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null + (( $? == 2 )) && break + sleep .25 # 1/4 second + done stat_done stat_busy "Sending SIGKILL To Processes" killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null - sleep 1 + local i + for (( i=0; i<4; i++ )); do + killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null + (( $? == 2 )) && break + sleep .25 # 1/4 second + done stat_done run_hook "$1_postkillall" -- 1.7.1
On Sat, Jul 02, 2011 at 11:49:29PM +0200, Kurt J. Bosch wrote:
killall5 returns 2 if it didn't find any processes to send to. Using this avoids sleeping longer than needed. This saves another up to six seconds of reboot/shutdown/go-single time. --- functions | 17 +++++++++++++++-- 1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/functions b/functions index 69f06eb..067d61d 100644 --- a/functions +++ b/functions @@ -292,14 +292,27 @@ kill_everything() { run_hook "$1_prekillall"
# Terminate all processes + # and wait until timeout or killall5 reports all done + # Unfortunately killall5 does not support the 0 signal, so just + # use SIGCONT for checking (which should be ignored). stat_busy "Sending SIGTERM To Processes" killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null - sleep 5 + local i + for (( i=0; i<20; i++ )); do + killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null + (( $? == 2 )) && break + sleep .25 # 1/4 second + done stat_done
stat_busy "Sending SIGKILL To Processes" killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null - sleep 1 + local i + for (( i=0; i<4; i++ )); do + killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null + (( $? == 2 )) && break + sleep .25 # 1/4 second + done stat_done
run_hook "$1_postkillall" -- 1.7.1
Not at all what I meant about the comment. I'll leave the decision on this one up to Tom. dave
killall5 returns 2 if it didn't find any processes to send to. Using this avoids sleeping longer than needed. This saves another up to six seconds of reboot/shutdown/go-single time. --- functions | 15 +++++++++++++-- 1 files changed, 13 insertions(+), 2 deletions(-) diff --git a/functions b/functions index 69f06eb..86f466e 100644 --- a/functions +++ b/functions @@ -292,14 +292,25 @@ kill_everything() { run_hook "$1_prekillall" # Terminate all processes + # and wait until timeout or killall5 reports all done + # Unfortunately killall5 does not support the 0 signal, so just + # use SIGCONT for checking (which should be ignored). stat_busy "Sending SIGTERM To Processes" + local i killall5 -15 ${omit_pids[@]/#/-o } &>/dev/null - sleep 5 + for (( i=0; i<20 && $?!=2; i++ )); do + sleep .25 # 1/4 second + killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null + done stat_done stat_busy "Sending SIGKILL To Processes" + local i killall5 -9 ${omit_pids[@]/#/-o } &>/dev/null - sleep 1 + for (( i=0; i<4 && $?!=2; i++ )); do + sleep .25 # 1/4 second + killall5 -18 ${omit_pids[@]/#/-o } &>/dev/null + done stat_done run_hook "$1_postkillall" -- 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 401e323..8d303e8 100644 --- a/functions +++ b/functions @@ -449,6 +449,12 @@ mount_all() { run_hook "$1_postmount" } +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 b6612ff..fcca765 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
Kurt J. Bosch, 2011-07-02 20:44:
--- functions | 6 ++++++ rc.shutdown | 2 +- rc.sysinit | 11 +++++------ 3 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/functions b/functions index 401e323..8d303e8 100644 --- a/functions +++ b/functions @@ -449,6 +449,12 @@ mount_all() { run_hook "$1_postmount" }
+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 b6612ff..fcca765 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
Dropped this from my git tree for now. -- Kurt
--- functions | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/functions b/functions index 8d303e8..1985170 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
On Sat, Jul 2, 2011 at 8:44 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 8d303e8..1985170 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
Still no. Do you will send this patch until it will be accepted ? -- Sébastien Luttringer www.seblu.net
Seblu, 2011-07-03 19:42:
On Sat, Jul 2, 2011 at 8:44 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 8d303e8..1985170 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
Still no. Do you will send this patch until it will be accepted ?
Sorry for spamming you. I just intended to make Toms live a bit easier who wanted to review the remaining old patches when back, but this one is about cosmetics anyway. (Do we have any girls here?) -- Kurt
status() did stdout/stderr redirection to /dev/null when calling the given command since the very beginning (commit fd8fde03). This is not as flexible and intuitive as it could be. It is much better to do redirection when calling when/where ever wanted. --- functions | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-) diff --git a/functions b/functions index 38d7054..440ed31 100644 --- a/functions +++ b/functions @@ -153,14 +153,17 @@ stat_die() { exit ${1:-1} } +# Avoid stolen messages if status() is called with stdout redirection +exec {RC_FUNCTIONS_STDOUT_FD}>&1 + status() { - stat_busy "$1" + stat_busy "$1" >&${RC_FUNCTIONS_STDOUT_FD} shift - if "$@" &>/dev/null; then - stat_done + if "$@"; then + stat_done >&${RC_FUNCTIONS_STDOUT_FD} return 0 fi - stat_fail + stat_fail >&${RC_FUNCTIONS_STDOUT_FD} return 1 } -- 1.7.1
--- rc.sysinit | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index b6612ff..078daf3 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -224,14 +224,14 @@ stat_busy "Removing Leftover Files" stat_done if [[ $HOSTNAME ]]; then - stat_busy "Setting Hostname: $HOSTNAME" - echo "$HOSTNAME" >| /proc/sys/kernel/hostname && stat_done || stat_fail + status "Setting Hostname: $HOSTNAME" \ + echo "$HOSTNAME" >| /proc/sys/kernel/hostname 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}" \ + echo "export LANG=$LOCALE" > /etc/profile.d/locale.sh +chmod 0755 /etc/profile.d/locale.sh if [[ ${LOCALE,,} =~ utf ]]; then stat_busy "Setting Consoles to UTF-8 mode" -- 1.7.1
participants (3)
-
Dave Reisner
-
Kurt J. Bosch
-
Seblu