[arch-general] [PATCH 01/48] Bashification of initscripts
Despite efforts to make the initscripts POSIX, we use bash 4.0 features. Bashifying this framework should result in about a 30% speedup, assuming no IO latency and that all programs we call also take zero time. :) --- functions | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/functions b/functions index 672eed2..023de35 100644 --- a/functions +++ b/functions @@ -1,4 +1,4 @@ -# +#!/bin/bash # initscripts functions # -- 1.7.1
--- functions | 30 +++++++++++++----------------- 1 files changed, 13 insertions(+), 17 deletions(-) diff --git a/functions b/functions index 023de35..a9acf6f 100644 --- a/functions +++ b/functions @@ -5,26 +5,21 @@ # width: STAT_COL=80 -if [ ! -t 1 ]; then - USECOLOR="" - -# stty will fail when stdin isn't a terminal -elif [ -t 0 ]; then - STAT_COL="$(/bin/stty size)" - # stty gives "rows cols"; strip the rows number, we just want columns - STAT_COL="${STAT_COL##* }" - -else +if [[ ! -t 1 ]]; then + USECOLOR="" +elif [[ -t 0 ]]; then + # stty will fail when stdin isn't a terminal + STAT_COL="$(/bin/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 # is /usr/share/terminfo already mounted, and TERM recognized? - /bin/tput cols &>/dev/null - if [ $? -eq 0 ]; then STAT_COL=$(/bin/tput cols) - fi fi -if [ "0$STAT_COL" -eq 0 ]; then - # if output was 0 (serial console), set default width to 80 - STAT_COL=80 - USECOLOR="" +if ((STAT_COL==0)); then + # if output was 0 (serial console), set default width to 80 + STAT_COL=80 + USECOLOR="" fi # we use 13 characters for our own stuff @@ -54,6 +49,7 @@ unset TZ # colors: if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then C_MAIN="\033[1;37;40m" # main text + C_OTHER="\033[1;34;40m" # prefix & brackets C_SEPARATOR="\033[1;30;40m" # separator -- 1.7.1
--- functions | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-) diff --git a/functions b/functions index 9b348b7..0acdbbf 100644 --- a/functions +++ b/functions @@ -57,7 +57,7 @@ if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then C_CLEAR="\033[1;0m" fi -if [ -t 1 ]; then +if [[ -t 1 ]]; then SAVE_POSITION="\033[s" RESTORE_POSITION="\033[u" DEL_TEXT="\033[$(($STAT_COL+4))G" @@ -116,10 +116,8 @@ stat_fail() { } stat_die() { - retval=1 - [ "$1" = "" ] || retval=$1 stat_fail - exit $retval + exit ${1:-1} } status() { -- 1.7.1
Nice patch, but ...
-if [ -t 1 ]; then +if [[ -t 1 ]]; then SAVE_POSITION="\033[s" RESTORE_POSITION="\033[u" DEL_TEXT="\033[$(($STAT_COL+4))G" @@ -116,10 +116,8 @@ stat_fail() {
Hmm, this definitely doesn't belong into this patch.
}
stat_die() { - retval=1 - [ "$1" = "" ] || retval=$1 stat_fail - exit $retval + exit ${1:-1} }
status() {
Okay, this is certainly nicer than before.
On Wed, 2010-06-30 at 23:57 +0200, Thomas Bächler wrote:
Nice patch, but ...
-if [ -t 1 ]; then +if [[ -t 1 ]]; then SAVE_POSITION="\033[s" RESTORE_POSITION="\033[u" DEL_TEXT="\033[$(($STAT_COL+4))G" @@ -116,10 +116,8 @@ stat_fail() {
Hmm, this definitely doesn't belong into this patch.
Yeah, I think it got smashed together while I was rebasing things to clean up.
}
stat_die() { - retval=1 - [ "$1" = "" ] || retval=$1 stat_fail - exit $retval + exit ${1:-1} }
status() {
Okay, this is certainly nicer than before.
-- Victor Lowther LPIC2 UCP RHCE
--- functions | 21 +++++++-------------- 1 files changed, 7 insertions(+), 14 deletions(-) diff --git a/functions b/functions index a9acf6f..6df8c5e 100644 --- a/functions +++ b/functions @@ -13,7 +13,7 @@ elif [[ -t 0 ]]; then # stty gives "rows cols"; strip the rows number, we just want columns STAT_COL="${STAT_COL##* }" elif /bin/tput cols &>/dev/null; then - # is /usr/share/terminfo already mounted, and TERM recognized? + # is /usr/share/terminfo already mounted, and TERM recognized? STAT_COL=$(/bin/tput cols) fi if ((STAT_COL==0)); then @@ -27,19 +27,12 @@ STAT_COL=$(($STAT_COL - 13)) # disable colors on broken terminals TERM_COLORS="$(/bin/tput colors 2>/dev/null)" -if [ $? = 3 ]; then - TERM_COLORS=8 -elif [ -n "${TERM_COLORS}" ]; then - case "${TERM_COLORS}" in - *[!0-9]*) - USECOLOR="" - ;; - *) - [ "${TERM_COLORS}" -lt 8 ] && USECOLOR="" - ;; - esac -else - USECOLOR="" +if (($? != 3)); then + case $TERM_COLORS in + *[!0-9]*) USECOLOR="";; + [0-7]) USECOLOR="";; + '') USECOLOR="";; + esac fi unset TERM_COLORS -- 1.7.1
${foo:+-p ${foo}} expands to nothing if foo is not set, -p $foo if foo is set. --- functions | 7 ++----- 1 files changed, 2 insertions(+), 5 deletions(-) diff --git a/functions b/functions index 8aaee68..56c6a7b 100644 --- a/functions +++ b/functions @@ -262,11 +262,8 @@ set_consolefont() { #CONSOLEMAP in UTF-8 shouldn't be used [[ $CONSOLEMAP && $LOCALE =~ UTF|utf ]] && CONSOLEMAP="" for i in /dev/tty[0-9]*; do - if [ -n "$CONSOLEMAP" ]; then - /usr/bin/setfont -m $CONSOLEMAP $CONSOLEFONT -C ${i} >/dev/null 2>&1 - else - /usr/bin/setfont $CONSOLEFONT -C ${i} >/dev/null 2>&1 - fi + /usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ + $CONSOLEFONT -C ${i} >/dev/null 2>&1 done if [ $? -ne 0 ]; then stat_fail -- 1.7.1
Bash has regex support, and it allows us to replace most trivial uses of sed, grep, and awk. The fewer processes we create, the faster we go, and every little bit helps. I also think it is more readable to use a bash regex for the trivial stuff. --- functions | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/functions b/functions index f954737..8aaee68 100644 --- a/functions +++ b/functions @@ -260,9 +260,7 @@ set_consolefont() { [[ $CONSOLEFONT ]] || return 0 stat_busy "Loading Console Font: $CONSOLEFONT" #CONSOLEMAP in UTF-8 shouldn't be used - if [ -n "$CONSOLEMAP" ] && echo "$LOCALE" | /bin/grep -qi utf ; then - CONSOLEMAP="" - fi + [[ $CONSOLEMAP && $LOCALE =~ UTF|utf ]] && CONSOLEMAP="" for i in /dev/tty[0-9]*; do if [ -n "$CONSOLEMAP" ]; then /usr/bin/setfont -m $CONSOLEMAP $CONSOLEFONT -C ${i} >/dev/null 2>&1 -- 1.7.1
It is worth 10 - 30% speedup whenever you want to compare something. --- functions | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/functions b/functions index 6df8c5e..9b348b7 100644 --- a/functions +++ b/functions @@ -40,7 +40,7 @@ unset TERM_COLORS unset TZ # colors: -if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then +if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then C_MAIN="\033[1;37;40m" # main text C_OTHER="\033[1;34;40m" # prefix & brackets -- 1.7.1
Am 30.06.2010 23:47, schrieb Victor Lowther:
It is worth 10 - 30% speedup whenever you want to compare something.
Where do you get this from? I always used [ ], and I found it sufficient. Why is [[ ]] faster?
-if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then +if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then
Why do you get rid of the quoting here? Quoting is nice.
On Wed, Jun 30, 2010 at 17:56, Thomas Bächler <thomas@archlinux.org> wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
It is worth 10 - 30% speedup whenever you want to compare something.
Where do you get this from? I always used [ ], and I found it sufficient. Why is [[ ]] faster?
-if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then +if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then
Why do you get rid of the quoting here? Quoting is nice.
Quoting is not needed in [[ and it makes the code uglier.
2010/7/1 Daenyth Blank <daenyth+arch@gmail.com>:
On Wed, Jun 30, 2010 at 17:56, Thomas Bächler <thomas@archlinux.org> wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
It is worth 10 - 30% speedup whenever you want to compare something.
Where do you get this from? I always used [ ], and I found it sufficient. Why is [[ ]] faster?
-if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then +if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then
Why do you get rid of the quoting here? Quoting is nice.
Quoting is not needed in [[ and it makes the code uglier.
Ditto. May I also suggest a link[1] to those that do not know all the beauties of double square brackets? By the way, the whole BashFAQ in there is really interesting, it has lots of advanced tips 'n tricks. Corrado [1] http://mywiki.wooledge.org/BashFAQ/031
On Thu, 2010-07-01 at 00:24 +0200, bardo wrote:
2010/7/1 Daenyth Blank <daenyth+arch@gmail.com>:
On Wed, Jun 30, 2010 at 17:56, Thomas Bächler <thomas@archlinux.org> wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
It is worth 10 - 30% speedup whenever you want to compare something.
Where do you get this from? I always used [ ], and I found it sufficient. Why is [[ ]] faster?
-if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then +if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then
Why do you get rid of the quoting here? Quoting is nice.
Quoting is not needed in [[ and it makes the code uglier.
Ditto. May I also suggest a link[1] to those that do not know all the beauties of double square brackets? By the way, the whole BashFAQ in there is really interesting, it has lots of advanced tips 'n tricks.
Corrado
greycat and friends are awesome, it is true. I learned alot reading gregs wiki and hanging out on #bash. -- Victor Lowther LPIC2 UCP RHCE
On Wed, 2010-06-30 at 23:56 +0200, Thomas Bächler wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
It is worth 10 - 30% speedup whenever you want to compare something.
Where do you get this from? I always used [ ], and I found it sufficient. Why is [[ ]] faster?
[[ ]] is faster because it is bash syntax, not a builtin command like [ is. In most programs, both are fast enough, but you an see the difference if you run otherwise identical tests in a loop one million times.
-if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then +if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then
Why do you get rid of the quoting here? Quoting is nice.
Because [[ ]] is bash syntax instead if a builtin comand, it relaxes the usual expansion rules -- inside of [[ ]], word splitting and pathname expansion are not performed, so you only have to quote strings if they need to be single-quoted. http://wiki.bash-hackers.org/syntax/ccmd/conditional_expression has more info. -- Victor Lowther LPIC2 UCP RHCE
Am 01.07.2010 00:22, schrieb Victor Lowther:
On Wed, 2010-06-30 at 23:56 +0200, Thomas Bächler wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
It is worth 10 - 30% speedup whenever you want to compare something.
Where do you get this from? I always used [ ], and I found it sufficient. Why is [[ ]] faster?
[[ ]] is faster because it is bash syntax, not a builtin command like [ is. In most programs, both are fast enough, but you an see the difference if you run otherwise identical tests in a loop one million times.
-if [ "$USECOLOR" = "YES" -o "$USECOLOR" = "yes" ]; then +if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then
Why do you get rid of the quoting here? Quoting is nice.
Because [[ ]] is bash syntax instead if a builtin comand, it relaxes the usual expansion rules -- inside of [[ ]], word splitting and pathname expansion are not performed, so you only have to quote strings if they need to be single-quoted. http://wiki.bash-hackers.org/syntax/ccmd/conditional_expression has more info.
Sounds nice. This will probably mean that I will apply all the patches that do this transition - however, it might probably be nicer to squash all of those into one commit.
We do this early so that the entire body of the function is not in an if block. --- functions | 37 ++++++++++++++++++------------------- 1 files changed, 18 insertions(+), 19 deletions(-) diff --git a/functions b/functions index d9f55fa..f954737 100644 --- a/functions +++ b/functions @@ -257,27 +257,26 @@ declare -r add_hook run_hook # Function for setting console font if required set_consolefont() { - if [ -n "$CONSOLEFONT" ]; then - stat_busy "Loading Console Font: $CONSOLEFONT" - #CONSOLEMAP in UTF-8 shouldn't be used - if [ -n "$CONSOLEMAP" ] && echo "$LOCALE" | /bin/grep -qi utf ; then - CONSOLEMAP="" - fi - for i in /dev/tty[0-9]*; do - if [ -n "$CONSOLEMAP" ]; then - /usr/bin/setfont -m $CONSOLEMAP $CONSOLEFONT -C ${i} >/dev/null 2>&1 - else - /usr/bin/setfont $CONSOLEFONT -C ${i} >/dev/null 2>&1 - fi - done - if [ $? -ne 0 ]; then - stat_fail + [[ $CONSOLEFONT ]] || return 0 + stat_busy "Loading Console Font: $CONSOLEFONT" + #CONSOLEMAP in UTF-8 shouldn't be used + if [ -n "$CONSOLEMAP" ] && echo "$LOCALE" | /bin/grep -qi utf ; then + CONSOLEMAP="" + fi + for i in /dev/tty[0-9]*; do + if [ -n "$CONSOLEMAP" ]; then + /usr/bin/setfont -m $CONSOLEMAP $CONSOLEFONT -C ${i} >/dev/null 2>&1 else - if [ -n "$CONSOLEMAP" ]; then - echo 'if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033(K"; fi' >>/etc/profile.d/locale.sh - fi - stat_done + /usr/bin/setfont $CONSOLEFONT -C ${i} >/dev/null 2>&1 + fi + done + if [ $? -ne 0 ]; then + stat_fail + else + if [ -n "$CONSOLEMAP" ]; then + echo 'if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033(K"; fi' >>/etc/profile.d/locale.sh fi + stat_done fi } -- 1.7.1
All that extra checking for the first character being @ is not needed, simple parameter expansion will trim it off if it is there. --- functions | 18 +++++++----------- 1 files changed, 7 insertions(+), 11 deletions(-) diff --git a/functions b/functions index 9d0aec3..8bbdfc6 100644 --- a/functions +++ b/functions @@ -136,17 +136,13 @@ status() { # 1 - not found # Copied from makepkg in_array() { - local needle=$1; shift - [ -z "$1" ] && return 1 # Not Found - local item - for item in "$@"; do - local c="${item:0:1}" - if [ "x$c" = "x@" ]; then - item="${item:1}" - fi - [ "$item" = "$needle" ] && return 0 # Found - done - return 1 # Not Found + [[ $2 ]] || return 1 + local needle=$1; shift + local item + for item in "$@"; do + [[ ${item#@} = $needle ]] && return 0 + done + return 1 # Not Found } # daemons: -- 1.7.1
Go ahead and declare add_hook and run_hook as readonly functions to prevent hooks from overwriting them. Too bad bash does not have lexically scoped variables -- if it does, we could do the same with the hook_funcs associative array. --- functions | 49 ++++++++++++++++++++++++++----------------------- 1 files changed, 26 insertions(+), 23 deletions(-) diff --git a/functions b/functions index 8bbdfc6..d9f55fa 100644 --- a/functions +++ b/functions @@ -148,38 +148,39 @@ in_array() { # daemons: add_daemon() { - [ -d /var/run/daemons ] || /bin/mkdir -p /var/run/daemons - /bin/touch /var/run/daemons/$1 + [[ -d /var/run/daemons ]] || /bin/mkdir -p /var/run/daemons + > /var/run/daemons/"$1" } rm_daemon() { - /bin/rm -f /var/run/daemons/$1 + /bin/rm -f /var/run/daemons/"$1" } ck_daemon() { - [ -f /var/run/daemons/$1 ] && return 1 - return 0 + [[ ! -f /var/run/daemons/$1 ]] } -ck_depends() { - for daemon in $@; do - if ck_daemon $daemon; then - /etc/rc.d/$daemon start - fi - done +have_daemon() { + [[ -x /etc/rc.d/"$1" ]] } start_daemon() { - /etc/rc.d/$1 start + have_daemon "$1" && /etc/rc.d/"$1" start +} + +ck_depends() { + for daemon in "$@"; do + ck_daemon "$daemon" && start_daemon "$daemon" + done } start_daemon_bkgd() { stat_bkgd "Starting $1" - (/etc/rc.d/$1 start) &>/dev/null & + have_daemon "$1" && (start_daemon "$1") &>/dev/null & } stop_daemon() { - /etc/rc.d/$1 stop + have_daemon "$1" && /etc/rc.d/"$1" stop } # Status functions @@ -234,24 +235,26 @@ ck_status() { # single_postkillall: after all processes have been killed in rc.single # shutdown_poweroff: directly before powering off in rc.shutdown # -# Make sure to never override the add_hook and run_hook functions via functions.d +# Declare add_hook and run_hook as read-only to prevent overwriting them. +# Too bad we cannot do the same thing with hook_funcs declare -A hook_funcs add_hook() { - [ -z "$1" -o -z "$2" ] && return 1 - hook_funcs["$1"]="${hook_funcs["$1"]} $2" + [[ $1 && $2 ]] || return 1 + hook_funcs["$1"]+=" $2" } run_hook() { - local func - - [ -z "$1" ] && return 1 - for func in ${hook_funcs["$1"]}; do - ${func} - done + [[ $1 ]] || return 1 + local func + for func in ${hook_funcs["$1"]}; do + "${func}" + done } +declare -r add_hook run_hook + # Function for setting console font if required set_consolefont() { if [ -n "$CONSOLEFONT" ]; then -- 1.7.1
Am 30.06.2010 23:47, schrieb Victor Lowther:
Go ahead and declare add_hook and run_hook as readonly functions to prevent hooks from overwriting them. Too bad bash does not have lexically scoped variables -- if it does, we could do the same with the hook_funcs associative array.
Lots of hunks below that have nothing to do with the actual change made here:
diff --git a/functions b/functions index 8bbdfc6..d9f55fa 100644 --- a/functions +++ b/functions @@ -148,38 +148,39 @@ in_array() { # daemons:
add_daemon() { - [ -d /var/run/daemons ] || /bin/mkdir -p /var/run/daemons - /bin/touch /var/run/daemons/$1 + [[ -d /var/run/daemons ]] || /bin/mkdir -p /var/run/daemons + > /var/run/daemons/"$1" }
rm_daemon() { - /bin/rm -f /var/run/daemons/$1 + /bin/rm -f /var/run/daemons/"$1" }
ck_daemon() { - [ -f /var/run/daemons/$1 ] && return 1 - return 0 + [[ ! -f /var/run/daemons/$1 ]] }
-ck_depends() { - for daemon in $@; do - if ck_daemon $daemon; then - /etc/rc.d/$daemon start - fi - done +have_daemon() { + [[ -x /etc/rc.d/"$1" ]] }
start_daemon() { - /etc/rc.d/$1 start + have_daemon "$1" && /etc/rc.d/"$1" start +} + +ck_depends() { + for daemon in "$@"; do + ck_daemon "$daemon" && start_daemon "$daemon" + done }
start_daemon_bkgd() { stat_bkgd "Starting $1" - (/etc/rc.d/$1 start) &>/dev/null & + have_daemon "$1" && (start_daemon "$1") &>/dev/null & }
stop_daemon() { - /etc/rc.d/$1 stop + have_daemon "$1" && /etc/rc.d/"$1" stop }
Here the actual patch starts, the above doesn't belong into this patch. You should _really_ check out git add -p/-i
# Status functions @@ -234,24 +235,26 @@ ck_status() { # single_postkillall: after all processes have been killed in rc.single # shutdown_poweroff: directly before powering off in rc.shutdown # -# Make sure to never override the add_hook and run_hook functions via functions.d +# Declare add_hook and run_hook as read-only to prevent overwriting them. +# Too bad we cannot do the same thing with hook_funcs
declare -A hook_funcs
add_hook() { - [ -z "$1" -o -z "$2" ] && return 1 - hook_funcs["$1"]="${hook_funcs["$1"]} $2" + [[ $1 && $2 ]] || return 1 + hook_funcs["$1"]+=" $2" }
+= in bash? Really? Didn't know that worked.
run_hook() { - local func - - [ -z "$1" ] && return 1 - for func in ${hook_funcs["$1"]}; do - ${func} - done + [[ $1 ]] || return 1 + local func + for func in ${hook_funcs["$1"]}; do + "${func}" + done }
+declare -r add_hook run_hook +
Nice, I didn't know you could do that.
# Function for setting console font if required set_consolefont() { if [ -n "$CONSOLEFONT" ]; then
On Thu, 2010-07-01 at 00:00 +0200, Thomas Bächler wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
Go ahead and declare add_hook and run_hook as readonly functions to prevent hooks from overwriting them. Too bad bash does not have lexically scoped variables -- if it does, we could do the same with the hook_funcs associative array.
Lots of hunks below that have nothing to do with the actual change made here:
Probably got smashed in. I did alot of git rebase -i to clean things up. Splitting it back out will not be a problem.
diff --git a/functions b/functions index 8bbdfc6..d9f55fa 100644 --- a/functions +++ b/functions @@ -148,38 +148,39 @@ in_array() { # daemons:
add_daemon() { - [ -d /var/run/daemons ] || /bin/mkdir -p /var/run/daemons - /bin/touch /var/run/daemons/$1 + [[ -d /var/run/daemons ]] || /bin/mkdir -p /var/run/daemons + > /var/run/daemons/"$1" }
rm_daemon() { - /bin/rm -f /var/run/daemons/$1 + /bin/rm -f /var/run/daemons/"$1" }
ck_daemon() { - [ -f /var/run/daemons/$1 ] && return 1 - return 0 + [[ ! -f /var/run/daemons/$1 ]] }
-ck_depends() { - for daemon in $@; do - if ck_daemon $daemon; then - /etc/rc.d/$daemon start - fi - done +have_daemon() { + [[ -x /etc/rc.d/"$1" ]] }
start_daemon() { - /etc/rc.d/$1 start + have_daemon "$1" && /etc/rc.d/"$1" start +} + +ck_depends() { + for daemon in "$@"; do + ck_daemon "$daemon" && start_daemon "$daemon" + done }
start_daemon_bkgd() { stat_bkgd "Starting $1" - (/etc/rc.d/$1 start) &>/dev/null & + have_daemon "$1" && (start_daemon "$1") &>/dev/null & }
stop_daemon() { - /etc/rc.d/$1 stop + have_daemon "$1" && /etc/rc.d/"$1" stop }
Here the actual patch starts, the above doesn't belong into this patch. You should _really_ check out git add -p/-i
# Status functions @@ -234,24 +235,26 @@ ck_status() { # single_postkillall: after all processes have been killed in rc.single # shutdown_poweroff: directly before powering off in rc.shutdown # -# Make sure to never override the add_hook and run_hook functions via functions.d +# Declare add_hook and run_hook as read-only to prevent overwriting them. +# Too bad we cannot do the same thing with hook_funcs
declare -A hook_funcs
add_hook() { - [ -z "$1" -o -z "$2" ] && return 1 - hook_funcs["$1"]="${hook_funcs["$1"]} $2" + [[ $1 && $2 ]] || return 1 + hook_funcs["$1"]+=" $2" }
+= in bash? Really? Didn't know that worked.
run_hook() { - local func - - [ -z "$1" ] && return 1 - for func in ${hook_funcs["$1"]}; do - ${func} - done + [[ $1 ]] || return 1 + local func + for func in ${hook_funcs["$1"]}; do + "${func}" + done }
+declare -r add_hook run_hook +
Nice, I didn't know you could do that.
# Function for setting console font if required set_consolefont() { if [ -n "$CONSOLEFONT" ]; then
-- Victor Lowther LPIC2 UCP RHCE
Calling your args with $* will do nasty things if any of your args has a space in it. "$@" will always do The Right Thing. Just test the command directly, don't run it and then grab its exit value. --- functions | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-) diff --git a/functions b/functions index 0acdbbf..9d0aec3 100644 --- a/functions +++ b/functions @@ -123,14 +123,12 @@ stat_die() { status() { stat_busy "$1" shift - $* >/dev/null 2>&1 - if [ $? -eq 0 ]; then + if "$@" >/dev/null 2>&1; then stat_done return 0 - else - stat_fail - return 1 fi + stat_fail + return 1 } # usage : in_array( $needle, $haystack ) -- 1.7.1
Parsing the output of ls is Bad, especially when globbing works just as well and does not get confused by odd characters in filenames. bash has arithemetic for loops. Use them instead of while loops for iterating over arrays. --- rc.single | 29 ++++++++++++----------------- 1 files changed, 12 insertions(+), 17 deletions(-) diff --git a/rc.single b/rc.single index aa58b4c..aa27be0 100755 --- a/rc.single +++ b/rc.single @@ -9,23 +9,18 @@ run_hook single_start if [[ $PREVLEVEL != N ]]; then - - # Find daemons NOT in the DAEMONS array. Shut these down first - if [[ -d /var/run/daemons ]]; then - for daemon in $(/bin/ls -1t /var/run/daemons); do - if ! in_array $daemon ${DAEMONS[@]}; then - stop_daemon $daemon - fi - done - fi - # Shutdown daemons in reverse order - let i=${#DAEMONS[@]}-1 - while ((i >= 0)); do - if [[ ${DAEMONS[$i]:0:1} != '!' ]]; then - ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@} - fi - let i=i-1 - done + # Find daemons NOT in the DAEMONS array. Shut these down first + for daemon in /var/run/daemons/*; do + [[ -f $daemon ]] || continue + daemon=${daemon##*/} + in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon" + done + + # Shutdown daemons in reverse order + for ((i=${#DAEMONS[@]}-1; i>=0; i--)); do + [[ ${DAEMONS[$i]:0:1} = '!' ]] && continue + ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@} + done # Terminate all processes stat_busy "Sending SIGTERM To Processes" -- 1.7.1
--- rc.single | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rc.single b/rc.single index f986a2a..aa58b4c 100755 --- a/rc.single +++ b/rc.single @@ -8,10 +8,10 @@ run_hook single_start -if [ "$PREVLEVEL" != "N" ]; then +if [[ $PREVLEVEL != N ]]; then # Find daemons NOT in the DAEMONS array. Shut these down first - if [ -d /var/run/daemons ]; then + if [[ -d /var/run/daemons ]]; then for daemon in $(/bin/ls -1t /var/run/daemons); do if ! in_array $daemon ${DAEMONS[@]}; then stop_daemon $daemon @@ -20,8 +20,8 @@ if [ "$PREVLEVEL" != "N" ]; then fi # Shutdown daemons in reverse order let i=${#DAEMONS[@]}-1 - while [ $i -ge 0 ]; do - if [ "${DAEMONS[$i]:0:1}" != '!' ]; then + while ((i >= 0)); do + if [[ ${DAEMONS[$i]:0:1} != '!' ]]; then ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@} fi let i=i-1 @@ -66,17 +66,17 @@ if [ "$PREVLEVEL" != "N" ]; then run_hook single_udevsettled # try syslog-NG first, then fall back to good ol' syslogd - if [ -x /etc/rc.d/syslog-ng ]; then + if [[ -x /etc/rc.d/syslog-ng ]]; then /etc/rc.d/syslog-ng start - elif [ -x /etc/rc.d/syslogd ]; then + elif [[ -x /etc/rc.d/syslogd ]]; then /etc/rc.d/syslogd start - [ -x /etc/rc.d/klogd ] && /etc/rc.d/klogd start + [[ -x /etc/rc.d/klogd ]] && /etc/rc.d/klogd start fi fi run_hook single_end -if [ "$RUNLEVEL" = "1" ]; then +if [[ $RUNLEVEL = 1 ]]; then printsep printhl "Entering single-user mode..." # make sure /dev/initctl is in place -- 1.7.1
This is shorter and easier to read. --- rc.multi | 12 +++++------- 1 files changed, 5 insertions(+), 7 deletions(-) diff --git a/rc.multi b/rc.multi index 46c18df..ec6fda6 100755 --- a/rc.multi +++ b/rc.multi @@ -13,13 +13,11 @@ run_hook multi_start # Start daemons for daemon in "${DAEMONS[@]}"; do - if [[ $daemon = ${daemon#!} ]]; then - if [[ $daemon = ${daemon#@} ]]; then - start_daemon $daemon - else - start_daemon_bkgd ${daemon:1} - fi - fi + case ${daemon:0:1} in + '!') continue;; # Skip this daemon. + '@') start_daemon_bkgd ${daemon#@};; + *) start_daemon $daemon;; + esac done if [[ -x /etc/rc.local ]]; then -- 1.7.1
--- rc.multi | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rc.multi b/rc.multi index a7ea703..46c18df 100755 --- a/rc.multi +++ b/rc.multi @@ -9,12 +9,12 @@ 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 ]] && /sbin/sysctl -q -p &>/dev/null # Start daemons for daemon in "${DAEMONS[@]}"; do - if [ "$daemon" = "${daemon#!}" ]; then - if [ "$daemon" = "${daemon#@}" ]; then + if [[ $daemon = ${daemon#!} ]]; then + if [[ $daemon = ${daemon#@} ]]; then start_daemon $daemon else start_daemon_bkgd ${daemon:1} @@ -22,7 +22,7 @@ for daemon in "${DAEMONS[@]}"; do fi done -if [ -x /etc/rc.local ]; then +if [[ -x /etc/rc.local ]]; then /etc/rc.local fi -- 1.7.1
--- functions | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/functions b/functions index 9730150..9c89ea1 100644 --- a/functions +++ b/functions @@ -278,9 +278,7 @@ EOF # Source additional functions at the end to allow overrides for f in /etc/rc.d/functions.d/*; do - if [ -e $f ]; then - . $f - fi + [[ -e $f ]] && . "$f" done # End of file -- 1.7.1
This adds a line, but making things more readable is worth it. --- functions | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-) diff --git a/functions b/functions index 56c6a7b..9730150 100644 --- a/functions +++ b/functions @@ -265,12 +265,13 @@ set_consolefont() { /usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ $CONSOLEFONT -C ${i} >/dev/null 2>&1 done - if [ $? -ne 0 ]; then + if (($? != 0)); then stat_fail - else - if [ -n "$CONSOLEMAP" ]; then - echo 'if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033(K"; fi' >>/etc/profile.d/locale.sh - fi + elif [[ $CONSOLEMAP ]]; then + cat <<"EOF" >>/etc/profile.d/locale.sh +if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033(K"; fi + +EOF stat_done fi } -- 1.7.1
--- functions | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/functions b/functions index 9c89ea1..d8e8e54 100644 --- a/functions +++ b/functions @@ -170,7 +170,7 @@ start_daemon() { ck_depends() { for daemon in "$@"; do - ck_daemon "$daemon" && start_daemon "$daemon" + ck_daemon "$daemon" && start_daemon "$daemon" done } @@ -200,7 +200,7 @@ ck_status() { status_started else status_stopped - fi + fi } ############################### @@ -236,7 +236,7 @@ ck_status() { # shutdown_poweroff: directly before powering off in rc.shutdown # # Declare add_hook and run_hook as read-only to prevent overwriting them. -# Too bad we cannot do the same thing with hook_funcs +# Too bad we cannot do the same thing with hook_funcs declare -A hook_funcs -- 1.7.1
If you introduced whitespace errors (or any errors), fix them in the commits that introduced them, don't do a separate commit fixing them.
On Wed, Jun 30, 2010 at 6:06 PM, Thomas Bächler <thomas@archlinux.org> wrote:
If you introduced whitespace errors (or any errors), fix them in the commits that introduced them, don't do a separate commit fixing them. ++
rebase -i on the remote and flatten squash this patch into the patch the problem was introduced in. -- Caleb Cushing http://xenoterracide.blogspot.com
On Thu, 2010-07-01 at 23:01 -0400, Caleb Cushing wrote:
On Wed, Jun 30, 2010 at 6:06 PM, Thomas Bächler <thomas@archlinux.org> wrote:
If you introduced whitespace errors (or any errors), fix them in the commits that introduced them, don't do a separate commit fixing them. ++
rebase -i on the remote and flatten squash this patch into the patch the problem was introduced in.
/me nods Just waiting for any other things Thomas wants fixed up. -- Victor Lowther LPIC2 UCP RHCE
Move that shared code into functions. --- functions | 29 +++++++++++++++++++++++++++++ rc.shutdown | 32 +------------------------------- rc.single | 27 +-------------------------- 3 files changed, 31 insertions(+), 57 deletions(-) diff --git a/functions b/functions index d8e8e54..bf6ed45 100644 --- a/functions +++ b/functions @@ -203,6 +203,35 @@ ck_status() { fi } +kill_everything() { + # Find daemons NOT in the DAEMONS array. Shut these down first + for daemon in /var/run/daemons/*; do + [[ -f $daemon ]] || continue + daemon=${daemon##*/} + in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon" + done + + # Shutdown daemons in reverse order + for ((i=${#DAEMONS[@]}-1; i>=0; i--)); do + [[ ${DAEMONS[$i]:0:1} = '!' ]] && continue + ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@} + done + + # Terminate all processes + stat_busy "Sending SIGTERM To Processes" + run_hook single_prekillall + /sbin/killall5 -15 &> /dev/null + /bin/sleep 5 + stat_done + + stat_busy "Sending SIGKILL To Processes" + /sbin/killall5 -9 &> /dev/null + /bin/sleep 1 + stat_done + + run_hook single_postkillall +} + ############################### # Custom hooks in initscripts # ############################### diff --git a/rc.shutdown b/rc.shutdown index 002a45d..ef9b16d 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -19,37 +19,7 @@ echo " " [[ -x /bin/domainname ]] && /bin/domainname "" [[ -x /etc/rc.local.shutdown ]] && /etc/rc.local.shutdown - -# Find daemons NOT in the DAEMONS array. Shut these down first -if [ -d /var/run/daemons ]; then - for daemon in $(/bin/ls -1t /var/run/daemons); do - if ! in_array $daemon ${DAEMONS[@]}; then - stop_daemon $daemon - fi - done -fi -# Shutdown daemons in reverse order -let i=${#DAEMONS[@]}-1 -while [ $i -ge 0 ]; do - if [ "${DAEMONS[$i]:0:1}" != '!' ]; then - ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@} - fi - let i=i-1 -done - -# Terminate all processes -stat_busy "Sending SIGTERM To Processes" -run_hook shutdown_prekillall -/sbin/killall5 -15 &> /dev/null -/bin/sleep 5 -stat_done - -stat_busy "Sending SIGKILL To Processes" -/sbin/killall5 -9 &> /dev/null -/bin/sleep 1 -stat_done - -run_hook shutdown_postkillall +kill_everything stat_busy "Saving Random Seed" RANDOM_SEED=/var/lib/misc/random-seed diff --git a/rc.single b/rc.single index aa27be0..a84ece8 100755 --- a/rc.single +++ b/rc.single @@ -9,33 +9,8 @@ run_hook single_start if [[ $PREVLEVEL != N ]]; then - # Find daemons NOT in the DAEMONS array. Shut these down first - for daemon in /var/run/daemons/*; do - [[ -f $daemon ]] || continue - daemon=${daemon##*/} - in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon" - done - - # Shutdown daemons in reverse order - for ((i=${#DAEMONS[@]}-1; i>=0; i--)); do - [[ ${DAEMONS[$i]:0:1} = '!' ]] && continue - ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@} - done - - # Terminate all processes - stat_busy "Sending SIGTERM To Processes" - run_hook single_prekillall - /sbin/killall5 -15 &> /dev/null - /bin/sleep 5 - stat_done - - stat_busy "Sending SIGKILL To Processes" - /sbin/killall5 -9 &> /dev/null - /bin/sleep 1 - stat_done - - run_hook single_postkillall + kill_everything stat_busy "Starting UDev Daemon" /sbin/udevd --daemon stat_done -- 1.7.1
Am 2010-06-30 23:47, schrieb Victor Lowther:
Move that shared code into functions. --- functions | 29 +++++++++++++++++++++++++++++ rc.shutdown | 32 +------------------------------- rc.single | 27 +-------------------------- 3 files changed, 31 insertions(+), 57 deletions(-)
diff --git a/functions b/functions index d8e8e54..bf6ed45 100644 --- a/functions +++ b/functions @@ -203,6 +203,35 @@ ck_status() { fi }
+kill_everything() { + # Find daemons NOT in the DAEMONS array. Shut these down first + for daemon in /var/run/daemons/*; do + [[ -f $daemon ]] || continue + daemon=${daemon##*/} + in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon" + done + + # Shutdown daemons in reverse order + for ((i=${#DAEMONS[@]}-1; i>=0; i--)); do + [[ ${DAEMONS[$i]:0:1} = '!' ]]&& continue + ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@} + done + + # Terminate all processes + stat_busy "Sending SIGTERM To Processes" + run_hook single_prekillall
This line should be run_hook "${0##*/rc.}"_prekillall IMHO
+ /sbin/killall5 -15&> /dev/null + /bin/sleep 5 + stat_done + + stat_busy "Sending SIGKILL To Processes" + /sbin/killall5 -9&> /dev/null + /bin/sleep 1 + stat_done + + run_hook single_postkillall
Similar as above.
+} + ############################### # Custom hooks in initscripts # ############################### diff --git a/rc.shutdown b/rc.shutdown index 002a45d..ef9b16d 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -19,37 +19,7 @@ echo " " [[ -x /bin/domainname ]]&& /bin/domainname "" [[ -x /etc/rc.local.shutdown ]]&& /etc/rc.local.shutdown
- -# Find daemons NOT in the DAEMONS array. Shut these down first -if [ -d /var/run/daemons ]; then - for daemon in $(/bin/ls -1t /var/run/daemons); do - if ! in_array $daemon ${DAEMONS[@]}; then - stop_daemon $daemon - fi - done -fi -# Shutdown daemons in reverse order -let i=${#DAEMONS[@]}-1 -while [ $i -ge 0 ]; do - if [ "${DAEMONS[$i]:0:1}" != '!' ]; then - ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@} - fi - let i=i-1 -done - -# Terminate all processes -stat_busy "Sending SIGTERM To Processes" -run_hook shutdown_prekillall -/sbin/killall5 -15&> /dev/null -/bin/sleep 5 -stat_done - -stat_busy "Sending SIGKILL To Processes" -/sbin/killall5 -9&> /dev/null -/bin/sleep 1 -stat_done - -run_hook shutdown_postkillall +kill_everything
stat_busy "Saving Random Seed" RANDOM_SEED=/var/lib/misc/random-seed diff --git a/rc.single b/rc.single index aa27be0..a84ece8 100755 --- a/rc.single +++ b/rc.single @@ -9,33 +9,8 @@ run_hook single_start
if [[ $PREVLEVEL != N ]]; then - # Find daemons NOT in the DAEMONS array. Shut these down first - for daemon in /var/run/daemons/*; do - [[ -f $daemon ]] || continue - daemon=${daemon##*/} - in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon" - done - - # Shutdown daemons in reverse order - for ((i=${#DAEMONS[@]}-1; i>=0; i--)); do - [[ ${DAEMONS[$i]:0:1} = '!' ]]&& continue - ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@} - done - - # Terminate all processes - stat_busy "Sending SIGTERM To Processes" - run_hook single_prekillall - /sbin/killall5 -15&> /dev/null - /bin/sleep 5 - stat_done - - stat_busy "Sending SIGKILL To Processes" - /sbin/killall5 -9&> /dev/null - /bin/sleep 1 - stat_done - - run_hook single_postkillall
+ kill_everything stat_busy "Starting UDev Daemon" /sbin/udevd --daemon stat_done
First of all, sorry for not continuing the review yesterday, time is short :( Still, I'll finish this, as I'd like to have this applied eventually. Am 02.07.2010 11:21, schrieb Kurt J. Bosch:
Am 2010-06-30 23:47, schrieb Victor Lowther:
Move that shared code into functions. --- functions | 29 +++++++++++++++++++++++++++++ rc.shutdown | 32 +------------------------------- rc.single | 27 +-------------------------- 3 files changed, 31 insertions(+), 57 deletions(-)
diff --git a/functions b/functions index d8e8e54..bf6ed45 100644 --- a/functions +++ b/functions @@ -203,6 +203,35 @@ ck_status() { fi }
+kill_everything() { + # Find daemons NOT in the DAEMONS array. Shut these down first + for daemon in /var/run/daemons/*; do + [[ -f $daemon ]] || continue + daemon=${daemon##*/} + in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon" + done + + # Shutdown daemons in reverse order + for ((i=${#DAEMONS[@]}-1; i>=0; i--)); do + [[ ${DAEMONS[$i]:0:1} = '!' ]]&& continue + ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@} + done + + # Terminate all processes + stat_busy "Sending SIGTERM To Processes" + run_hook single_prekillall
This line should be run_hook "${0##*/rc.}"_prekillall IMHO
Kurt is right here. We call this code from rc.single and rc.shutdown I think. We use two distinct hooks, you can register functions for these hooks independently!
2010-07-02 11:27, Thomas Bächler:
First of all, sorry for not continuing the review yesterday, time is short :(
Still, I'll finish this, as I'd like to have this applied eventually.
Am 02.07.2010 11:21, schrieb Kurt J. Bosch:
Am 2010-06-30 23:47, schrieb Victor Lowther:
Move that shared code into functions. + run_hook single_prekillall
This line should be run_hook "${0##*/rc.}"_prekillall IMHO
Kurt is right here. We call this code from rc.single and rc.shutdown I think. We use two distinct hooks, you can register functions for these hooks independently!
Hmm, git bashification-redux has now: 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 for daemon in /var/run/daemons/*; do [[ -f $daemon ]] || continue daemon=${daemon##*/} in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon" done # Shutdown daemons in reverse order for ((i=${#DAEMONS[@]}-1; i>=0; i--)); do [[ ${DAEMONS[$i]:0:1} = '!' ]] && continue ck_daemon ${DAEMONS[$i]#@} || stop_daemon ${DAEMONS[$i]#@} done # Terminate all processes stat_busy "Sending SIGTERM To Processes" run_hook "$1_prekillall" /sbin/killall5 -15 &> /dev/null /bin/sleep 5 stat_done stat_busy "Sending SIGKILL To Processes" /sbin/killall5 -9 &> /dev/null /bin/sleep 1 stat_done run_hook "$1_postkillall" } I suggest: From b202be97f8dc1c0c68aaea792d4457c674c673f3 Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> Date: Tue, 31 Aug 2010 09:57:47 +0200 Subject: [PATCH 17/17] Correct behaviour of kill_everything() --- functions | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-) diff --git a/functions b/functions index b9ba718..3ca7324 100644 --- a/functions +++ b/functions @@ -205,10 +205,9 @@ ck_status() { 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 - for daemon in /var/run/daemons/*; do - [[ -f $daemon ]] || continue - daemon=${daemon##*/} + # Find daemons NOT in the DAEMONS array. + # Shut these down first in reverse order. + for daemon in $( /bin/ls -t /var/run/daemons ); do in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon" done @@ -220,7 +219,7 @@ kill_everything() { # Terminate all processes stat_busy "Sending SIGTERM To Processes" - run_hook "$1_prekillall" + run_hook "${1}_prekillall" /sbin/killall5 -15 &> /dev/null /bin/sleep 5 stat_done @@ -230,7 +229,7 @@ kill_everything() { /bin/sleep 1 stat_done - run_hook "$1_postkillall" + run_hook "${1}_postkillall" } activate_vgs() { -- 1.7.0.3
On Tue, Aug 31, 2010 at 10:07:52AM +0200, Kurt J. Bosch wrote:
--snip--
I suggest:
From b202be97f8dc1c0c68aaea792d4457c674c673f3 Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> Date: Tue, 31 Aug 2010 09:57:47 +0200 Subject: [PATCH 17/17] Correct behaviour of kill_everything()
--- functions | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/functions b/functions index b9ba718..3ca7324 100644 --- a/functions +++ b/functions @@ -205,10 +205,9 @@ ck_status() { 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 - for daemon in /var/run/daemons/*; do - [[ -f $daemon ]] || continue - daemon=${daemon##*/} + # Find daemons NOT in the DAEMONS array. + # Shut these down first in reverse order. + for daemon in $( /bin/ls -t /var/run/daemons ); do in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon" done
@@ -220,7 +219,7 @@ kill_everything() {
# Terminate all processes stat_busy "Sending SIGTERM To Processes" - run_hook "$1_prekillall" + run_hook "${1}_prekillall" /sbin/killall5 -15 &> /dev/null /bin/sleep 5 stat_done @@ -230,7 +229,7 @@ kill_everything() { /bin/sleep 1 stat_done
- run_hook "$1_postkillall" + run_hook "${1}_postkillall" }
activate_vgs() { -- 1.7.0.3
Parsing the output of ls will never be better than using shell globbing no matter how much simpler it might make the code appear to be. Not only are you avoiding a fork, but the shell glob will properly handle any odd characters thrown into the mix. You'll see breakage on something as simple as a space in your suggestion. While I'm inclined to believe that there will never be a space in the name of a daemon in Arch, if we're going for pure Bash in this rewrite, let's use Bash instead of mindlessly forking. The only useful change here is to remove the line: [[ -f $daemon ]] || continue and instead call 'shopt -s nullglob' outside the loop. Sorry for the no-patch patch. d
2010-08-31 13:16, Dave Reisner:
On Tue, Aug 31, 2010 at 10:07:52AM +0200, Kurt J. Bosch wrote:
--snip--
I suggest:
From b202be97f8dc1c0c68aaea792d4457c674c673f3 Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch<kjb-temp-2009@alpenjodel.de> Date: Tue, 31 Aug 2010 09:57:47 +0200 Subject: [PATCH 17/17] Correct behaviour of kill_everything()
--- functions | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/functions b/functions index b9ba718..3ca7324 100644 --- a/functions +++ b/functions @@ -205,10 +205,9 @@ ck_status() { 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 - for daemon in /var/run/daemons/*; do - [[ -f $daemon ]] || continue - daemon=${daemon##*/} + # Find daemons NOT in the DAEMONS array. + # Shut these down first in reverse order. + for daemon in $( /bin/ls -t /var/run/daemons ); do in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon" done
@@ -220,7 +219,7 @@ kill_everything() {
# Terminate all processes stat_busy "Sending SIGTERM To Processes" - run_hook "$1_prekillall" + run_hook "${1}_prekillall" /sbin/killall5 -15&> /dev/null /bin/sleep 5 stat_done @@ -230,7 +229,7 @@ kill_everything() { /bin/sleep 1 stat_done
- run_hook "$1_postkillall" + run_hook "${1}_postkillall" }
activate_vgs() { -- 1.7.0.3
Parsing the output of ls will never be better than using shell globbing no matter how much simpler it might make the code appear to be. Not only are you avoiding a fork, but the shell glob will properly handle any odd characters thrown into the mix. You'll see breakage on something as simple as a space in your suggestion. While I'm inclined to believe that there will never be a space in the name of a daemon in Arch, if we're going for pure Bash in this rewrite, let's use Bash instead of mindlessly forking.
NAK. The patch just reverts breaking of the current behaviour which is shutdown daemons in reverse order of start. AFAIK bash globbing is unable to sort on timestamps, right? p
On Wed, Sep 01, 2010 at 12:41:04PM +0200, Kurt J. Bosch wrote:
2010-08-31 13:16, Dave Reisner:
On Tue, Aug 31, 2010 at 10:07:52AM +0200, Kurt J. Bosch wrote:
--snip--
I suggest:
From b202be97f8dc1c0c68aaea792d4457c674c673f3 Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch<kjb-temp-2009@alpenjodel.de> Date: Tue, 31 Aug 2010 09:57:47 +0200 Subject: [PATCH 17/17] Correct behaviour of kill_everything()
--- functions | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/functions b/functions index b9ba718..3ca7324 100644 --- a/functions +++ b/functions @@ -205,10 +205,9 @@ ck_status() { 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 - for daemon in /var/run/daemons/*; do - [[ -f $daemon ]] || continue - daemon=${daemon##*/} + # Find daemons NOT in the DAEMONS array. + # Shut these down first in reverse order. + for daemon in $( /bin/ls -t /var/run/daemons ); do in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon" done
@@ -220,7 +219,7 @@ kill_everything() {
# Terminate all processes stat_busy "Sending SIGTERM To Processes" - run_hook "$1_prekillall" + run_hook "${1}_prekillall" /sbin/killall5 -15&> /dev/null /bin/sleep 5 stat_done @@ -230,7 +229,7 @@ kill_everything() { /bin/sleep 1 stat_done
- run_hook "$1_postkillall" + run_hook "${1}_postkillall" }
activate_vgs() { -- 1.7.0.3
Parsing the output of ls will never be better than using shell globbing no matter how much simpler it might make the code appear to be. Not only are you avoiding a fork, but the shell glob will properly handle any odd characters thrown into the mix. You'll see breakage on something as simple as a space in your suggestion. While I'm inclined to believe that there will never be a space in the name of a daemon in Arch, if we're going for pure Bash in this rewrite, let's use Bash instead of mindlessly forking.
NAK. The patch just reverts breaking of the current behaviour which is shutdown daemons in reverse order of start. AFAIK bash globbing is unable to sort on timestamps, right? p
The _current_ behavior doesn't define an order unless its in DAEMONS. I've reverted _your_ behavior, which I don't feel has proper justification. Suppose I start daemons foo, bar and baz (in that order) after Arch boots. Why then, should the shutdown order of these daemons change merely because I had to restart bar, which is independent of foo and baz? d
2010-09-01 13:03, Dave Reisner:
The _current_ behavior doesn't define an order unless its in DAEMONS. I've reverted _your_ behavior, which I don't feel has proper justification.
I referred to extras/initscripts which indeed does. Please read the code: http://projects.archlinux.org/initscripts.git/tree/rc.shutdown?id=2010.07-1
Suppose I start daemons foo, bar and baz (in that order) after Arch boots. Why then, should the shutdown order of these daemons change merely because I had to restart bar, which is independent of foo and baz?
Because you know which is the right order and rc.shutdown just rolls back what you did. ^^
On Wed, Sep 01, 2010 at 07:30:45PM +0200, Kurt J. Bosch wrote:
2010-09-01 13:03, Dave Reisner:
The _current_ behavior doesn't define an order unless its in DAEMONS. I've reverted _your_ behavior, which I don't feel has proper justification.
I referred to extras/initscripts which indeed does. Please read the code: http://projects.archlinux.org/initscripts.git/tree/rc.shutdown?id=2010.07-1
Indeed, I was mistaken. However, I still stand by the idea that trying to parse the output of /bin/ls is flawed from the ground up. ls is made for human parsing, not programatical parsing.
Suppose I start daemons foo, bar and baz (in that order) after Arch boots. Why then, should the shutdown order of these daemons change merely because I had to restart bar, which is independent of foo and baz?
Because you know which is the right order and rc.shutdown just rolls back what you did. ^^
No, rc.shutdown does _not_ know the right order. The current behavior is broken. Example: 1) start network 2) start rpcbind 3) start nfs-common 4) restart network network now shuts down first, rendering the OS unable to cleanly close any outstanding nfs shares. This commonly results in a long hang at shutdown and the possibility of truncated files. d
2010-09-01 22:52, Dave Reisner:
On Wed, Sep 01, 2010 at 07:30:45PM +0200, Kurt J. Bosch wrote:
2010-09-01 13:03, Dave Reisner:
The _current_ behavior doesn't define an order unless its in DAEMONS. I've reverted _your_ behavior, which I don't feel has proper justification.
I referred to extras/initscripts which indeed does. Please read the code: http://projects.archlinux.org/initscripts.git/tree/rc.shutdown?id=2010.07-1
Indeed, I was mistaken. However, I still stand by the idea that trying to parse the output of /bin/ls is flawed from the ground up. ls is made for human parsing, not programatical parsing.
Suppose I start daemons foo, bar and baz (in that order) after Arch boots. Why then, should the shutdown order of these daemons change merely because I had to restart bar, which is independent of foo and baz?
Because you know which is the right order and rc.shutdown just rolls back what you did. ^^
No, rc.shutdown does _not_ know the right order. The current behavior is broken. Example:
1) start network 2) start rpcbind 3) start nfs-common 4) restart network
network now shuts down first, rendering the OS unable to cleanly close any outstanding nfs shares. This commonly results in a long hang at shutdown and the possibility of truncated files.
That's exactly what I meant. _You_ should now what you're doing and rc.shutdown tries its best afterwards. There is no real daemons dependency handling in Arch (probably because of KISS) so we can't expect it does always the right thing, but at least without the restart it would do in your example and that's better than nothing (random order) isn't it? :)
On Thu, Sep 02, 2010 at 01:53:20AM +0200, Kurt J. Bosch wrote:
2010-09-01 22:52, Dave Reisner:
On Wed, Sep 01, 2010 at 07:30:45PM +0200, Kurt J. Bosch wrote:
2010-09-01 13:03, Dave Reisner:
The _current_ behavior doesn't define an order unless its in DAEMONS. I've reverted _your_ behavior, which I don't feel has proper justification.
I referred to extras/initscripts which indeed does. Please read the code: http://projects.archlinux.org/initscripts.git/tree/rc.shutdown?id=2010.07-1
Indeed, I was mistaken. However, I still stand by the idea that trying to parse the output of /bin/ls is flawed from the ground up. ls is made for human parsing, not programatical parsing.
Suppose I start daemons foo, bar and baz (in that order) after Arch boots. Why then, should the shutdown order of these daemons change merely because I had to restart bar, which is independent of foo and baz?
Because you know which is the right order and rc.shutdown just rolls back what you did. ^^
No, rc.shutdown does _not_ know the right order. The current behavior is broken. Example:
1) start network 2) start rpcbind 3) start nfs-common 4) restart network
network now shuts down first, rendering the OS unable to cleanly close any outstanding nfs shares. This commonly results in a long hang at shutdown and the possibility of truncated files.
That's exactly what I meant. _You_ should now what you're doing and rc.shutdown tries its best afterwards. There is no real daemons dependency handling in Arch (probably because of KISS) so we can't expect it does always the right thing, but at least without the restart it would do in your example and that's better than nothing (random order) isn't it? :)
Isn't the KISS solution just to add the thing to the DAEMONS array? We're clearly in disagreement, and this is getting a little circular. I'm going to bow out from this gracefully -- the devs can resolve this as they see fit.
On Wed, Sep 1, 2010 at 5:41 AM, Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> wrote:
2010-08-31 13:16, Dave Reisner:
On Tue, Aug 31, 2010 at 10:07:52AM +0200, Kurt J. Bosch wrote:
--snip--
I suggest:
From b202be97f8dc1c0c68aaea792d4457c674c673f3 Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch<kjb-temp-2009@alpenjodel.de> Date: Tue, 31 Aug 2010 09:57:47 +0200 Subject: [PATCH 17/17] Correct behaviour of kill_everything()
--- functions | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/functions b/functions index b9ba718..3ca7324 100644 --- a/functions +++ b/functions @@ -205,10 +205,9 @@ ck_status() { 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 - for daemon in /var/run/daemons/*; do - [[ -f $daemon ]] || continue - daemon=${daemon##*/} + # Find daemons NOT in the DAEMONS array. + # Shut these down first in reverse order. + for daemon in $( /bin/ls -t /var/run/daemons ); do in_array "$daemon" "${DAEMONS[@]}" || stop_daemon "$daemon" done
@@ -220,7 +219,7 @@ kill_everything() {
# Terminate all processes stat_busy "Sending SIGTERM To Processes" - run_hook "$1_prekillall" + run_hook "${1}_prekillall" /sbin/killall5 -15&> /dev/null /bin/sleep 5 stat_done @@ -230,7 +229,7 @@ kill_everything() { /bin/sleep 1 stat_done
- run_hook "$1_postkillall" + run_hook "${1}_postkillall" }
activate_vgs() { -- 1.7.0.3
Parsing the output of ls will never be better than using shell globbing no matter how much simpler it might make the code appear to be. Not only are you avoiding a fork, but the shell glob will properly handle any odd characters thrown into the mix. You'll see breakage on something as simple as a space in your suggestion. While I'm inclined to believe that there will never be a space in the name of a daemon in Arch, if we're going for pure Bash in this rewrite, let's use Bash instead of mindlessly forking.
NAK. The patch just reverts breaking of the current behaviour which is shutdown daemons in reverse order of start. AFAIK bash globbing is unable to sort on timestamps, right?
Bash globbing cannot handle it, but bash knows how to test file timestamps, so we could code something up that handles killing the daemons in reverse timestamp order if we had to. However, there is no reason to think that the order is significant for daemons not in $DAEMONS. If there are any dependencies that this code does not handle gracefully, the offending daemons will be killed when we kill -15 and then kill -9 the rest of the processes. If a daemon does not handle SIGTERM gracefully because of dependency issues, it has other, more significant problems.
2010-09-01 17:29, Victor Lowther:
Bash globbing cannot handle it, but bash knows how to test file timestamps, so we could code something up that handles killing the daemons in reverse timestamp order if we had to. However, there is no reason to think that the order is significant for daemons not in $DAEMONS. If there are any dependencies that this code does not handle gracefully, the offending daemons will be killed when we kill -15 and then kill -9 the rest of the processes. If a daemon does not handle SIGTERM gracefully because of dependency issues, it has other, more significant problems.
I really don't know if this 'feature' is actually still wanted or needed, but I feel it should be dropped in a separate commit if ever. :)
2010-09-01 17:29, Victor Lowther:
Bash globbing cannot handle it, but bash knows how to test file timestamps, so we could code something up that handles killing the daemons in reverse timestamp order if we had to.
ls -l --full-time healthd fancontrol -rw-r--r-- 1 root root 0 2010-09-02 00:51:28.680006529 +0200 fancontrol -rw-r--r-- 1 root root 0 2010-09-02 00:51:28.736673174 +0200 healthd [[ healthd -nt fancontrol || healthd -ot fancontrol ]] || echo equal equal It appears as if bash doesn't recognise fractions of a second :/
--- rc.shutdown | 8 ++------ 1 files changed, 2 insertions(+), 6 deletions(-) diff --git a/rc.shutdown b/rc.shutdown index 4eb29cc..002a45d 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -16,13 +16,9 @@ printhl "Initiating Shutdown..." echo " " # avoid NIS hanging syslog-ng on shutdown by unsetting the domainname -if [ -x /bin/domainname ]; then - /bin/domainname "" -fi +[[ -x /bin/domainname ]] && /bin/domainname "" +[[ -x /etc/rc.local.shutdown ]] && /etc/rc.local.shutdown -if [ -x /etc/rc.local.shutdown ]; then - /etc/rc.local.shutdown -fi # Find daemons NOT in the DAEMONS array. Shut these down first if [ -d /var/run/daemons ]; then -- 1.7.1
Someday, someone may have a daemon name with a space in it. --- rc.multi | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rc.multi b/rc.multi index ec6fda6..660f649 100755 --- a/rc.multi +++ b/rc.multi @@ -15,8 +15,8 @@ run_hook multi_start for daemon in "${DAEMONS[@]}"; do case ${daemon:0:1} in '!') continue;; # Skip this daemon. - '@') start_daemon_bkgd ${daemon#@};; - *) start_daemon $daemon;; + '@') start_daemon_bkgd "${daemon#@}";; + *) start_daemon "$daemon";; esac done -- 1.7.1
--- rc.sysinit | 16 +++++++--------- 1 files changed, 7 insertions(+), 9 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index f3e60b7..1d16224 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -92,16 +92,14 @@ if /bin/pidof -o %PPID /sbin/udevd >/dev/null; then fi # Load modules from the MODULES array defined in rc.conf -if ! [ "$load_modules" = "off" ]; then - if [ -f /proc/modules ]; then - stat_busy "Loading Modules" - for mod in "${MODULES[@]}"; do - if [ "$mod" = "${mod#!}" ]; then - /sbin/modprobe $mod - fi - done - stat_done +if [[ $load_modules != off && -f /proc/modules ]]; then + stat_busy "Loading Modules" + for mod in "${MODULES[@]}"; do + if [[ $mod = ${mod#!} ]]; then + /sbin/modprobe $mod fi + done + stat_done fi # Wait for udev uevents -- 1.7.1
--- rc.shutdown | 7 +++---- 1 files changed, 3 insertions(+), 4 deletions(-) diff --git a/rc.shutdown b/rc.shutdown index b7b7d45..7d5ec26 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -108,15 +108,14 @@ stat_done run_hook shutdown_poweroff # Power off or reboot -if [ "$RUNLEVEL" = "0" ]; then - printsep +printsep +if [[ $RUNLEVEL = 0 ]]; then printhl "${C_H2}POWER OFF" /sbin/poweroff -d -f -h -i else - printsep printhl "${C_H2}REBOOTING" # if kexec is installed and a kernel is loaded, use it - [ -x /sbin/kexec ] && /sbin/kexec -e > /dev/null 2>&1 + [[ -x /sbin/kexec ]] && /sbin/kexec -e > /dev/null 2>&1 /sbin/reboot -d -f -i fi -- 1.7.1
--- rc.sysinit | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 31636e5..404e11a 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -123,7 +123,7 @@ if [[ -d /sys/class/net/lo ]]; then fi # If necessary, find md devices and manually assemble RAID arrays -if [ -f /etc/mdadm.conf -a "$(/bin/grep ^ARRAY /etc/mdadm.conf 2>/dev/null)" ]; then +if [[ -f /etc/mdadm.conf ]] && /bin/grep -q ^ARRAY /etc/mdadm.conf; then status "Activating RAID arrays" /sbin/mdadm --assemble --scan fi -- 1.7.1
--- rc.sysinit | 21 ++++++++------------- 1 files changed, 8 insertions(+), 13 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index c62ae8d..29adeca 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -17,12 +17,9 @@ printsep run_hook sysinit_start # mount /proc, /sys and our RAM /dev -if ! /bin/mountpoint -q /proc; then - /bin/mount -n -t proc none /proc -fi -if ! /bin/mountpoint -q /sys; then - /bin/mount -n -t sysfs none /sys -fi +/bin/mountpoint -q /proc || /bin/mount -n -t proc none /proc +/bin/mountpoint -q /sys || /bin/mount -n -t sysfs none /sys + if ! /bin/mountpoint -q /dev; then if grep -q devtmpfs /proc/filesystems 2>/dev/null; then /bin/mount -n -t devtmpfs udev /dev -o mode=0755,size=10M,nosuid @@ -46,13 +43,11 @@ else fi HWCLOCK_PARAMS="--hctosys" -if [ "$HARDWARECLOCK" = "UTC" ]; then - HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc" -elif [ "$HARDWARECLOCK" = "localtime" ]; then - HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime" -else - HWCLOCK_PARAMS="" -fi +case $HARDWARECLOCK in + UTC) "$HWCLOCK_PARAMS --utc";; + localtime) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime";; + *) HWCLOCK_PARAMS="";; +esac if [ -n "$HWCLOCK_PARAMS" ]; then # enable rtc access -- 1.7.1
--- rc.shutdown | 22 +++++++++------------- 1 files changed, 9 insertions(+), 13 deletions(-) diff --git a/rc.shutdown b/rc.shutdown index cc39030..b2278b6 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -27,8 +27,8 @@ RANDOM_SEED=/var/lib/misc/random-seed : > $RANDOM_SEED /bin/chmod 0600 $RANDOM_SEED POOL_FILE=/proc/sys/kernel/random/poolsize -if [ -r $POOL_FILE ]; then - POOL_SIZE=$(/bin/cat $POOL_FILE) +if [[ -r $POOL_FILE ]]; then + read POOL_SIZE <$POOL_FILE else POOL_SIZE=512 fi @@ -36,22 +36,18 @@ fi stat_done stat_busy "Saving System Clock" -if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ]; then +if [[ $TIMEZONE && -e /usr/share/zoneinfo/$TIMEZONE ]]; then /bin/rm -f /etc/localtime /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime fi HWCLOCK_PARAMS="--systohc" -if [ "$HARDWARECLOCK" = "UTC" ]; then - HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc" -elif [ "$HARDWARECLOCK" = "localtime" ]; then - HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime" -else - HWCLOCK_PARAMS="" -fi -if [ -n "$HWCLOCK_PARAMS" ]; then - /sbin/hwclock $HWCLOCK_PARAMS -fi +case $HARDWARECLOCK in + UTC) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc";; + localtime) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime";; + *) HWCLOCK_PARAMS="";; +esac +[[ $HWCLOCK_PARAMS ]] && /sbin/hwclock $HWCLOCK_PARAMS stat_done # removing psmouse module to fix some reboot issues on newer laptops -- 1.7.1
--- rc.shutdown | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/rc.shutdown b/rc.shutdown index ef9b16d..cc39030 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -23,7 +23,7 @@ kill_everything stat_busy "Saving Random Seed" RANDOM_SEED=/var/lib/misc/random-seed -[ -d $(dirname $RANDOM_SEED) ] || mkdir -p $(dirname $RANDOM_SEED) +[[ -d ${RANDOM_SEED%/*} ]] || mkdir -p ${RANDOM_SEED%/*} : > $RANDOM_SEED /bin/chmod 0600 $RANDOM_SEED POOL_FILE=/proc/sys/kernel/random/poolsize -- 1.7.1
--- rc.shutdown | 52 +++++++++++++++++++++++----------------------------- 1 files changed, 23 insertions(+), 29 deletions(-) diff --git a/rc.shutdown b/rc.shutdown index b2278b6..b7b7d45 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -65,7 +65,7 @@ stat_busy "Unmounting Filesystems" stat_done # Kill non-root encrypted partition mappings -if [ -f /etc/crypttab -a -n "$(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$)" ]; then +if [[ -f /etc/crypttab ]]; then stat_busy "Deactivating encrypted volumes:" # Arch cryptsetup packages traditionally contained the binaries # /usr/sbin/cryptsetup @@ -73,38 +73,32 @@ if [ -f /etc/crypttab -a -n "$(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$)" # By default, initscripts used the /sbin/cryptsetup.static. # Newer packages will only have /sbin/cryptsetup and no static binary # This ensures maximal compatibility with the old and new layout - if [ -x /sbin/cryptsetup ]; then - CS=/sbin/cryptsetup - elif [ -x /usr/sbin/cryptsetup ]; then - CS=/usr/sbin/cryptsetup + for CS in /sbin/cryptsetup /usr/sbin/cryptsetup \ + /sbin/cryptsetup.static ''; do + [[ -x $CS ]] && break + done + if [[ ! $CS ]]; then + stat_append " Failed, unable to find cryptsetup." + stat_fail else - CS=/sbin/cryptsetup.static - fi - do_uncrypt() { - if [ $# -ge 3 ]; then - if [ -b /dev/mapper/$1 ] ;then - stat_append "${1}.." - $CS remove $1 >/dev/null 2>&1 - if [ $? -ne 0 ]; then - stat_append "failed " - else - stat_append "ok " - fi - fi + while read name src passwd opts; do + [[ ! $name || ${name:0:1} = '#']] && continue + [[ -b /dev/mapper/$name ]] || continue + stat_append "${1}.." + if "$CS" remove "$name" >/dev/null 2>&1; then + stat_append "ok " + else + stat_append "failed " fi - } - while read line; do - eval do_uncrypt "$line" - done </etc/crypttab - stat_done + done </etc/crypttab + fi + stat_done fi -if [ "$USELVM" = "yes" -o "$USELVM" = "YES" ]; then - if [ -x /sbin/lvm -a -d /sys/block ]; then - stat_busy "Deactivating LVM2 groups" - /sbin/lvm vgchange --ignorelockingfailure -an >/dev/null 2>&1 - stat_done - fi +if [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then + stat_busy "Deactivating LVM2 groups" + /sbin/lvm vgchange --ignorelockingfailure -an >/dev/null 2>&1 + stat_done fi stat_busy "Remounting Root Filesystem Read-only" -- 1.7.1
Trying to stick with POSIX syntax only just slows things down. --- rc.sysinit | 27 +++++++++++---------------- 1 files changed, 11 insertions(+), 16 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 29adeca..f3e60b7 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -44,27 +44,22 @@ fi HWCLOCK_PARAMS="--hctosys" case $HARDWARECLOCK in - UTC) "$HWCLOCK_PARAMS --utc";; - localtime) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime";; + UTC) HWCLOCK_PARAMS+=" --utc";; + localtime) HWCLOCK_PARAMS+=" --localtime";; *) HWCLOCK_PARAMS="";; esac -if [ -n "$HWCLOCK_PARAMS" ]; then +if [[ $HWCLOCK_PARAMS ]]; then # enable rtc access - /sbin/modprobe -q rtc-cmos - # some custom kernels use rtc/genrtc, try to load those too - /sbin/modprobe -q rtc - /sbin/modprobe -q genrtc + /sbin/modprobe -q -a rtc-cmos rtc genrtc # If devtmpfs is used, the required RTC device already exists now # Otherwise, create whatever device is available - if [ ! -c /dev/rtc -a ! -c /dev/rtc0 ]; then - if [ -f /sys/class/rtc/rtc0/dev ]; then - IFS=: read -r major minor < /sys/class/rtc/rtc0/dev - /bin/mknod /dev/rtc0 c $major $minor - elif [ -f /sys/class/misc/rtc/dev ]; then - IFS=: read -r major minor < /sys/class/misc/rtc/dev - /bin/mknod /dev/rtc c $major $minor - fi + if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then + for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do + [[ -e $dev ]] || continue + IFS=: read -r major minor < "$dev" + /bin/mknod /dev/rtc c $major $minor + done fi # Do a clock set here for a few reasons: @@ -75,7 +70,7 @@ if [ -n "$HWCLOCK_PARAMS" ]; then # a later time. # This does *NOT* take into account a time adjustment file as /var may not be # mounted yet. A second set occurs later to match rc.conf. - if [ -f /etc/localtime ]; then + if [[ -f /etc/localtime ]]; then /sbin/hwclock $HWCLOCK_PARAMS --noadjfile fi fi -- 1.7.1
Am 2010-06-30 23:47, schrieb Victor Lowther:
Trying to stick with POSIX syntax only just slows things down. --- rc.sysinit | 27 +++++++++++---------------- 1 files changed, 11 insertions(+), 16 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index 29adeca..f3e60b7 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -44,27 +44,22 @@ fi
HWCLOCK_PARAMS="--hctosys" case $HARDWARECLOCK in - UTC) "$HWCLOCK_PARAMS --utc";; - localtime) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime";; + UTC) HWCLOCK_PARAMS+=" --utc";; + localtime) HWCLOCK_PARAMS+=" --localtime";; *) HWCLOCK_PARAMS="";; esac
-if [ -n "$HWCLOCK_PARAMS" ]; then +if [[ $HWCLOCK_PARAMS ]]; then # enable rtc access - /sbin/modprobe -q rtc-cmos - # some custom kernels use rtc/genrtc, try to load those too - /sbin/modprobe -q rtc - /sbin/modprobe -q genrtc + /sbin/modprobe -q -a rtc-cmos rtc genrtc # If devtmpfs is used, the required RTC device already exists now # Otherwise, create whatever device is available - if [ ! -c /dev/rtc -a ! -c /dev/rtc0 ]; then - if [ -f /sys/class/rtc/rtc0/dev ]; then - IFS=: read -r major minor< /sys/class/rtc/rtc0/dev - /bin/mknod /dev/rtc0 c $major $minor - elif [ -f /sys/class/misc/rtc/dev ]; then - IFS=: read -r major minor< /sys/class/misc/rtc/dev - /bin/mknod /dev/rtc c $major $minor - fi + if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then + for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do + [[ -e $dev ]] || continue + IFS=: read -r major minor< "$dev" + /bin/mknod /dev/rtc c $major $minor + done fi
Actually this doesn't do the same. What about the following? if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then for dev in /sys/class/rtc/rtc0 /sys/class/misc/rtc; do [[ -e $dev/dev ]] || continue IFS=: read -r major minor< "$dev/dev" /bin/mknod /dev/${dev##*/} c $major $minor done fi
I am missing the difference. Diff please? Sent from my Nexus One On Aug 18, 2010 2:41 AM, "Kurt J. Bosch" <kjb-temp-2009@alpenjodel.de> wrote:
Am 2010-06-30 23:47, schrieb Victor Lowther:
Trying to stick with POSIX syntax only just slows things down. --- rc.sysinit | 27 +++++++++++---------------- 1 files changed, 11 insertions(+), 16 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index 29adeca..f3e60b7 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -44,27 +44,22 @@ fi
HWCLOCK_PARAMS="--hctosys" case $HARDWARECLOCK in - UTC) "$HWCLOCK_PARAMS --utc";; - localtime) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime";; + UTC) HWCLOCK_PARAMS+=" --utc";; + localtime) HWCLOCK_PARAMS+=" --localtime";; *) HWCLOCK_PARAMS="";; esac
-if [ -n "$HWCLOCK_PARAMS" ]; then +if [[ $HWCLOCK_PARAMS ]]; then # enable rtc access - /sbin/modprobe -q rtc-cmos - # some custom kernels use rtc/genrtc, try to load those too - /sbin/modprobe -q rtc - /sbin/modprobe -q genrtc + /sbin/modprobe -q -a rtc-cmos rtc genrtc # If devtmpfs is used, the required RTC device already exists now # Otherwise, create whatever device is available - if [ ! -c /dev/rtc -a ! -c /dev/rtc0 ]; then - if [ -f /sys/class/rtc/rtc0/dev ]; then - IFS=: read -r major minor< /sys/class/rtc/rtc0/dev - /bin/mknod /dev/rtc0 c $major $minor - elif [ -f /sys/class/misc/rtc/dev ]; then - IFS=: read -r major minor< /sys/class/misc/rtc/dev - /bin/mknod /dev/rtc c $major $minor - fi + if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then + for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do + [[ -e $dev ]] || continue + IFS=: read -r major minor< "$dev" + /bin/mknod /dev/rtc c $major $minor + done fi
Actually this doesn't do the same. What about the following?
if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then for dev in /sys/class/rtc/rtc0 /sys/class/misc/rtc; do [[ -e $dev/dev ]] || continue IFS=: read -r major minor< "$dev/dev" /bin/mknod /dev/${dev##*/} c $major $minor done fi
On 19/08/10 14:23, Victor Lowther wrote:
I am missing the difference. Diff please?
Yours:
+ /bin/mknod /dev/rtc c $major $minor
His:
/bin/mknod /dev/${dev##*/} c $major $minor
Yours creates /dev/rtc and his creates /dev/rtc and /dev/rtc0 Allan
On Thu, Aug 19, 2010 at 02:34:50PM +1000, Allan McRae wrote:
On 19/08/10 14:23, Victor Lowther wrote:
I am missing the difference. Diff please?
Yours:
+ /bin/mknod /dev/rtc c $major $minor
His:
/bin/mknod /dev/${dev##*/} c $major $minor
Yours creates /dev/rtc and his creates /dev/rtc and /dev/rtc0
Allan
Couldn't we avoid all this by just flipping a switch in the kernel? CONFIG_RTC_DRV_CMOS=y If it's compiled into the kernel, udev picks it up and creates the /dev nodes for us. d
On Thu, 2010-08-19 at 00:56 -0400, Dave Reisner wrote:
Couldn't we avoid all this by just flipping a switch in the kernel?
CONFIG_RTC_DRV_CMOS=y
If it's compiled into the kernel, udev picks it up and creates the /dev nodes for us.
Which still locks out the people who use a custom kernel with this driver compiled as module. IMHO the init scripts should work with both module and built-in.
Am 2010-08-19 10:19, schrieb Jan de Groot:
On Thu, 2010-08-19 at 00:56 -0400, Dave Reisner wrote:
Couldn't we avoid all this by just flipping a switch in the kernel?
CONFIG_RTC_DRV_CMOS=y
If it's compiled into the kernel, udev picks it up and creates the /dev nodes for us.
Which still locks out the people who use a custom kernel with this driver compiled as module. IMHO the init scripts should work with both module and built-in.
So why not let udev do the job? Patch below. I modified my initcpio to get rid of the devtmpfs. A ls -l /dev/rtc* added between the new /sbin/udevadm settle and the initial clock setting showed /dev/rtc0 and /dev/rtc -> rtc0. So I think this should work. I did *not* move the sysinit_udevlaunched hook together with udev start to avoid insane creation times of dev nodes because this hook is used for some early udev triggering in fbsplash-extras (AUR). Patch against bashification-redux: From 22d410a2566964d58752d443a1312a6eb552660a Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> Date: Thu, 19 Aug 2010 16:46:23 +0200 Subject: [PATCH 17/17] Correct rtc dev nodes creation using udev --- rc.sysinit | 22 +++++++--------------- 1 files changed, 7 insertions(+), 15 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 4421def..2415967 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -46,6 +46,12 @@ else /bin/dmesg -n 3 fi +echo > /proc/sys/kernel/hotplug + +stat_busy "Starting UDev Daemon" +/sbin/udevd --daemon +stat_done + HWCLOCK_PARAMS="--hctosys" case $HARDWARECLOCK in UTC) HWCLOCK_PARAMS+=" --utc";; @@ -56,15 +62,7 @@ esac if [[ $HWCLOCK_PARAMS ]]; then # enable rtc access /sbin/modprobe -q -a rtc-cmos rtc genrtc - # If devtmpfs is used, the required RTC device already exists now - # Otherwise, create whatever device is available - if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then - for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do - [[ -e $dev ]] || continue - IFS=: read -r major minor < "$dev" - /bin/mknod /dev/rtc c $major $minor - done - fi + /sbin/udevadm settle # Do a clock set here for a few reasons: # 1. Make creation time on udev nodes sane (FS#8665) @@ -79,12 +77,6 @@ if [[ $HWCLOCK_PARAMS ]]; then fi fi -echo > /proc/sys/kernel/hotplug - -stat_busy "Starting UDev Daemon" -/sbin/udevd --daemon -stat_done - run_hook sysinit_udevlaunched # Trigger udev uevents -- 1.7.2.1
I like this one the best. Sent from my Nexus One. Sorry for top posting. On Aug 19, 2010 10:08 AM, "Kurt J. Bosch" <kjb-temp-2009@alpenjodel.de> wrote:
Am 2010-08-19 10:19, schrieb Jan de Groot:
On Thu, 2010-08-19 at 00:56 -0400, Dave Reisner wrote:
Couldn't we avoid all this by just flipping a switch in the kernel?
CONFIG_RTC_DRV_CMOS=y
If it's compiled into the kernel, udev picks it up and creates the /dev nodes for us.
Which still locks out the people who use a custom kernel with this driver compiled as module. IMHO the init scripts should work with both module and built-in.
So why not let udev do the job? Patch below. I modified my initcpio to get rid of the devtmpfs. A ls -l /dev/rtc* added between the new /sbin/udevadm settle and the initial clock setting showed /dev/rtc0 and /dev/rtc -> rtc0. So I think this should work.
I did *not* move the sysinit_udevlaunched hook together with udev start to avoid insane creation times of dev nodes because this hook is used for some early udev triggering in fbsplash-extras (AUR).
Patch against bashification-redux:
From 22d410a2566964d58752d443a1312a6eb552660a Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> Date: Thu, 19 Aug 2010 16:46:23 +0200 Subject: [PATCH 17/17] Correct rtc dev nodes creation using udev
--- rc.sysinit | 22 +++++++--------------- 1 files changed, 7 insertions(+), 15 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index 4421def..2415967 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -46,6 +46,12 @@ else /bin/dmesg -n 3 fi
+echo > /proc/sys/kernel/hotplug + +stat_busy "Starting UDev Daemon" +/sbin/udevd --daemon +stat_done + HWCLOCK_PARAMS="--hctosys" case $HARDWARECLOCK in UTC) HWCLOCK_PARAMS+=" --utc";; @@ -56,15 +62,7 @@ esac if [[ $HWCLOCK_PARAMS ]]; then # enable rtc access /sbin/modprobe -q -a rtc-cmos rtc genrtc - # If devtmpfs is used, the required RTC device already exists now - # Otherwise, create whatever device is available - if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then - for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do - [[ -e $dev ]] || continue - IFS=: read -r major minor < "$dev" - /bin/mknod /dev/rtc c $major $minor - done - fi + /sbin/udevadm settle
# Do a clock set here for a few reasons: # 1. Make creation time on udev nodes sane (FS#8665) @@ -79,12 +77,6 @@ if [[ $HWCLOCK_PARAMS ]]; then fi fi
-echo > /proc/sys/kernel/hotplug - -stat_busy "Starting UDev Daemon" -/sbin/udevd --daemon -stat_done - run_hook sysinit_udevlaunched
# Trigger udev uevents -- 1.7.2.1
On 2010-08-19 23:12, Victor Lowther wrote:
On Aug 19, 2010 10:08 AM, "Kurt J. Bosch"<kjb-temp-2009@alpenjodel.de> wrote:
On 2010-08-19 10:19, Jan de Groot wrote:
On Thu, 2010-08-19 at 00:56 -0400, Dave Reisner wrote:
Couldn't we avoid all this by just flipping a switch in the kernel?
CONFIG_RTC_DRV_CMOS=y
If it's compiled into the kernel, udev picks it up and creates the /dev nodes for us.
Which still locks out the people who use a custom kernel with this driver compiled as module. IMHO the init scripts should work with both module and built-in.
So why not let udev do the job? Patch below. I modified my initcpio to get rid of the devtmpfs. A ls -l /dev/rtc* added between the new /sbin/udevadm settle and the initial clock setting showed /dev/rtc0 and /dev/rtc -> rtc0. So I think this should work.
I did *not* move the sysinit_udevlaunched hook together with udev start to avoid insane creation times of dev nodes because this hook is used for some early udev triggering in fbsplash-extras (AUR).
Patch against bashification-redux:
From 22d410a2566964d58752d443a1312a6eb552660a Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch<kjb-temp-2009@alpenjodel.de> Date: Thu, 19 Aug 2010 16:46:23 +0200 Subject: [PATCH 17/17] Correct rtc dev nodes creation using udev
--- rc.sysinit | 22 +++++++--------------- 1 files changed, 7 insertions(+), 15 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index 4421def..2415967 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -46,6 +46,12 @@ else /bin/dmesg -n 3 fi
+echo> /proc/sys/kernel/hotplug + +stat_busy "Starting UDev Daemon" +/sbin/udevd --daemon +stat_done + HWCLOCK_PARAMS="--hctosys" case $HARDWARECLOCK in UTC) HWCLOCK_PARAMS+=" --utc";; @@ -56,15 +62,7 @@ esac if [[ $HWCLOCK_PARAMS ]]; then # enable rtc access /sbin/modprobe -q -a rtc-cmos rtc genrtc - # If devtmpfs is used, the required RTC device already exists now - # Otherwise, create whatever device is available - if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then - for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do - [[ -e $dev ]] || continue - IFS=: read -r major minor< "$dev" - /bin/mknod /dev/rtc c $major $minor - done - fi + /sbin/udevadm settle
# Do a clock set here for a few reasons: # 1. Make creation time on udev nodes sane (FS#8665) @@ -79,12 +77,6 @@ if [[ $HWCLOCK_PARAMS ]]; then fi fi
-echo> /proc/sys/kernel/hotplug - -stat_busy "Starting UDev Daemon" -/sbin/udevd --daemon -stat_done - run_hook sysinit_udevlaunched
# Trigger udev uevents -- 1.7.2.1
I like this one the best.
Sent from my Nexus One. Sorry for top posting.
Corrected Hmm, the patch might break things with custom non modular kernels without devtmpfs though. No modules loading no uevents and no dev nodes. On the other hand reading the hwclock man page, I'm a bit uncertain whether that piece will ever use /dev/rtc0 without a symlink from /dev/rtc. Instead it might actually fall back to direct I/O with the current code and with the patched one too. Moreover I found a couple of interesting things: * The system clock is already set (by the kernel - in spite of CONFIG_RTC_HCTOSYS not set) even without doing anything. Weird, but with UTC hardware clock I even get correct mtimes in early user space. * man hwclock:
−−systz Reset the System Time based on the current timezone. ... This is an alternate option to −−hctosys that does not read the hardware clock, and may be used in system startup scripts for recent 2.6 kernels where you know the System Time contains the Hardware Clock time. I switched my hardware clock to localtime, reverted my patch and modified rc.sysinit to use −systz instead of --hctosys for the first hwclock call and also disabled the entire rtc modprobe and mknod code. A date command inserted for testing spit out the correct time. From the util-linux-ng list: Indeed, we may be running hwclock --systz before /dev is mounted. Getting rid of the pre fsck hwclock --hctosys would also on the average save another half second of boot up time beside removing some ugly code.
AFAIKS we can go one of three ways: * Use udev expecting CONFIG_RTC_DRV_CMOS=m or fall back to direct I/O * Use −−systz, drop the ugly code and expect some help from the kernel * Use an even more ugly code creating the missing symlink: Corrected non udev patch against bashification-redux: From 4e5d6a763af8f45c63ad53aa99b82246f90c0b43 Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> Date: Fri, 20 Aug 2010 09:04:46 +0200 Subject: [PATCH 17/17] Really correct rtc dev nodes creation --- rc.sysinit | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 4421def..1ff37cc 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -58,12 +58,15 @@ if [[ $HWCLOCK_PARAMS ]]; then /sbin/modprobe -q -a rtc-cmos rtc genrtc # If devtmpfs is used, the required RTC device already exists now # Otherwise, create whatever device is available - if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then - for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do - [[ -e $dev ]] || continue - IFS=: read -r major minor < "$dev" - /bin/mknod /dev/rtc c $major $minor - done + if ! [[ -c /dev/rtc ]]; then + for dev in /sys/class/misc/rtc /sys/class/rtc/rtc0; do + [[ -e $dev/dev ]] || continue + IFS=: read -r major minor < "$dev/dev" + node=${dev##*/} + /bin/mknod /dev/$node c $major $minor + [[ $node = rtc ]] || /bin/ln -s $node /dev/rtc + break + done fi # Do a clock set here for a few reasons: -- 1.7.2.1 -- Kurt
On Fri, Aug 20, 2010 at 2:12 AM, Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> wrote:
On 2010-08-19 23:12, Victor Lowther wrote:
On Aug 19, 2010 10:08 AM, "Kurt J. Bosch"<kjb-temp-2009@alpenjodel.de> wrote:
On 2010-08-19 10:19, Jan de Groot wrote:
On Thu, 2010-08-19 at 00:56 -0400, Dave Reisner wrote:
Couldn't we avoid all this by just flipping a switch in the kernel?
CONFIG_RTC_DRV_CMOS=y
If it's compiled into the kernel, udev picks it up and creates the /dev nodes for us.
Which still locks out the people who use a custom kernel with this driver compiled as module. IMHO the init scripts should work with both module and built-in.
So why not let udev do the job? Patch below. I modified my initcpio to get rid of the devtmpfs. A ls -l /dev/rtc* added between the new /sbin/udevadm settle and the initial clock setting showed /dev/rtc0 and /dev/rtc -> rtc0. So I think this should work.
I did *not* move the sysinit_udevlaunched hook together with udev start to avoid insane creation times of dev nodes because this hook is used for some early udev triggering in fbsplash-extras (AUR).
Patch against bashification-redux:
From 22d410a2566964d58752d443a1312a6eb552660a Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch<kjb-temp-2009@alpenjodel.de> Date: Thu, 19 Aug 2010 16:46:23 +0200 Subject: [PATCH 17/17] Correct rtc dev nodes creation using udev
--- rc.sysinit | 22 +++++++--------------- 1 files changed, 7 insertions(+), 15 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index 4421def..2415967 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -46,6 +46,12 @@ else /bin/dmesg -n 3 fi
+echo> /proc/sys/kernel/hotplug + +stat_busy "Starting UDev Daemon" +/sbin/udevd --daemon +stat_done + HWCLOCK_PARAMS="--hctosys" case $HARDWARECLOCK in UTC) HWCLOCK_PARAMS+=" --utc";; @@ -56,15 +62,7 @@ esac if [[ $HWCLOCK_PARAMS ]]; then # enable rtc access /sbin/modprobe -q -a rtc-cmos rtc genrtc - # If devtmpfs is used, the required RTC device already exists now - # Otherwise, create whatever device is available - if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then - for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do - [[ -e $dev ]] || continue - IFS=: read -r major minor< "$dev" - /bin/mknod /dev/rtc c $major $minor - done - fi + /sbin/udevadm settle
# Do a clock set here for a few reasons: # 1. Make creation time on udev nodes sane (FS#8665) @@ -79,12 +77,6 @@ if [[ $HWCLOCK_PARAMS ]]; then fi fi
-echo> /proc/sys/kernel/hotplug - -stat_busy "Starting UDev Daemon" -/sbin/udevd --daemon -stat_done - run_hook sysinit_udevlaunched
# Trigger udev uevents -- 1.7.2.1
I like this one the best.
Sent from my Nexus One. Sorry for top posting.
Corrected
Hmm, the patch might break things with custom non modular kernels without devtmpfs though. No modules loading no uevents and no dev nodes. On the other hand reading the hwclock man page, I'm a bit uncertain whether that piece will ever use /dev/rtc0 without a symlink from /dev/rtc. Instead it might actually fall back to direct I/O with the current code and with the patched one too.
Moreover I found a couple of interesting things: * The system clock is already set (by the kernel - in spite of CONFIG_RTC_HCTOSYS not set) even without doing anything. Weird, but with UTC hardware clock I even get correct mtimes in early user space. * man hwclock:
--systz Reset the System Time based on the current timezone. ... This is an alternate option to --hctosys that does not read the hardware clock, and may be used in system startup scripts for recent 2.6 kernels where you know the System Time contains the Hardware Clock time. I switched my hardware clock to localtime, reverted my patch and modified rc.sysinit to use -systz instead of --hctosys for the first hwclock call and also disabled the entire rtc modprobe and mknod code. A date command inserted for testing spit out the correct time. From the util-linux-ng list: Indeed, we may be running hwclock --systz before /dev is mounted. Getting rid of the pre fsck hwclock --hctosys would also on the average save another half second of boot up time beside removing some ugly code.
AFAIKS we can go one of three ways: * Use udev expecting CONFIG_RTC_DRV_CMOS=m or fall back to direct I/O * Use --systz, drop the ugly code and expect some help from the kernel * Use an even more ugly code creating the missing symlink:
Corrected non udev patch against bashification-redux:
From 4e5d6a763af8f45c63ad53aa99b82246f90c0b43 Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> Date: Fri, 20 Aug 2010 09:04:46 +0200 Subject: [PATCH 17/17] Really correct rtc dev nodes creation
--- rc.sysinit | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index 4421def..1ff37cc 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -58,12 +58,15 @@ if [[ $HWCLOCK_PARAMS ]]; then /sbin/modprobe -q -a rtc-cmos rtc genrtc # If devtmpfs is used, the required RTC device already exists now # Otherwise, create whatever device is available - if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then - for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do - [[ -e $dev ]] || continue - IFS=: read -r major minor < "$dev" - /bin/mknod /dev/rtc c $major $minor - done + if ! [[ -c /dev/rtc ]]; then + for dev in /sys/class/misc/rtc /sys/class/rtc/rtc0; do + [[ -e $dev/dev ]] || continue + IFS=: read -r major minor < "$dev/dev" + node=${dev##*/} + /bin/mknod /dev/$node c $major $minor + [[ $node = rtc ]] || /bin/ln -s $node /dev/rtc + break + done fi
# Do a clock set here for a few reasons: -- 1.7.2.1
Thanks, I will apply this to bashification-redux.
-- Kurt
Am 2010-08-19 06:23, schrieb Victor Lowther:
I am missing the difference. Diff please?
/dev/rtc vs. /dev/{rtc,rtc0} as already said in the other replies. Patch against bashification-redux: From 5d3ac218c3e05bf9735bb49826bee0b393418699 Mon Sep 17 00:00:00 2001 From: Kurt J. Bosch <kjb-temp-2009@alpenjodel.de> Date: Thu, 19 Aug 2010 18:17:01 +0200 Subject: [PATCH 17/17] Correct rtc dev nodes creation --- rc.sysinit | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 4421def..9fb10af 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -59,10 +59,10 @@ if [[ $HWCLOCK_PARAMS ]]; then # If devtmpfs is used, the required RTC device already exists now # Otherwise, create whatever device is available if ! [[ -c /dev/rtc || -c /dev/rtc0 ]]; then - for dev in /sys/class/rtc/rtc0/dev /sys/class/misc/rtc/dev; do - [[ -e $dev ]] || continue - IFS=: read -r major minor < "$dev" - /bin/mknod /dev/rtc c $major $minor + for dev in /sys/class/rtc/rtc0 /sys/class/misc/rtc; do + [[ -e $dev/dev ]] || continue + IFS=: read -r major minor< "$dev/dev" + /bin/mknod /dev/${dev##*/} c $major $minor done fi -- 1.7.2.1
--- rc.sysinit | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 1d16224..31636e5 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -113,13 +113,12 @@ fi run_hook sysinit_udevsettled # bring up the loopback interface -if [ -d /sys/class/net/lo ]; then +if [[ -d /sys/class/net/lo ]]; then stat_busy "Bringing up loopback interface" - /sbin/ifconfig lo 127.0.0.1 up - if [ $? -ne 0 ]; then - stat_fail + if ! /sbin/ifconfig lo 127.0.0.1 up; then + stat_fail else - stat_done + stat_done fi fi -- 1.7.1
Am 30.06.2010 23:47, schrieb Victor Lowther:
--- rc.sysinit | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index 1d16224..31636e5 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -113,13 +113,12 @@ fi run_hook sysinit_udevsettled
# bring up the loopback interface -if [ -d /sys/class/net/lo ]; then +if [[ -d /sys/class/net/lo ]]; then stat_busy "Bringing up loopback interface" - /sbin/ifconfig lo 127.0.0.1 up - if [ $? -ne 0 ]; then - stat_fail + if ! /sbin/ifconfig lo 127.0.0.1 up; then + stat_fail else - stat_done + stat_done fi fi
Hmm, this could be done with the status() function instead, right? No need for stat_{busy,fail,done} then.
On Thu, 2010-07-01 at 00:13 +0200, Thomas Bächler wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
--- rc.sysinit | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index 1d16224..31636e5 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -113,13 +113,12 @@ fi run_hook sysinit_udevsettled
# bring up the loopback interface -if [ -d /sys/class/net/lo ]; then +if [[ -d /sys/class/net/lo ]]; then stat_busy "Bringing up loopback interface" - /sbin/ifconfig lo 127.0.0.1 up - if [ $? -ne 0 ]; then - stat_fail + if ! /sbin/ifconfig lo 127.0.0.1 up; then + stat_fail else - stat_done + stat_done fi fi
Hmm, this could be done with the status() function instead, right? No need for stat_{busy,fail,done} then.
Probably. I was just looking for trivial bashification here -- I did not look for further simplifications. -- Victor Lowther LPIC2 UCP RHCE
--- rc.shutdown | 28 ++++++++++++++-------------- 1 files changed, 14 insertions(+), 14 deletions(-) diff --git a/rc.shutdown b/rc.shutdown index 7d5ec26..e823ed2 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -42,7 +42,7 @@ if [[ $TIMEZONE && -e /usr/share/zoneinfo/$TIMEZONE ]]; then fi HWCLOCK_PARAMS="--systohc" -case $HARDWARECLOCK in +case $HARDWARECLOCK in UTC) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc";; localtime) HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime";; *) HWCLOCK_PARAMS="";; @@ -73,26 +73,26 @@ if [[ -f /etc/crypttab ]]; then # By default, initscripts used the /sbin/cryptsetup.static. # Newer packages will only have /sbin/cryptsetup and no static binary # This ensures maximal compatibility with the old and new layout - for CS in /sbin/cryptsetup /usr/sbin/cryptsetup \ - /sbin/cryptsetup.static ''; do - [[ -x $CS ]] && break - done - if [[ ! $CS ]]; then - stat_append " Failed, unable to find cryptsetup." - stat_fail + for CS in /sbin/cryptsetup /usr/sbin/cryptsetup \ + /sbin/cryptsetup.static ''; do + [[ -x $CS ]] && break + done + if [[ ! $CS ]]; then + stat_append " Failed, unable to find cryptsetup." + stat_fail else - while read name src passwd opts; do - [[ ! $name || ${name:0:1} = '#']] && continue - [[ -b /dev/mapper/$name ]] || continue + while read name src passwd opts; do + [[ ! $name || ${name:0:1} = '#']] && continue + [[ -b /dev/mapper/$name ]] || continue stat_append "${1}.." if "$CS" remove "$name" >/dev/null 2>&1; then stat_append "ok " - else + else stat_append "failed " fi done </etc/crypttab - fi - stat_done + fi + stat_done fi if [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]]; then -- 1.7.1
--- rc.sysinit | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index ac32fca..1ecfc3f 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -352,7 +352,7 @@ done /bin/dmesg >| /var/log/dmesg.log # final hwclock setting needs to be done at this point -if [ -n "$clock_pid" ]; then +if [[ $clock_pid ]]; then wait $clock_pid fi -- 1.7.1
Split out reading /etc/crypttab and procssing the individual lines into their own helper functions, and bashify the resulting shorter code. Processing this file is still ugly, though. :( --- functions | 43 +++++++++++++++++-- rc.shutdown | 36 +++++------------ rc.sysinit | 131 ++++++++++++++++++---------------------------------------- 3 files changed, 90 insertions(+), 120 deletions(-) diff --git a/functions b/functions index bf6ed45..9ec8b5e 100644 --- a/functions +++ b/functions @@ -232,6 +232,40 @@ kill_everything() { run_hook single_postkillall } +activate_vgs() { + [[ $USELVM =~ yes|YES && -x /sbin/lvm && -d /sys/block ]] || return + # Kernel 2.6.x, LVM2 groups + /sbin/modprobe -q dm-mod 2>/dev/null + stat_busy "Activating LVM2 groups" + if /sbin/lvm vgchange --ignorelockingfailure -a y >/dev/null; then + stat_done + else + stat_fail + fi +} + +# Arch cryptsetup packages traditionally contained the binaries +# /usr/sbin/cryptsetup +# /sbin/cryptsetup.static +# By default, initscripts used the /sbin/cryptsetup.static. +# Newer packages will only have /sbin/cryptsetup and no static binary +# This ensures maximal compatibility with the old and new layout +for CS in /sbin/cryptsetup /usr/sbin/cryptsetup \ + /sbin/cryptsetup.static ''; do + [[ -x $CS ]] && break +done + +read_crypttab() { + # $1 = function to call with the split out line from the crypttab + local line nspo failed=0 + while read line; do + [[ $line && ${line:0:1} != '#' ]] || continue + eval nspo=("${line%#*}") + $1 "${nspo[@]}" || failed=1 + done < /etc/crypttab + return $failed +} + ############################### # Custom hooks in initscripts # ############################### @@ -278,7 +312,7 @@ run_hook() { [[ $1 ]] || return 1 local func for func in ${hook_funcs["$1"]}; do - "${func}" + q"${func}" done } @@ -293,13 +327,14 @@ set_consolefont() { for i in /dev/tty[0-9]*; do /usr/bin/setfont ${CONSOLEMAP:+-m ${CONSOLEMAP}} \ $CONSOLEFONT -C ${i} >/dev/null 2>&1 - done + done if (($? != 0)); then stat_fail elif [[ $CONSOLEMAP ]]; then cat <<"EOF" >>/etc/profile.d/locale.sh -if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033(K"; fi - +if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ] + then printf "\033(K" +fi EOF stat_done fi diff --git a/rc.shutdown b/rc.shutdown index e823ed2..1081970 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -65,33 +65,17 @@ stat_busy "Unmounting Filesystems" stat_done # Kill non-root encrypted partition mappings -if [[ -f /etc/crypttab ]]; then +if [[ -f /etc/crypttab && $CS ]]; then stat_busy "Deactivating encrypted volumes:" - # Arch cryptsetup packages traditionally contained the binaries - # /usr/sbin/cryptsetup - # /sbin/cryptsetup.static - # By default, initscripts used the /sbin/cryptsetup.static. - # Newer packages will only have /sbin/cryptsetup and no static binary - # This ensures maximal compatibility with the old and new layout - for CS in /sbin/cryptsetup /usr/sbin/cryptsetup \ - /sbin/cryptsetup.static ''; do - [[ -x $CS ]] && break - done - if [[ ! $CS ]]; then - stat_append " Failed, unable to find cryptsetup." - stat_fail - else - while read name src passwd opts; do - [[ ! $name || ${name:0:1} = '#']] && continue - [[ -b /dev/mapper/$name ]] || continue - stat_append "${1}.." - if "$CS" remove "$name" >/dev/null 2>&1; then - stat_append "ok " - else - stat_append "failed " - fi - done </etc/crypttab - fi + do_lock() { + stat_append "${1}.." + if $CS remove "$1" >/dev/null 2>&1; then + stat_append "ok " + else + stat_append "failed " + fi + } + read_crypttab do_lock stat_done fi diff --git a/rc.sysinit b/rc.sysinit index 404e11a..d54b9bb 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -127,104 +127,55 @@ if [[ -f /etc/mdadm.conf ]] && /bin/grep -q ^ARRAY /etc/mdadm.conf; then status "Activating RAID arrays" /sbin/mdadm --assemble --scan fi -if [ "$USELVM" = "yes" -o "$USELVM" = "YES" ]; then - if [ -x /sbin/lvm -a -d /sys/block ]; then - # Kernel 2.6.x, LVM2 groups - /sbin/modprobe -q dm-mod 2>/dev/null - stat_busy "Activating LVM2 groups" - /sbin/lvm vgchange --ignorelockingfailure -a y >/dev/null - if [ $? -ne 0 ]; then - stat_fail - else - stat_done - fi - fi -fi +activate_vgs # Set up non-root encrypted partition mappings -if [ -f /etc/crypttab -a -n "$(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$)" ]; then - /sbin/modprobe -q dm-mod 2>/dev/null +if [[ -f /etc/crypttab && $CS ]]; then + /sbin/modprobe -q dm-crypt 2>/dev/null stat_busy "Unlocking encrypted volumes:" - csfailed=0 - # Arch cryptsetup packages traditionally contained the binaries - # /usr/sbin/cryptsetup - # /sbin/cryptsetup.static - # By default, initscripts used the /sbin/cryptsetup.static. - # Newer packages will only have /sbin/cryptsetup and no static binary - # This ensures maximal compatibility with the old and new layout - if [ -x /sbin/cryptsetup ]; then - CS=/sbin/cryptsetup - elif [ -x /usr/sbin/cryptsetup ]; then - CS=/usr/sbin/cryptsetup - else - CS=/sbin/cryptsetup.static - fi - do_crypt() { - if [ $# -ge 3 ]; then - cname="$1" - csrc="$2" - cpass="$3" - shift 3 - copts="$*" - stat_append "${cname}.." - # For some fun reason, the parameter ordering varies for - # LUKS and non-LUKS devices. Joy. - if [ "${cpass}" = "SWAP" ]; then - # This is DANGEROUS! The only possible safety check - # is to not proceed in case we find a LUKS device - # This may cause dataloss if it is not used carefully - if $CS isLuks $csrc 2>/dev/null; then - false - else - $CS -d /dev/urandom $copts create $cname $csrc >/dev/null - if [ $? -eq 0 ]; then - stat_append "creating swapspace.." - /sbin/mkswap -f -L $cname /dev/mapper/$cname >/dev/null - fi - fi - elif [ "${cpass}" = "ASK" ]; then - printf "\nOpening '${cname}' volume:\n" - - if $CS isLuks $csrc 2>/dev/null; then - $CS $copts luksOpen $csrc $cname < /dev/console - else - $CS $copts create $cname $csrc < /dev/console - fi - elif [ "${cpass:0:1}" != "/" ]; then - if $CS isLuks $csrc 2>/dev/null; then - echo "$cpass" | $CS $copts luksOpen $csrc $cname >/dev/null - else - echo "$cpass" | $CS $copts create $cname $csrc >/dev/null - fi - else - if $CS isLuks $csrc 2>/dev/null; then - $CS -d $cpass $copts luksOpen $csrc $cname >/dev/null - else - $CS -d $cpass $copts create $cname $csrc >/dev/null - fi - fi - if [ $? -ne 0 ]; then - csfailed=1 - stat_append "failed " - else - stat_append "ok " - fi - fi - } - while read line; do - eval do_crypt "$line" - done </etc/crypttab - if [ $csfailed -eq 0 ]; then + do_unlock() { + # $1 = requested name + # $2 = source device + # $3 = password + # $4 = options + local open=create a="$1" b="$2" failed=0 + # Ordering of options is different if you are using LUKS vs. not. + # Use ugly swizzling to deal with it. + if $CS isLuks "$2"; then + open=luksOpen + a="$2" + b="$1" + fi + case $3 in + SWAP) if [[ $_isluks ]]; then + # This is DANGEROUS! The only possible safety check + # is to not proceed in case we find a LUKS device + # This may cause dataloss if it is not used carefully + false + elif $CS -d /dev/urandom $4 $open "$a" "$b" >/dev/null; then + stat_append "creating swapspace.." + /sbin/mkswap -f -L $1 /dev/mapper/$1 >/dev/null + fi;; + ASK) printf "\nOpening '$1' volume:\n" + $CS $4 $open "$a" "$b" < /dev/console;; + /*) $CS -d "$3" $4 $open "$a" "$b" >/dev/null;; + *) echo "$3" | $CS $4 $open "$a" "$b" >/dev/null;; + esac + if (($? != 0)); then + failed=1 + stat_append "failed " + else + stat_append "ok " + fi + return $failed + } + if read_crypttab do_unlock; then stat_done else stat_fail fi # Maybe someone has LVM on an encrypted block device - if [ "$USELVM" = "yes" -o "$USELVM" = "YES" ]; then - if [ -x /sbin/lvm -a -d /sys/block ]; then - /sbin/lvm vgchange --ignorelockingfailure -a y >/dev/null - fi - fi + activate_vgs fi status "Mounting Root Read-only" /bin/mount -n -o remount,ro / -- 1.7.1
Am 30.06.2010 23:47, schrieb Victor Lowther:
Split out reading /etc/crypttab and procssing the individual lines into their own helper functions, and bashify the resulting shorter code.
Processing this file is still ugly, though. :(
I wanted to factor this out and deprecate crypttab for a long time. This is a good first step. However, there are still things in this commit that do not belong there, again. While your work here is appreciated, and I am looking forward to applying most (all?) of it, you will probably have to re-do many of the commit due to these errors. I'll stop reviewing now and continue with 33-48 tomorrow.
On Thu, 2010-07-01 at 00:16 +0200, Thomas Bächler wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
Split out reading /etc/crypttab and procssing the individual lines into their own helper functions, and bashify the resulting shorter code.
Processing this file is still ugly, though. :(
I wanted to factor this out and deprecate crypttab for a long time. This is a good first step.
Danke.
However, there are still things in this commit that do not belong there, again. While your work here is appreciated, and I am looking forward to applying most (all?) of it, you will probably have to re-do many of the commit due to these errors.
No problem, I got a little crazier with the ol' git rebase than I should have.
I'll stop reviewing now and continue with 33-48 tomorrow.
I look forward to it. -- Victor Lowther LPIC2 UCP RHCE
--- rc.sysinit | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 5842a57..c6ed35f 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -303,12 +303,12 @@ status "Updating Module Dependencies" /sbin/depmod -A : >| /etc/profile.d/locale.sh /bin/chmod 755 /etc/profile.d/locale.sh # Set user defined locale -[ -z "$LOCALE" ] && LOCALE="en_US" +[[ $LOCALE ]] || LOCALE="en_US" stat_busy "Setting Locale: $LOCALE" echo "export LANG=$LOCALE" >>/etc/profile.d/locale.sh stat_done -if echo "$LOCALE" | /bin/grep -qi utf ; then +if [[ $LOCALE =~ utf|UTF ]]; then stat_busy "Setting Consoles to UTF-8 mode" # UTF-8 consoles are default since 2.6.24 kernel # this code is needed not only for older kernels, @@ -318,9 +318,11 @@ if echo "$LOCALE" | /bin/grep -qi utf ; then printf "\033%%G" > ${i} done # the $CONSOLE check helps us avoid this when running scripts from cron - echo 'if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033%%G"; fi' >>/etc/profile.d/locale.sh + cat <<"EOF" >>/etc/profile.d/locale.sh +if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033%%G"; fi +EOF stat_done - [ -n "$KEYMAP" ] && status "Loading Keyboard Map: $KEYMAP" /bin/loadkeys -q -u $KEYMAP + [[ $KEYMAP ]] && status "Loading Keyboard Map: $KEYMAP" /bin/loadkeys -q -u "$KEYMAP" else stat_busy "Setting Consoles to legacy mode" # make non-UTF-8 consoles work on 2.6.24 and newer kernels @@ -329,9 +331,11 @@ else printf "\033%%@" > ${i} done # the $CONSOLE check helps us avoid this when running scripts from cron - echo 'if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033%%@"; fi' >>/etc/profile.d/locale.sh + cat <<"EOF" >>/etc/profile.d/locale.sh +if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033%%@"; fi +EOF stat_done - [ -n "$KEYMAP" ] && status "Loading Keyboard Map: $KEYMAP" /bin/loadkeys -q $KEYMAP + [[ $KEYMAP ]] && status "Loading Keyboard Map: $KEYMAP" /bin/loadkeys -q $KEYMAP fi # Set console font if required -- 1.7.1
This patch should be split into two: Am 30.06.2010 23:47, schrieb Victor Lowther:
diff --git a/rc.sysinit b/rc.sysinit index 5842a57..c6ed35f 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -303,12 +303,12 @@ status "Updating Module Dependencies" /sbin/depmod -A : >| /etc/profile.d/locale.sh /bin/chmod 755 /etc/profile.d/locale.sh # Set user defined locale -[ -z "$LOCALE" ] && LOCALE="en_US" +[[ $LOCALE ]] || LOCALE="en_US" stat_busy "Setting Locale: $LOCALE" echo "export LANG=$LOCALE" >>/etc/profile.d/locale.sh stat_done
-if echo "$LOCALE" | /bin/grep -qi utf ; then +if [[ $LOCALE =~ utf|UTF ]]; then stat_busy "Setting Consoles to UTF-8 mode" # UTF-8 consoles are default since 2.6.24 kernel # this code is needed not only for older kernels,
Simple bashification.
@@ -318,9 +318,11 @@ if echo "$LOCALE" | /bin/grep -qi utf ; then printf "\033%%G" > ${i} done # the $CONSOLE check helps us avoid this when running scripts from cron - echo 'if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033%%G"; fi' >>/etc/profile.d/locale.sh + cat <<"EOF" >>/etc/profile.d/locale.sh +if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033%%G"; fi +EOF
This has nothing to do with bashification, this is a readability improvement. Same applies below. Either merge the bashifications into the "big one" and apply the readability changes separately, or leave it like this, but adjust the commit message. Same applies below.
stat_done - [ -n "$KEYMAP" ] && status "Loading Keyboard Map: $KEYMAP" /bin/loadkeys -q -u $KEYMAP + [[ $KEYMAP ]] && status "Loading Keyboard Map: $KEYMAP" /bin/loadkeys -q -u "$KEYMAP" else stat_busy "Setting Consoles to legacy mode" # make non-UTF-8 consoles work on 2.6.24 and newer kernels @@ -329,9 +331,11 @@ else printf "\033%%@" > ${i} done # the $CONSOLE check helps us avoid this when running scripts from cron - echo 'if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033%%@"; fi' >>/etc/profile.d/locale.sh + cat <<"EOF" >>/etc/profile.d/locale.sh +if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033%%@"; fi +EOF stat_done - [ -n "$KEYMAP" ] && status "Loading Keyboard Map: $KEYMAP" /bin/loadkeys -q $KEYMAP + [[ $KEYMAP ]] && status "Loading Keyboard Map: $KEYMAP" /bin/loadkeys -q $KEYMAP fi
# Set console font if required
--- rc.sysinit | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 91ee03a..319ea60 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -243,13 +243,13 @@ stat_done status "Activating Swap" /sbin/swapon -a stat_busy "Configuring System Clock" -if [ "$TIMEZONE" != "" -a -e "/usr/share/zoneinfo/$TIMEZONE" ]; then +if [[ $TIMEZONE && -e /usr/share/zoneinfo/$TIMEZONE ]]; then /bin/rm -f /etc/localtime /bin/cp "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime fi clock_pid="" -if [ -n "$HWCLOCK_PARAMS" ]; then +if [[ $HWCLOCK_PARAMS ]]; then # This time, we set the clock for real. Use the adjustment file now that # /var will definitely be available, and then set the system clock once # the hardware clock has been adjusted accordingly. The backgrounding magic -- 1.7.1
--- rc.sysinit | 16 ++++++---------- 1 files changed, 6 insertions(+), 10 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index c6ed35f..ac32fca 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -342,16 +342,12 @@ fi set_consolefont # Adding persistent network/cdrom generated rules -if [ -f "/dev/.udev/tmp-rules--70-persistent-cd.rules" ]; then - stat_busy "Adding persistent cdrom udev rules" - /bin/cat /dev/.udev/tmp-rules--70-persistent-cd.rules >> /etc/udev/rules.d/70-persistent-cd.rules - stat_done -fi -if [ -f "/dev/.udev/tmp-rules--70-persistent-net.rules" ]; then - stat_busy "Adding persistent network udev rules" - /bin/cat /dev/.udev/tmp-rules--70-persistent-net.rules >> /etc/udev/rules.d/70-persistent-net.rules - stat_done -fi +for f in cd net; do + [[ -f /dev/.udev/tmp-rules--70-persistent-$f.rules ]] || continue + stat_busy "Adding persistent $f udev rules" + /bin/cat "/dev/.udev/tmp-rules--70-persistent-$f.rules" >> "/etc/udev/rules.d/70-persistent-$f.rules" + stat_done +done /bin/dmesg >| /var/log/dmesg.log -- 1.7.1
Am 30.06.2010 23:47, schrieb Victor Lowther:
--- rc.sysinit | 16 ++++++---------- 1 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index c6ed35f..ac32fca 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -342,16 +342,12 @@ fi set_consolefont
# Adding persistent network/cdrom generated rules -if [ -f "/dev/.udev/tmp-rules--70-persistent-cd.rules" ]; then - stat_busy "Adding persistent cdrom udev rules" - /bin/cat /dev/.udev/tmp-rules--70-persistent-cd.rules >> /etc/udev/rules.d/70-persistent-cd.rules - stat_done -fi -if [ -f "/dev/.udev/tmp-rules--70-persistent-net.rules" ]; then - stat_busy "Adding persistent network udev rules" - /bin/cat /dev/.udev/tmp-rules--70-persistent-net.rules >> /etc/udev/rules.d/70-persistent-net.rules - stat_done -fi +for f in cd net; do + [[ -f /dev/.udev/tmp-rules--70-persistent-$f.rules ]] || continue + stat_busy "Adding persistent $f udev rules" + /bin/cat "/dev/.udev/tmp-rules--70-persistent-$f.rules" >> "/etc/udev/rules.d/70-persistent-$f.rules" + stat_done +done
/bin/dmesg >| /var/log/dmesg.log
ACKed
--- netfs | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-) diff --git a/netfs b/netfs index cdfdf98..d4a926f 100755 --- a/netfs +++ b/netfs @@ -12,8 +12,7 @@ case "$1" in /bin/mount -a -t nfs,nfs4,smbfs,codafs,ncpfs,cifs,shfs,glusterfs,fuse,fuseblk,fuse.glusterfs rc=$? /bin/mount -a -O _netdev - rc=$(($rc+$?)) - if [ $rc -gt 0 ]; then + if ((rc + $? > 0)); then stat_fail else add_daemon netfs @@ -25,8 +24,7 @@ case "$1" in /bin/umount -a -O _netdev rc=$? /bin/umount -a -t nfs,nfs4,smbfs,codafs,ncpfs,cifs,shfs,glusterfs,fuse,fuseblk,fuse.glusterfs - rc=$(($rc+$?)) - if [ $rc -gt 0 ]; then + if ((rc + $? > 0)); then stat_fail else rm_daemon netfs -- 1.7.1
--- rc.sysinit | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index d54b9bb..91ee03a 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -181,7 +181,7 @@ fi status "Mounting Root Read-only" /bin/mount -n -o remount,ro / FORCEFSCK= -[ -f /forcefsck ] && FORCEFSCK="-- -f" +[[ -f /forcefsck ]] && FORCEFSCK="-- -f" NETFS="nonfs,nonfs4,nosmbfs,nocifs,nocodafs,noncpfs,nosysfs,noshfs,nofuse,nofuseblk,noglusterfs" fsck_reboot() { @@ -192,7 +192,7 @@ fsck_reboot() { exit 0 } -if [ -x /sbin/fsck ]; then +if [[ -x /sbin/fsck ]]; then stat_busy "Checking Filesystems" FSCK_OUT=/dev/stdout FSCK_ERR=/dev/stdout @@ -200,11 +200,11 @@ if [ -x /sbin/fsck ]; then run_hook sysinit_prefsck /sbin/fsck -A -T -C$FSCK_FD -a -t "$NETFS,noopts=_netdev" $FORCEFSCK >$FSCK_OUT 2>$FSCK_ERR fsckret=$? - if [ ${fsckret} -gt 1 ]; then + if ((fsckret > 1)); then stat_fail fi run_hook sysinit_postfsck - if [ $((${fsckret}&2)) -eq 2 ]; then + if (( ( fsckret & 2) == 2)); then echo echo "********************** REBOOT REQUIRED *********************" echo "* *" @@ -214,8 +214,7 @@ if [ -x /sbin/fsck ]; then echo /bin/sleep 15 fsck_reboot - fi - if [ ${fsckret} -gt 1 -a ${fsckret} -ne 32 ]; then + elif ((fsckret > 1 && fsckret != 32)); then echo echo "***************** FILESYSTEM CHECK FAILED ****************" echo "* *" -- 1.7.1
Am 30.06.2010 23:47, schrieb Victor Lowther:
--- rc.sysinit | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-)
This is one of those patches with no logic changes and just sh->bash conversion that should be part of the big one.
--- rc.sysinit | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 037a9f2..217dacf 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -265,7 +265,7 @@ fi stat_done RANDOM_SEED=/var/lib/misc/random-seed -if [ -f $RANDOM_SEED ]; then +if [[ -f $RANDOM_SEED ]]; then stat_busy "Initializing Random Seed" /bin/cat $RANDOM_SEED > /dev/urandom stat_done -- 1.7.1
--- rc.sysinit | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 217dacf..5842a57 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -287,14 +287,14 @@ stat_done #status "Updating Shared Library Links" /sbin/ldconfig -if [ "$HOSTNAME" != "" ]; then - status "Setting Hostname: $HOSTNAME" /bin/hostname $HOSTNAME +if [[ $HOSTNAME ]]; then + status "Setting Hostname: $HOSTNAME" /bin/hostname "$HOSTNAME" fi # Set the NIS domain name, if necessary -[ -f /etc/conf.d/nisdomainname ] && . /etc/conf.d/nisdomainname -if [ "$NISDOMAINNAME" != "" ]; then - status "Setting NIS Domain Name: $NISDOMAINNAME" /bin/nisdomainname $NISDOMAINNAME +[[ -f /etc/conf.d/nisdomainname ]] && . /etc/conf.d/nisdomainname +if [[ $NISDOMAINNAME ]]; then + status "Setting NIS Domain Name: $NISDOMAINNAME" /bin/nisdomainname "$NISDOMAINNAME" fi status "Updating Module Dependencies" /sbin/depmod -A -- 1.7.1
--- rc.sysinit | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/rc.sysinit b/rc.sysinit index 319ea60..037a9f2 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -277,7 +277,7 @@ stat_busy "Removing Leftover Files" /bin/rm -f /var/lock/* &>/dev/null /bin/rm -rf /tmp/* /tmp/.* &>/dev/null /bin/rm -f /forcefsck &>/dev/null -(cd /var/run && /usr/bin/find . ! -type d -exec /bin/rm -f -- {} \; ) +(cd /var/run && /usr/bin/find . \! -type d -delete ) : >| /var/run/utmp /bin/chmod 0664 /var/run/utmp # Keep {x,k,g}dm happy with xorg -- 1.7.1
On Wed, Jun 30, 2010 at 17:47, Victor Lowther <victor.lowther@gmail.com> wrote:
--- rc.sysinit | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index 319ea60..037a9f2 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -277,7 +277,7 @@ stat_busy "Removing Leftover Files" /bin/rm -f /var/lock/* &>/dev/null /bin/rm -rf /tmp/* /tmp/.* &>/dev/null /bin/rm -f /forcefsck &>/dev/null -(cd /var/run && /usr/bin/find . ! -type d -exec /bin/rm -f -- {} \; ) +(cd /var/run && /usr/bin/find . \! -type d -delete ) : >| /var/run/utmp /bin/chmod 0664 /var/run/utmp # Keep {x,k,g}dm happy with xorg -- 1.7.1
I don't think this is portable though.
On Wed, 2010-06-30 at 17:58 -0400, Daenyth Blank wrote:
On Wed, Jun 30, 2010 at 17:47, Victor Lowther <victor.lowther@gmail.com> wrote:
--- rc.sysinit | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index 319ea60..037a9f2 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -277,7 +277,7 @@ stat_busy "Removing Leftover Files" /bin/rm -f /var/lock/* &>/dev/null /bin/rm -rf /tmp/* /tmp/.* &>/dev/null /bin/rm -f /forcefsck &>/dev/null -(cd /var/run && /usr/bin/find . ! -type d -exec /bin/rm -f -- {} \; ) +(cd /var/run && /usr/bin/find . \! -type d -delete ) : >| /var/run/utmp /bin/chmod 0664 /var/run/utmp # Keep {x,k,g}dm happy with xorg -- 1.7.1
I don't think this is portable though.
How portable are you looking for? -- Victor Lowther LPIC2 UCP RHCE
Am 30.06.2010 23:58, schrieb Daenyth Blank:
On Wed, Jun 30, 2010 at 17:47, Victor Lowther <victor.lowther@gmail.com> wrote:
--- rc.sysinit | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index 319ea60..037a9f2 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -277,7 +277,7 @@ stat_busy "Removing Leftover Files" /bin/rm -f /var/lock/* &>/dev/null /bin/rm -rf /tmp/* /tmp/.* &>/dev/null /bin/rm -f /forcefsck &>/dev/null -(cd /var/run && /usr/bin/find . ! -type d -exec /bin/rm -f -- {} \; ) +(cd /var/run && /usr/bin/find . \! -type d -delete ) : >| /var/run/utmp /bin/chmod 0664 /var/run/utmp # Keep {x,k,g}dm happy with xorg -- 1.7.1
I don't think this is portable though.
Portability is not an issue. The beauty about this is that we can simply assume we have GNU tools and we do use Linux ... because that is what Arch is based on. I have no problem having GNU-specific features in there, as we can rely on GNU find (or GNU whatever) being present. The only exception is initramfs - however, no shell script is used in both the system and initramfs.
On Wed, Jun 30, 2010 at 5:32 PM, Thomas Bächler <thomas@archlinux.org> wrote:
Am 30.06.2010 23:58, schrieb Daenyth Blank:
On Wed, Jun 30, 2010 at 17:47, Victor Lowther <victor.lowther@gmail.com> wrote:
--- rc.sysinit | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index 319ea60..037a9f2 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -277,7 +277,7 @@ stat_busy "Removing Leftover Files" /bin/rm -f /var/lock/* &>/dev/null /bin/rm -rf /tmp/* /tmp/.* &>/dev/null /bin/rm -f /forcefsck &>/dev/null -(cd /var/run && /usr/bin/find . ! -type d -exec /bin/rm -f -- {} \; ) +(cd /var/run && /usr/bin/find . \! -type d -delete ) : >| /var/run/utmp /bin/chmod 0664 /var/run/utmp # Keep {x,k,g}dm happy with xorg -- 1.7.1
I don't think this is portable though.
Portability is not an issue. The beauty about this is that we can simply assume we have GNU tools and we do use Linux ... because that is what Arch is based on.
Exactly.
I have no problem having GNU-specific features in there, as we can rely on GNU find (or GNU whatever) being present. The only exception is initramfs - however, no shell script is used in both the system and initramfs
That is one reason I helped write and use dracut (the new initramfs generation framework that Fedora 12 and 13 use, and that RHEL6 will use) -- instead of using busybox/klobc/whatever, it trades a slightly larger initramfs for the convienence of using exactly the same binaries the installed system uses for everything. I will happily trade a few hundred K larger initramfs for not having to maintain another toolchain and userspace just for the initramfs.
Am 01.07.2010 00:40, schrieb Victor Lowther:
I have no problem having GNU-specific features in there, as we can rely on GNU find (or GNU whatever) being present. The only exception is initramfs - however, no shell script is used in both the system and initramfs
That is one reason I helped write and use dracut (the new initramfs generation framework that Fedora 12 and 13 use, and that RHEL6 will use) -- instead of using busybox/klobc/whatever, it trades a slightly larger initramfs for the convienence of using exactly the same binaries the installed system uses for everything. I will happily trade a few hundred K larger initramfs for not having to maintain another toolchain and userspace just for the initramfs.
Well, it's basically what I did in mkinitcpio 0.6. I dumped klibc and all the packages that used it in favor of pure glibc binaries. However, I still use busybox instead of util-linux-ng and coreutils: It is much more convenient to just run "busybox --install -s" and have a fully functional environment than having to collect all the basic tools and make sure they are installed. The maintenance effort for busybox is almost nonexistent, and it offers many tools that you wouldn't install into initramfs otherwise. I am convinced that this is the best of both worlds, I get a feature-rich and very very small initramfs environment this way. Anyway, this is OT in this thread and we probably shouldn't pollute it with this discussion.
On Wed, Jun 30, 2010 at 18:32, Thomas Bächler <thomas@archlinux.org> wrote:
Am 30.06.2010 23:58, schrieb Daenyth Blank:
I don't think this is portable though.
Portability is not an issue. The beauty about this is that we can simply assume we have GNU tools and we do use Linux ... because that is what Arch is based on.
Oh duh, I was thinking of makepkg et al which we want to be portable. Carry on
Am 30.06.2010 23:47, schrieb Victor Lowther:
--- rc.sysinit | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/rc.sysinit b/rc.sysinit index 319ea60..037a9f2 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -277,7 +277,7 @@ stat_busy "Removing Leftover Files" /bin/rm -f /var/lock/* &>/dev/null /bin/rm -rf /tmp/* /tmp/.* &>/dev/null /bin/rm -f /forcefsck &>/dev/null -(cd /var/run && /usr/bin/find . ! -type d -exec /bin/rm -f -- {} \; ) +(cd /var/run && /usr/bin/find . \! -type d -delete ) : >| /var/run/utmp /bin/chmod 0664 /var/run/utmp # Keep {x,k,g}dm happy with xorg
ACKed.
--- functions | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/functions b/functions index 9ec8b5e..f1dce8a 100644 --- a/functions +++ b/functions @@ -4,6 +4,10 @@ # width: +grep -q initdebug && { + exec 2>/dev/tty9 +} + STAT_COL=80 if [[ ! -t 1 ]]; then USECOLOR="" -- 1.7.1
Am 2010-06-30 23:47, schrieb Victor Lowther:
--- functions | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/functions b/functions index 9ec8b5e..f1dce8a 100644 --- a/functions +++ b/functions @@ -4,6 +4,10 @@
# width:
+grep -q initdebug&& { + exec 2>/dev/tty9 +} +
Hmm, won't this cause a read from stdin when starting/stopping daemons manually in a terminal?
STAT_COL=80 if [[ ! -t 1 ]]; then USECOLOR=""
On Jul 2, 2010, at 4:48 AM, "Kurt J. Bosch" <kjb- temp-2009@alpenjodel.de> wrote:
Am 2010-06-30 23:47, schrieb Victor Lowther:
--- functions | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/functions b/functions index 9ec8b5e..f1dce8a 100644 --- a/functions +++ b/functions @@ -4,6 +4,10 @@
# width:
+grep -q initdebug&& { + exec 2>/dev/tty9 +} +
Hmm, won't this cause a read from stdin when starting/stopping daemons manually in a terminal?
It gets fixed in the next patch.
STAT_COL=80 if [[ ! -t 1 ]]; then USECOLOR=""
Am 30.06.2010 23:47, schrieb Victor Lowther:
--- functions | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/functions b/functions index 9ec8b5e..f1dce8a 100644 --- a/functions +++ b/functions @@ -4,6 +4,10 @@
# width:
+grep -q initdebug && { + exec 2>/dev/tty9 +} + STAT_COL=80 if [[ ! -t 1 ]]; then USECOLOR=""
Apart from Kurt's comment: Won't this cause errors to be omitted from the console? I'd much rather implement a full boot logging using bootlogd, but last time I tried, it was broken. Redirecting stderr away from the normal output seems unhelpful, and unecessary. I'd much rather omit this in favor of a patch that adds proper boot logging, which is a feature we really need.
On Fri, 2010-07-16 at 14:09 +0200, Thomas Bächler wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
--- functions | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/functions b/functions index 9ec8b5e..f1dce8a 100644 --- a/functions +++ b/functions @@ -4,6 +4,10 @@
# width:
+grep -q initdebug && { + exec 2>/dev/tty9 +} + STAT_COL=80 if [[ ! -t 1 ]]; then USECOLOR=""
Apart from Kurt's comment:
Won't this cause errors to be omitted from the console? I'd much rather implement a full boot logging using bootlogd, but last time I tried, it was broken. Redirecting stderr away from the normal output seems unhelpful, and unecessary.
The intent was to redirect the errors to be redirected to tty9 -- when I was debugging these scripts, syntax errors kept getting nuked by the gettys and X starting up, so putting them on a tty that was not running a getty seemed like the easiest solution.
I'd much rather omit this in favor of a patch that adds proper boot logging, which is a feature we really need.
No problem. The bashification-redux branch @ git://fnordovax.org/~victor/arch-initscripts has this as the last patch to make it easy to drop. -- Victor Lowther LPIC2 UCP RHCE
This builds straight out of a git checkout. --- PKGBUILD | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-) diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..79b3403 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,23 @@ +pkgname=initscripts-git +pkgver=$(date +%s) +pkgrel=$(git log --pretty=format:%h |head -n 1) +pkgdesc="System initialization/bootup scripts" +arch=('i686' 'x86_64') +url="http://www.archlinux.org" +license=('GPL') +groups=('base') +conflicts=('initscripts') +provides=('initscripts=9999') +backup=(etc/inittab etc/rc.conf etc/rc.local etc/rc.local.shutdown) +depends=('glibc' 'bash' 'awk' 'grep' 'coreutils' 'sed' 'udev>=139-1' + 'net-tools' 'ncurses' 'kbd' 'findutils' 'sysvinit') +optdepends=('bridge-utils: Network bridging support' + 'dhcpcd: DHCP network configuration' + 'wireless_tools: Wireless networking') +source=() +sha256sums=() + +build() { + cd .. + DESTDIR=${pkgdir} ./install.sh +} -- 1.7.1
Am 30.06.2010 23:47, schrieb Victor Lowther:
This builds straight out of a git checkout. --- PKGBUILD | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..79b3403 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,23 @@ +pkgname=initscripts-git +pkgver=$(date +%s) +pkgrel=$(git log --pretty=format:%h |head -n 1) +pkgdesc="System initialization/bootup scripts" +arch=('i686' 'x86_64') +url="http://www.archlinux.org" +license=('GPL') +groups=('base') +conflicts=('initscripts') +provides=('initscripts=9999') +backup=(etc/inittab etc/rc.conf etc/rc.local etc/rc.local.shutdown) +depends=('glibc' 'bash' 'awk' 'grep' 'coreutils' 'sed' 'udev>=139-1' + 'net-tools' 'ncurses' 'kbd' 'findutils' 'sysvinit') +optdepends=('bridge-utils: Network bridging support' + 'dhcpcd: DHCP network configuration' + 'wireless_tools: Wireless networking') +source=() +sha256sums=() + +build() { + cd .. + DESTDIR=${pkgdir} ./install.sh +}
Not necessary IMO, but nice to have. Should come with a .gitignore patch that adds '*pkg.tar.*'.
On Fri, 2010-07-16 at 14:06 +0200, Thomas Bächler wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
This builds straight out of a git checkout. --- PKGBUILD | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..79b3403 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,23 @@ +pkgname=initscripts-git +pkgver=$(date +%s) +pkgrel=$(git log --pretty=format:%h |head -n 1) +pkgdesc="System initialization/bootup scripts" +arch=('i686' 'x86_64') +url="http://www.archlinux.org" +license=('GPL') +groups=('base') +conflicts=('initscripts') +provides=('initscripts=9999') +backup=(etc/inittab etc/rc.conf etc/rc.local etc/rc.local.shutdown) +depends=('glibc' 'bash' 'awk' 'grep' 'coreutils' 'sed' 'udev>=139-1' + 'net-tools' 'ncurses' 'kbd' 'findutils' 'sysvinit') +optdepends=('bridge-utils: Network bridging support' + 'dhcpcd: DHCP network configuration' + 'wireless_tools: Wireless networking') +source=() +sha256sums=() + +build() { + cd .. + DESTDIR=${pkgdir} ./install.sh +}
Not necessary IMO, but nice to have. Should come with a .gitignore patch that adds '*pkg.tar.*'.
It is nice to have -- being able to makepkg && sudo pacman -U inits*.tar.* sure does make it easier to test things. Why do you think a .gitignore patch is needed? Unless someone does something silly like adding the tarball to the git repo git will ignore it anyways. -- Victor Lowther LPIC2 UCP RHCE
Am 17.07.2010 16:13, schrieb Victor Lowther:
Why do you think a .gitignore patch is needed? Unless someone does something silly like adding the tarball to the git repo git will ignore it anyways.
You want to keep "git status" clean, especially with __git_ps1. If there is nothing changed/to commit, I want to see a clean "git status" output.
On Sat, 2010-07-17 at 16:34 +0200, Thomas Bächler wrote:
Am 17.07.2010 16:13, schrieb Victor Lowther:
Why do you think a .gitignore patch is needed? Unless someone does something silly like adding the tarball to the git repo git will ignore it anyways.
You want to keep "git status" clean, especially with __git_ps1. If there is nothing changed/to commit, I want to see a clean "git status" output.
Huh. I guess I have never used git status before. -- Victor Lowther LPIC2 UCP RHCE
pkgrel=$(git rev-parse --short HEAD) much simpler. On Wed, Jun 30, 2010 at 11:47 PM, Victor Lowther <victor.lowther@gmail.com> wrote:
This builds straight out of a git checkout. --- PKGBUILD | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..79b3403 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,23 @@ +pkgname=initscripts-git +pkgver=$(date +%s) +pkgrel=$(git log --pretty=format:%h |head -n 1) +pkgdesc="System initialization/bootup scripts" +arch=('i686' 'x86_64') +url="http://www.archlinux.org" +license=('GPL') +groups=('base') +conflicts=('initscripts') +provides=('initscripts=9999') +backup=(etc/inittab etc/rc.conf etc/rc.local etc/rc.local.shutdown) +depends=('glibc' 'bash' 'awk' 'grep' 'coreutils' 'sed' 'udev>=139-1' + 'net-tools' 'ncurses' 'kbd' 'findutils' 'sysvinit') +optdepends=('bridge-utils: Network bridging support' + 'dhcpcd: DHCP network configuration' + 'wireless_tools: Wireless networking') +source=() +sha256sums=() + +build() { + cd .. + DESTDIR=${pkgdir} ./install.sh +} -- 1.7.1
--- adjtime.cron | 16 +++++++--------- 1 files changed, 7 insertions(+), 9 deletions(-) diff --git a/adjtime.cron b/adjtime.cron index b1c8950..a876506 100755 --- a/adjtime.cron +++ b/adjtime.cron @@ -4,14 +4,12 @@ . /etc/rc.conf HWCLOCK_PARAMS="--adjust" -if [ "$HARDWARECLOCK" = "UTC" ]; then - HWCLOCK_PARAMS="$HWCLOCK_PARAMS --utc" -elif [ "$HARDWARECLOCK" = "localtime" ]; then - HWCLOCK_PARAMS="$HWCLOCK_PARAMS --localtime" -else - HWCLOCK_PARAMS="" -fi +case $HARDWARECLOCK in + UTC) HWCLOCK_PARAMS+=" --utc";; + localtime) HWCLOCK_PARAMS+=" --localtime";; + *) HWCLOCK_PARAMS="";; +esac -if [ -n "$HWCLOCK_PARAMS" ]; then - /sbin/hwclock $HWCLOCK_PARAMS +if [[ $HWCLOCK_PARAMS ]]; then + /sbin/hwclock $HWCLOCK_PARAMS fi -- 1.7.1
--- functions | 2 +- rc.shutdown | 3 +++ 2 files changed, 4 insertions(+), 1 deletions(-) diff --git a/functions b/functions index f1dce8a..2c80a59 100644 --- a/functions +++ b/functions @@ -4,7 +4,7 @@ # width: -grep -q initdebug && { +grep -q initdebug /proc/cmdline && { exec 2>/dev/tty9 } diff --git a/rc.shutdown b/rc.shutdown index 1081970..96b10f0 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -93,6 +93,9 @@ run_hook shutdown_poweroff # Power off or reboot printsep + +grep -q initdebug /proc/cmdline && sleep 9999 + if [[ $RUNLEVEL = 0 ]]; then printhl "${C_H2}POWER OFF" /sbin/poweroff -d -f -h -i -- 1.7.1
Am 2010-06-30 23:47, schrieb Victor Lowther:
--- functions | 2 +- rc.shutdown | 3 +++ 2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/functions b/functions index f1dce8a..2c80a59 100644 --- a/functions +++ b/functions @@ -4,7 +4,7 @@
# width:
-grep -q initdebug&& { +grep -q initdebug /proc/cmdline&& { exec 2>/dev/tty9 }
OK that fixes the stdin problem :) - but /proc won't be mounted when this is sourced in rc.sysinit if someone doesn't use an initcpio.
diff --git a/rc.shutdown b/rc.shutdown index 1081970..96b10f0 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -93,6 +93,9 @@ run_hook shutdown_poweroff
# Power off or reboot printsep + +grep -q initdebug /proc/cmdline&& sleep 9999 + if [[ $RUNLEVEL = 0 ]]; then printhl "${C_H2}POWER OFF" /sbin/poweroff -d -f -h -i
On Fri, 2010-07-02 at 11:56 +0200, Kurt J. Bosch wrote:
Am 2010-06-30 23:47, schrieb Victor Lowther:
--- functions | 2 +- rc.shutdown | 3 +++ 2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/functions b/functions index f1dce8a..2c80a59 100644 --- a/functions +++ b/functions @@ -4,7 +4,7 @@
# width:
-grep -q initdebug&& { +grep -q initdebug /proc/cmdline&& { exec 2>/dev/tty9 }
OK that fixes the stdin problem :) - but /proc won't be mounted when this is sourced in rc.sysinit if someone doesn't use an initcpio.
True, That did not occur to me. I discovered the awesomeness of lvm too many years ago, I suppose.
diff --git a/rc.shutdown b/rc.shutdown index 1081970..96b10f0 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -93,6 +93,9 @@ run_hook shutdown_poweroff
# Power off or reboot printsep + +grep -q initdebug /proc/cmdline&& sleep 9999 + if [[ $RUNLEVEL = 0 ]]; then printhl "${C_H2}POWER OFF" /sbin/poweroff -d -f -h -i
-- Victor Lowther LPIC2 UCP RHCE
Am 30.06.2010 23:47, schrieb Victor Lowther:
--- functions | 2 +- rc.shutdown | 3 +++ 2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/functions b/functions index f1dce8a..2c80a59 100644 --- a/functions +++ b/functions @@ -4,7 +4,7 @@
# width:
-grep -q initdebug && { +grep -q initdebug /proc/cmdline && { exec 2>/dev/tty9 }
diff --git a/rc.shutdown b/rc.shutdown index 1081970..96b10f0 100755 --- a/rc.shutdown +++ b/rc.shutdown @@ -93,6 +93,9 @@ run_hook shutdown_poweroff
# Power off or reboot printsep + +grep -q initdebug /proc/cmdline && sleep 9999 + if [[ $RUNLEVEL = 0 ]]; then printhl "${C_H2}POWER OFF" /sbin/poweroff -d -f -h -i
Seems nice. I'll still omit the initdebug patches for now and rethink this, for some reason I don't like this yet.
--- network | 11 +++-------- 1 files changed, 3 insertions(+), 8 deletions(-) diff --git a/network b/network index 977e81e..242acc3 100755 --- a/network +++ b/network @@ -3,14 +3,9 @@ . /etc/rc.conf . /etc/rc.d/functions -# wireless settings -[ -f /etc/conf.d/wireless ] && . /etc/conf.d/wireless -# ethernet bonding settings -[ -f /etc/conf.d/bonding ] && . /etc/conf.d/bonding -# bridge settings -[ -f /etc/conf.d/bridges ] && . /etc/conf.d/bridges -# dhcpcd settings -[ -f /etc/conf.d/dhcpcd ] && . /etc/conf.d/dhcpcd +for s in wireless bonding bridges dhcpcd; do + [[ -f /etc/conf.d/$s ]] && . "/etc/conf.d/$s" +done ifup() { -- 1.7.1
Am 30.06.2010 23:47, schrieb Victor Lowther:
--- network | 11 +++-------- 1 files changed, 3 insertions(+), 8 deletions(-)
diff --git a/network b/network index 977e81e..242acc3 100755 --- a/network +++ b/network @@ -3,14 +3,9 @@ . /etc/rc.conf . /etc/rc.d/functions
-# wireless settings -[ -f /etc/conf.d/wireless ] && . /etc/conf.d/wireless -# ethernet bonding settings -[ -f /etc/conf.d/bonding ] && . /etc/conf.d/bonding -# bridge settings -[ -f /etc/conf.d/bridges ] && . /etc/conf.d/bridges -# dhcpcd settings -[ -f /etc/conf.d/dhcpcd ] && . /etc/conf.d/dhcpcd +for s in wireless bonding bridges dhcpcd; do + [[ -f /etc/conf.d/$s ]] && . "/etc/conf.d/$s" +done
ifup() {
ACKed.
--- network | 70 +++++++++++++++++++++++++++----------------------------------- 1 files changed, 31 insertions(+), 39 deletions(-) diff --git a/network b/network index 40f1a90..20ff9c7 100755 --- a/network +++ b/network @@ -9,17 +9,15 @@ done ifup() { - if [ "$1" = "" ]; then + if [[ ! $1 ]]; then echo "usage: $0 ifup <interface_name>" return 1 fi - eval ifcfg="\$${1}" # Get the name of the interface from the first token in the string - - if [ "$ifcfg" = "dhcp" ]; then - ifname="$1" + if [[ $ifcfg = dhcp ]]; then + ifname=$1 else ifname=${ifcfg%% *} fi @@ -28,7 +26,7 @@ ifup() wi_up $1 || return 1 - if [ "$ifcfg" = "dhcp" ]; then + if [[ $ifcfg = dhcp ]]; then # remove the .pid file if it exists /bin/rm -f /var/run/dhcpcd-${1}.pid >/dev/null 2>&1 /bin/rm -f /var/run/dhcpcd-${1}.cache >/dev/null 2>&1 @@ -36,20 +34,19 @@ ifup() else /sbin/ifconfig $ifcfg fi - return $? } wi_up() { eval iwcfg="\$wlan_${1}" - [ "$iwcfg" = "" ] && return 0 + [[ ! $iwcfg ]] && return 0 /usr/sbin/iwconfig $iwcfg - [[ -z "$WIRELESS_TIMEOUT" ]] && WIRELESS_TIMEOUT=2 + [[ $WIRELESS_TIMEOUT ]] || WIRELESS_TIMEOUT=2 sleep $WIRELESS_TIMEOUT - bssid=`iwgetid $1 -ra` - if [[ "$bssid" = "00:00:00:00:00:00" ]]; then + bssid=$(iwgetid $1 -ra) + if [[ $bssid = 00:00:00:00:00:00 ]]; then printhl "Could not associate $1 - try increasing WIRELESS_TIMEOUT and check network is WEP or has no security" return 1 fi @@ -58,25 +55,22 @@ wi_up() ifdown() { - if [ "$1" = "" ]; then + if [[ ! $1 ]]; then echo "usage: $0 ifdown <interface_name>" return 1 fi eval ifcfg="\$${1}" - if [ "$ifcfg" = "dhcp" ]; then - if [ -f /var/run/dhcpcd-${1}.pid ]; then - /bin/kill $(cat /var/run/dhcpcd-${1}.pid) - fi + if [[ $ifcfg = dhcp && -f /var/run/dhcpcd-${1}.pid ]]; then + /bin/kill $(cat /var/run/dhcpcd-${1}.pid) fi # Always bring the interface itself down /sbin/ifconfig ${1} down >/dev/null 2>&1 - return $? } iflist() { for ifline in ${INTERFACES[@]}; do - if [ "$ifline" = "${ifline#!}" ]; then + if [[ $ifline = ${ifline#!} ]]; then printf " $ifline:\t" else printf "$ifline:\t" @@ -88,38 +82,36 @@ iflist() rtup() { - if [ "$1" = "" ]; then + if [[ ! $1 ]]; then echo "usage: $0 rtup <route_name>" return 1 fi eval routecfg="\$${1}" - if grep -q :: <<< $routecfg; then + if [[ $routecfg =~ :: ]]; then /sbin/route -A inet6 add $routecfg else /sbin/route add $routecfg fi - return $? } rtdown() { - if [ "$1" = "" ]; then + if [[ ! $1 ]; then echo "usage: $0 rtdown <route_name>" return 1 fi eval routecfg="\$${1}" - if grep -q :: <<< $routecfg; then + if [[ $routecfg =~ :: ]]; then /sbin/route -A inet6 del $routecfg else /sbin/route del $routecfg fi - return $? } rtlist() { for rtline in ${ROUTES[@]}; do - if [ "$rtline" = "${rtline#!}" ]; then + if [[ $rtline = ${rtline#!} ]]; then printf " $rtline:\t" else printf "$rtline:\t" @@ -132,9 +124,9 @@ rtlist() bond_up() { for ifline in ${BOND_INTERFACES[@]}; do - if [ "$ifline" = "${ifline#!}" ]; then + if [[ $ifline = ${ifline#!} ]]; then eval bondcfg="\$bond_${ifline}" - if [ -n "${bondcfg}" ]; then + if [[ ${bondcfg} ]]; then /sbin/ifenslave $ifline $bondcfg || error=1 fi fi @@ -144,7 +136,7 @@ bond_up() bond_down() { for ifline in ${BOND_INTERFACES[@]}; do - if [ "$ifline" = "${ifline#!}" ]; then + if [[ $ifline = ${ifline#!} ]]; then eval bondcfg="\$bond_${ifline}" /sbin/ifenslave -d $ifline $bondcfg || error=1 fi @@ -154,18 +146,18 @@ bond_down() bridge_up() { for br in ${BRIDGE_INTERFACES[@]}; do - if [ "$br" = "${br#!}" ]; then + if [[ $br = ${br#!} ]]; then # if the bridge already exists, remove it - if [ "$(/sbin/ifconfig $br 2>/dev/null)" ]; then + if [[ $(/sbin/ifconfig $br 2>/dev/null) ]]; then /sbin/ifconfig $br down /usr/sbin/brctl delbr $br fi /usr/sbin/brctl addbr $br eval brifs="\$bridge_${br}" for brif in $brifs; do - if [ "$brif" = "${brif#!}" ]; then + if [[ $brif = ${brif#!} ]]; then for ifline in ${BOND_INTERFACES[@]}; do - if [ "$brif" = "$ifline" ] && [ "$ifline" = "${ifline#!}" ]; then + if [[ $brif = $ifline && $ifline = ${ifline#!} ]]; then ifup $ifline eval bondcfg="\$bond_${ifline}" /sbin/ifenslave $ifline $bondcfg || error=1 @@ -183,7 +175,7 @@ bridge_up() bridge_down() { for br in ${BRIDGE_INTERFACES[@]}; do - if [ "$br" = "${br#!}" ]; then + if [[ $br = ${br#!} ]]; then /usr/sbin/brctl delbr $br fi done @@ -203,7 +195,7 @@ case "$1" in bridge_up # bring up ethernet interfaces for ifline in ${INTERFACES[@]}; do - if [ "$ifline" = "${ifline#!}" ]; then + if [[ $ifline = ${ifline#!} ]]; then ifup $ifline || error=1 fi done @@ -215,7 +207,7 @@ case "$1" in rtup $rtline || error=1 fi done - if [ $error -eq 0 ]; then + if ((error == 0)); then add_daemon network stat_done else @@ -228,7 +220,7 @@ case "$1" in # exit #fi - if [ "${NETWORK_PERSIST}" = "yes" -o "${NETWORK_PERSIST}" = "YES" ]; then + if [[ $NETWORK_PERSIST =~ yes|YES ]]; then status "Skipping Network Shutdown" true exit 0 fi @@ -237,20 +229,20 @@ case "$1" in rm_daemon network error=0 for rtline in "${ROUTES[@]}"; do - if [ "$rtline" = "${rtline#!}" ]; then + if [[ $rtline = ${rtline#!} ]]; then rtdown $rtline || error=1 fi done # bring down bond interfaces bond_down for ifline in ${INTERFACES[@]}; do - if [ "$ifline" = "${ifline#!}" ]; then + if [[ $ifline = ${ifline#!} ]]; then ifdown $ifline || error=1 fi done # bring down bridge interfaces bridge_down - if [ $error -eq 0 ]; then + if ((error == 0)); then stat_done else stat_fail -- 1.7.1
Thomas, while you're working on rc.d/network, could you please have another look @ FS#16625? It's been sitting stale for quite a while. It would *really* speed up networking for us bridge users, and bridging is becoming more and more common with all the virtualization around.
Am 30.06.2010 23:47, schrieb Victor Lowther:
Despite efforts to make the initscripts POSIX, we use bash 4.0 features.
Bashifying this framework should result in about a 30% speedup, assuming no IO latency and that all programs we call also take zero time. :) --- functions | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/functions b/functions index 672eed2..023de35 100644 --- a/functions +++ b/functions @@ -1,4 +1,4 @@ -# +#!/bin/bash # initscripts functions
I don't see the need for this patch. functions is not supposed to be executed standalone, it is only source'd from bash scripts.
On Wed, 2010-06-30 at 23:55 +0200, Thomas Bächler wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
Despite efforts to make the initscripts POSIX, we use bash 4.0 features.
Bashifying this framework should result in about a 30% speedup, assuming no IO latency and that all programs we call also take zero time. :) --- functions | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/functions b/functions index 672eed2..023de35 100644 --- a/functions +++ b/functions @@ -1,4 +1,4 @@ -# +#!/bin/bash # initscripts functions
I don't see the need for this patch. functions is not supposed to be executed standalone, it is only source'd from bash scripts.
It is a habit I have -- including the shebang line at the top makes sure my text editors automatically detect the right shell syntax for syntax highlighting. -- Victor Lowther LPIC2 UCP RHCE
Am 01.07.2010 00:07, schrieb Victor Lowther:
On Wed, 2010-06-30 at 23:55 +0200, Thomas Bächler wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
Despite efforts to make the initscripts POSIX, we use bash 4.0 features.
Bashifying this framework should result in about a 30% speedup, assuming no IO latency and that all programs we call also take zero time. :) --- functions | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/functions b/functions index 672eed2..023de35 100644 --- a/functions +++ b/functions @@ -1,4 +1,4 @@ -# +#!/bin/bash # initscripts functions
I don't see the need for this patch. functions is not supposed to be executed standalone, it is only source'd from bash scripts.
It is a habit I have -- including the shebang line at the top makes sure my text editors automatically detect the right shell syntax for syntax highlighting.
Fair enough, but then that should be in the commit message.
On Wed, Jun 30, 2010 at 6:07 PM, Victor Lowther <victor.lowther@gmail.com> wrote:
I don't see the need for this patch. functions is not supposed to be executed standalone, it is only source'd from bash scripts.
It is a habit I have -- including the shebang line at the top makes sure my text editors automatically detect the right shell syntax for syntax highlighting.
It has the added benefit of making it quite clear that the script will not work on another POSIX shell. -- Caleb Cushing http://xenoterracide.blogspot.com
On Thu, 2010-07-01 at 22:58 -0400, Caleb Cushing wrote:
On Wed, Jun 30, 2010 at 6:07 PM, Victor Lowther <victor.lowther@gmail.com> wrote:
I don't see the need for this patch. functions is not supposed to be executed standalone, it is only source'd from bash scripts.
It is a habit I have -- including the shebang line at the top makes sure my text editors automatically detect the right shell syntax for syntax highlighting.
It has the added benefit of making it quite clear that the script will not work on another POSIX shell.
Indeed. -- Victor Lowther LPIC2 UCP RHCE
Here is a quick review on all these patches. I recommend that the lvm and crypttab changes get a decent amount of testing before these go live as they are the biggest changes being done. Tighten up the console size finding code a bit. Add some white space in test construct: if ((STAT_COL==0)); then if (( STAT_COL == 0 )); then and throughout these patches Simplify the code that clears USECOLOR. The following condition is removed with no commit message to explain why if [ $? = 3 ]; then TERM_COLOURS=8 Replace trivial use of grep with bash regex conditional. - if [ -n "$CONSOLEMAP" ] && echo "$LOCALE" | /bin/grep -qi utf ; then + [[ $CONSOLEMAP && $LOCALE =~ UTF|utf ]] && CONSOLEMAP="" Use ... && ${LOCALE,,} == utf ]] to accurately replicate the grep Replace slightly too long echo staement with a here document. ^^ typo I actually find the echo more readable Change the daemon runnign loop to use a case statement. Quote daemon names. Merge these commits Both rc.single and rc.shutdown use the same code to kill everything. + # $1 = where we are being called from. + # This is used to determine which hooks to run. -> Add separater line here... + # Find daemons NOT in the DAEMONS array. Shut these down first Why has this been removed: -if [ -x /etc/rc.local.shutdown ]; then - /etc/rc.local.shutdown -fi Ah... it has been moved to another place in another commit. Please document these sorts of changes in your commit message and preferably do the entire move in one commit. Flatten LVM deactivation if block in rc.shutdown. This change does not do the same thing and I do not see where it gets replicated -if [ -f /etc/crypttab -a -n "$(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$)" ]; then +if [[ -f /etc/crypttab ]]; then Also another: +if [[ $USELVM =~ yes|YES -> ${USELVM,,} == yes bashify bringing up the loopback adaptor. Add a commit message as that is doing a lot more than bashifing. Bashify locale setting. $LOCALE =~ utf|UTF Allan
On Tue, Jul 6, 2010 at 11:03 PM, Allan McRae <allan@archlinux.org> wrote:
Here is a quick review on all these patches. I recommend that the lvm and crypttab changes get a decent amount of testing before these go live as they are the biggest changes being done.
Why has this been removed: -if [ -x /etc/rc.local.shutdown ]; then - /etc/rc.local.shutdown -fi Ah... it has been moved to another place in another commit. Please document these sorts of changes in your commit message and preferably do the entire move in one commit.
If there was one thing I wasn't so fond of in these patches, it seemed like there were too many. The beauty of git is the ability to go back and squash and split patches in a way that makes a lot more sense to others- it might not have been the way or order you did things in, but you should try as hard as possible to make a commit the largest logical unit that makes sense, but still small enough to grasp fully. If there are ever closely-related changes strewn across multiple patches in a patch set, you should probably think about merging those commits. -Dan
On Jul 6, 2010, at 11:25 PM, Dan McGee <dpmcgee@gmail.com> wrote:
If there was one thing I wasn't so fond of in these patches, it seemed like there were too many.
Some people like larger patches, some like smaller ones. It is easier to merge smaller ones together than it is to split larger ones apart.
The beauty of git is the ability to go back and squash and split patches in a way that makes a lot more sense to others- it might not have been the way or order you did things in, but you should try as hard as possible to make a commit the largest logical unit that makes sense, but still small enough to grasp fully.
Ya, I wanted to get feedback to see if the larger Arch community was interested before going too much farther.
If there are ever closely-related changes strewn across multiple patches in a patch set, you should probably think about merging those commits.
-Dan
First of all: Sorry that I haven't finished the review, I have been busy with work and the heat kept me from thinking clearly. Am 07.07.2010 06:25, schrieb Dan McGee:
On Tue, Jul 6, 2010 at 11:03 PM, Allan McRae <allan@archlinux.org> wrote:
Here is a quick review on all these patches. I recommend that the lvm and crypttab changes get a decent amount of testing before these go live as they are the biggest changes being done.
Why has this been removed: -if [ -x /etc/rc.local.shutdown ]; then - /etc/rc.local.shutdown -fi Ah... it has been moved to another place in another commit. Please document these sorts of changes in your commit message and preferably do the entire move in one commit.
If there was one thing I wasn't so fond of in these patches, it seemed like there were too many. The beauty of git is the ability to go back and squash and split patches in a way that makes a lot more sense to others- it might not have been the way or order you did things in, but you should try as hard as possible to make a commit the largest logical unit that makes sense, but still small enough to grasp fully.
If there are ever closely-related changes strewn across multiple patches in a patch set, you should probably think about merging those commits.
I agree with Dan here. For example, all the commits that are merely "replace [ with [[" and no functional changes should be one commit only. I will release new initscripts and mkinitcpio now with a fix that needs to go to core before we do such a major change in initscripts.
On Sun, Jul 11, 2010 at 4:45 AM, Thomas Bächler <thomas@archlinux.org> wrote:
First of all: Sorry that I haven't finished the review, I have been busy with work and the heat kept me from thinking clearly.
Am 07.07.2010 06:25, schrieb Dan McGee:
On Tue, Jul 6, 2010 at 11:03 PM, Allan McRae <allan@archlinux.org> wrote:
Here is a quick review on all these patches. I recommend that the lvm and crypttab changes get a decent amount of testing before these go live as they are the biggest changes being done.
Why has this been removed: -if [ -x /etc/rc.local.shutdown ]; then - /etc/rc.local.shutdown -fi Ah... it has been moved to another place in another commit. Please document these sorts of changes in your commit message and preferably do the entire move in one commit.
If there was one thing I wasn't so fond of in these patches, it seemed like there were too many. The beauty of git is the ability to go back and squash and split patches in a way that makes a lot more sense to others- it might not have been the way or order you did things in, but you should try as hard as possible to make a commit the largest logical unit that makes sense, but still small enough to grasp fully.
If there are ever closely-related changes strewn across multiple patches in a patch set, you should probably think about merging those commits.
I agree with Dan here. For example, all the commits that are merely "replace [ with [[" and no functional changes should be one commit only.
Going back through and rewriting the patch series to do that will be jsut about as much effort as creating the original one was. If I had know that was what your preference was, I would have written it that way to begin with. Since the end result is going to be the same once the patch series is applied, though, I don't really see the point of making modifications beyond bugfixes.
I will release new initscripts and mkinitcpio now with a fix that needs to go to core before we do such a major change in initscripts.
Am 11.07.2010 14:20, schrieb Victor Lowther:
Going back through and rewriting the patch series to do that will be jsut about as much effort as creating the original one was. If I had know that was what your preference was, I would have written it that way to begin with. Since the end result is going to be the same once the patch series is applied, though, I don't really see the point of making modifications beyond bugfixes.
It is a matter of keeping the history readable. And it is simple: Just create a new branch based on master, cherry-pick the commits that do nothing but change [ to [[ and git merge --squash that branch into a new one.
On Sun, 2010-07-11 at 14:26 +0200, Thomas Bächler wrote:
Am 11.07.2010 14:20, schrieb Victor Lowther:
Going back through and rewriting the patch series to do that will be jsut about as much effort as creating the original one was. If I had know that was what your preference was, I would have written it that way to begin with. Since the end result is going to be the same once the patch series is applied, though, I don't really see the point of making modifications beyond bugfixes.
It is a matter of keeping the history readable. And it is simple: Just create a new branch based on master, cherry-pick the commits that do nothing but change [ to [[ and git merge --squash that branch into a new one.
If that is all you wnat done, that is easy enough to do. If you want all of the instances of trivial bashification split out from where I reworked the logic in the same patch, that is much less easy. -- Victor Lowther LPIC2 UCP RHCE
Am 11.07.2010 15:12, schrieb Victor Lowther:
On Sun, 2010-07-11 at 14:26 +0200, Thomas Bächler wrote:
Am 11.07.2010 14:20, schrieb Victor Lowther:
Going back through and rewriting the patch series to do that will be jsut about as much effort as creating the original one was. If I had know that was what your preference was, I would have written it that way to begin with. Since the end result is going to be the same once the patch series is applied, though, I don't really see the point of making modifications beyond bugfixes.
It is a matter of keeping the history readable. And it is simple: Just create a new branch based on master, cherry-pick the commits that do nothing but change [ to [[ and git merge --squash that branch into a new one.
If that is all you wnat done, that is easy enough to do. If you want all of the instances of trivial bashification split out from where I reworked the logic in the same patch, that is much less easy.
No no, that wouldn't make sense. It should be this way: First all patches that actually change logic, then one big commit that just converts the _remaining_ [ to [[ with no additional logic changes involved. I hope to actually finish the review of the rest of the patches some time this week, sorry that I let so much time pass now.
On Sun, Jul 11, 2010 at 2:11 PM, Thomas Bächler <thomas@archlinux.org> wrote:
No no, that wouldn't make sense. It should be this way: First all patches that actually change logic, then one big commit that just converts the _remaining_ [ to [[ with no additional logic changes involved.
wouldn't it be better to do the other way around... first the mass conversions with no logic changes (more likely to be accepted?) then the ones with logic changes in case some get rejected. that way the mass conversion doesn't depend on logic changes by accident. -- Caleb Cushing http://xenoterracide.blogspot.com
On Sun, Jul 11, 2010 at 1:11 PM, Thomas Bächler <thomas@archlinux.org> wrote:
Am 11.07.2010 15:12, schrieb Victor Lowther:
On Sun, 2010-07-11 at 14:26 +0200, Thomas Bächler wrote:
Am 11.07.2010 14:20, schrieb Victor Lowther:
Going back through and rewriting the patch series to do that will be jsut about as much effort as creating the original one was. If I had know that was what your preference was, I would have written it that way to begin with. Since the end result is going to be the same once the patch series is applied, though, I don't really see the point of making modifications beyond bugfixes.
It is a matter of keeping the history readable. And it is simple: Just create a new branch based on master, cherry-pick the commits that do nothing but change [ to [[ and git merge --squash that branch into a new one.
If that is all you wnat done, that is easy enough to do. If you want all of the instances of trivial bashification split out from where I reworked the logic in the same patch, that is much less easy.
No no, that wouldn't make sense. It should be this way: First all patches that actually change logic, then one big commit that just converts the _remaining_ [ to [[ with no additional logic changes involved.
OK, I flattened all the patches I considered "trivial" into several large-ish patches, approx 1 or 2 per file in initscripts. I did not combine them all into one large patch because making all the logic changes independent generated more conflicts than I felt like dealing with. The new branch is named bashification-redux, and is available at git://fnordovax.org/~victor/arch-initscripts. If you want me to post them to the list again, I will, but the logic is unchanged.
I hope to actually finish the review of the rest of the patches some time this week, sorry that I let so much time pass now.
No worries, the first time I did this sort of thing I ended up maintaining the project. :)
On Wed, 2010-07-07 at 14:03 +1000, Allan McRae wrote:
Here is a quick review on all these patches. I recommend that the lvm and crypttab changes get a decent amount of testing before these go live as they are the biggest changes being done.
Tighten up the console size finding code a bit. Add some white space in test construct: if ((STAT_COL==0)); then if (( STAT_COL == 0 )); then and throughout these patches
Maybe when all the other bugs are fixed. :)
Simplify the code that clears USECOLOR. The following condition is removed with no commit message to explain why if [ $? = 3 ]; then TERM_COLOURS=8
An exitval of 3 means tput has no idea what terminal type we are running on, and I figured that it is after to default to not using colorized output in that case.
Replace trivial use of grep with bash regex conditional. - if [ -n "$CONSOLEMAP" ] && echo "$LOCALE" | /bin/grep -qi utf ; then + [[ $CONSOLEMAP && $LOCALE =~ UTF|utf ]] && CONSOLEMAP=""
Use ... && ${LOCALE,,} == utf ]] to accurately replicate the grep
Hmmm... I had not seen that parameter expansion before. New to bash 4.1?
Replace slightly too long echo staement with a here document. ^^ typo I actually find the echo more readable
Well, then Thomas can keep it or drop it as he prefers.
Change the daemon runnign loop to use a case statement. Quote daemon names. Merge these commits
Both rc.single and rc.shutdown use the same code to kill everything. + # $1 = where we are being called from. + # This is used to determine which hooks to run. -> Add separater line here... + # Find daemons NOT in the DAEMONS array. Shut these down first
Why has this been removed: -if [ -x /etc/rc.local.shutdown ]; then - /etc/rc.local.shutdown -fi Ah... it has been moved to another place in another commit. Please document these sorts of changes in your commit message and preferably do the entire move in one commit.
Will fix.
Flatten LVM deactivation if block in rc.shutdown. This change does not do the same thing and I do not see where it gets replicated -if [ -f /etc/crypttab -a -n "$(/bin/grep -v ^# /etc/crypttab | /bin/grep -v ^$)" ]; then +if [[ -f /etc/crypttab ]]; then
All the second bit of that test does is to see if there is actual content in /etc/crypttab. I handle that in the read loop by zapping comments and blank lines with parameter expansion and conditional checks instead -- the greps end up reading the whole file anyways. Replicated via parameter expansion and conditionals: [[ $line && ${line:0:1} != '#' ]] || continue eval nspo=("${line%#*}")
Also another: +if [[ $USELVM =~ yes|YES -> ${USELVM,,} == yes
bashify bringing up the loopback adaptor. Add a commit message as that is doing a lot more than bashifing.
Already fixed in the last round of rebasing.
Bashify locale setting. $LOCALE =~ utf|UTF
Allan
-- Victor Lowther LPIC2 UCP RHCE
Am 30.06.2010 23:47, schrieb Victor Lowther:
Despite efforts to make the initscripts POSIX, we use bash 4.0 features.
Bashifying this framework should result in about a 30% speedup, assuming no IO latency and that all programs we call also take zero time. :)
I just pushed the patches - I was going to do more review of some of them, but I am apparently too busy. Please post any patches (especially if a correction of patch 21 is needed, I haven't finished reading the discussion) rebased on the current initscripts.git.
On Tue, Sep 7, 2010 at 3:32 PM, Thomas Bächler <thomas@archlinux.org> wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
Despite efforts to make the initscripts POSIX, we use bash 4.0 features.
Bashifying this framework should result in about a 30% speedup, assuming no IO latency and that all programs we call also take zero time. :)
I just pushed the patches - I was going to do more review of some of them, but I am apparently too busy. Please post any patches (especially if a correction of patch 21 is needed, I haven't finished reading the discussion) rebased on the current initscripts.git.
Your last patch has a typo (missed close paren): diff --git a/rc.sysinit b/rc.sysinit index b25f7ac..dc916a2 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -275,7 +275,7 @@ stat_busy "Removing Leftover Files" /bin/rm -f /var/lock/* &>/dev/null /bin/rm -rf /tmp/* /tmp/.* &>/dev/null /bin/rm -f /forcefsck &>/dev/null -[[ -d /var/run ]] && /usr/bin/find /var/run/ \! -type d -delete ) +[[ -d /var/run ]] && /usr/bin/find /var/run/ \! -type d -delete : >| /var/run/utmp /bin/chmod 0664 /var/run/utmp # Keep {x,k,g}dm happy with xorg
On Tue, Sep 07, 2010 at 09:51:59PM -0500, Victor Lowther wrote:
On Tue, Sep 7, 2010 at 3:32 PM, Thomas Bächler <thomas@archlinux.org> wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
Despite efforts to make the initscripts POSIX, we use bash 4.0 features.
Bashifying this framework should result in about a 30% speedup, assuming no IO latency and that all programs we call also take zero time. :)
I just pushed the patches - I was going to do more review of some of them, but I am apparently too busy. Please post any patches (especially if a correction of patch 21 is needed, I haven't finished reading the discussion) rebased on the current initscripts.git.
Your last patch has a typo (missed close paren):
-snip-
There's a typo in the network script from commit a334b36b: diff --git a/network b/network index 20ff9c7..5abb824 100755 --- a/network +++ b/network @@ -96,7 +96,7 @@ rtup() rtdown() { - if [[ ! $1 ]; then + if [[ ! $1 ]]; then echo "usage: $0 rtdown <route_name>" return 1 fi
On Tue, Sep 07, 2010 at 10:32:28PM +0200, Thomas Bächler wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
Despite efforts to make the initscripts POSIX, we use bash 4.0 features.
Bashifying this framework should result in about a 30% speedup, assuming no IO latency and that all programs we call also take zero time. :)
I just pushed the patches - I was going to do more review of some of them, but I am apparently too busy. Please post any patches (especially if a correction of patch 21 is needed, I haven't finished reading the discussion) rebased on the current initscripts.git.
I'm noticing that in general, the vim modelines aren't followed. Not sure what editor was used to rebase these scripts, but the mix of tabs and spaces for indents is somewhat irritating. I'm about to send a pair of patches (neither of which address this) but which follow the modeline. d
On Tue, Sep 7, 2010 at 10:47 PM, Dave Reisner <d@falconindy.com> wrote:
On Tue, Sep 07, 2010 at 10:32:28PM +0200, Thomas Bächler wrote:
Am 30.06.2010 23:47, schrieb Victor Lowther:
Despite efforts to make the initscripts POSIX, we use bash 4.0 features.
Bashifying this framework should result in about a 30% speedup, assuming no IO latency and that all programs we call also take zero time. :)
I just pushed the patches - I was going to do more review of some of them, but I am apparently too busy. Please post any patches (especially if a correction of patch 21 is needed, I haven't finished reading the discussion) rebased on the current initscripts.git.
I'm noticing that in general, the vim modelines aren't followed. Not sure what editor was used to rebase these scripts, but the mix of tabs and spaces for indents is somewhat irritating. I'm about to send a pair of patches (neither of which address this) but which follow the modeline.
Blame my ongoing Emacs education. I learned about (custom-set-variables '(indent-tabs-mode nil)) after doing most of the work, and dropped the whitespace cleanup patches due to size. Otherwise, I ignored the vim modelines -- 2 characters per indentation is not really enough, and most of the preexisting code happily ignored it anyways.
d
Am 08.09.2010 06:07, schrieb Victor Lowther:
Blame my ongoing Emacs education. I learned about (custom-set-variables '(indent-tabs-mode nil)) after doing most of the work, and dropped the whitespace cleanup patches due to size.
Otherwise, I ignored the vim modelines -- 2 characters per indentation is not really enough, and most of the preexisting code happily ignored it anyways.
Yeah, the code was very inconsistent to begin with. And whitespace cleanup patches are ugly, nobody bothered to do them so far.
participants (12)
-
Alexander Duscheleit
-
Allan McRae
-
bardo
-
Caleb Cushing
-
Daenyth Blank
-
Dan McGee
-
Dave Reisner
-
Jan de Groot
-
Jan Steffens
-
Kurt J. Bosch
-
Thomas Bächler
-
Victor Lowther