FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux General Discussion

 
 
LinkBack Thread Tools
 
Old 06-30-2010, 10:00 PM
Thomas Bächler
 
Default Slightly simplify hook-running infrastructure.

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
 

Thread Tools




All times are GMT. The time now is 07:33 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org