ia64/xen-unstable
changeset 7532:20d1a79ebe31
Fix the check for non-existence of the save/restore directories, by using &&
rather than -a. The former shortcuts at the script level, whereas the latter
does not, which means that the backtick-enclosed arguments are evaluated
regardless of the success of preceding tests.
Tidy the aforementioned test into a function of its own.
Add an implementation of usleep for those systems that only have sleep (Debian,
for example).
Signed-off-by: Ewan Mellor <ewan@xensource.com>
rather than -a. The former shortcuts at the script level, whereas the latter
does not, which means that the backtick-enclosed arguments are evaluated
regardless of the success of preceding tests.
Tidy the aforementioned test into a function of its own.
Add an implementation of usleep for those systems that only have sleep (Debian,
for example).
Signed-off-by: Ewan Mellor <ewan@xensource.com>
author | emellor@leeni.uk.xensource.com |
---|---|
date | Wed Oct 26 16:59:13 2005 +0100 (2005-10-26) |
parents | 0240a69e1f97 |
children | a793b7a53605 |
files | tools/examples/init.d/xendomains |
line diff
1.1 --- a/tools/examples/init.d/xendomains Wed Oct 26 14:59:29 2005 +0100 1.2 +++ b/tools/examples/init.d/xendomains Wed Oct 26 16:59:13 2005 +0100 1.3 @@ -121,9 +121,34 @@ else 1.4 } 1.5 fi 1.6 1.7 +if ! which usleep >&/dev/null 1.8 +then 1.9 + usleep() 1.10 + { 1.11 + if [ -n "$1" ] 1.12 + then 1.13 + sleep $(( $1 / 1000 )) 1.14 + fi 1.15 + } 1.16 +fi 1.17 + 1.18 # Reset status of this service 1.19 rc_reset 1.20 1.21 +## 1.22 +# Returns 0 (success) if the given parameter names a directory, and that 1.23 +# directory is not empty. 1.24 +# 1.25 +contains_something() 1.26 +{ 1.27 + if [ -d "$1" ] && [ `/bin/ls $1 | wc -l` -gt 0 ] 1.28 + then 1.29 + return 0 1.30 + else 1.31 + return 1 1.32 + fi 1.33 +} 1.34 + 1.35 # read name from xen config file 1.36 rdname() 1.37 { 1.38 @@ -133,7 +158,8 @@ rdname() 1.39 rdnames() 1.40 { 1.41 NAMES= 1.42 - if test ! -d $XENDOMAINS_AUTO -o `/bin/ls $XENDOMAINS_AUTO | wc -l` -eq 0; then 1.43 + if ! contains_something "$XENDOMAINS_AUTO" 1.44 + then 1.45 return 1.46 fi 1.47 for dom in $XENDOMAINS_AUTO/*; do 1.48 @@ -177,9 +203,10 @@ start() 1.49 return; 1.50 fi 1.51 1.52 - if test "$XENDOMAINS_RESTORE" = "true" -a -n "$XENDOMAINS_SAVE" \ 1.53 - -a -d $XENDOMAINS_SAVE -a `/bin/ls $XENDOMAINS_SAVE | wc -l` -gt 0; then 1.54 - 1.55 + if [ "$XENDOMAINS_RESTORE" = "true" ] && 1.56 + contains_something "$XENDOMAINS_SAVE" 1.57 + then 1.58 + mkdir -p $(dirname "$LOCKFILE") 1.59 touch $LOCKFILE 1.60 echo -n "Restoring Xen domains:" 1.61 for dom in $XENDOMAINS_SAVE/*; do 1.62 @@ -195,9 +222,8 @@ start() 1.63 done 1.64 fi 1.65 1.66 - if test -n "$XENDOMAINS_AUTO" -a -d $XENDOMAINS_AUTO \ 1.67 - -a `/bin/ls $XENDOMAINS_AUTO | wc -l` -gt 0; then 1.68 - 1.69 + if contains_something "$XENDOMAINS_AUTO" 1.70 + then 1.71 touch $LOCKFILE 1.72 echo -n "Starting auto Xen domains:" 1.73 # We expect config scripts for auto starting domains to be in 1.74 @@ -378,8 +404,10 @@ check_domain_up() 1.75 1.76 check_all_auto_domains_up() 1.77 { 1.78 - if test -z "$XENDOMAINS_AUTO" -o ! -d "$XENDOMAINS_AUTO" \ 1.79 - -o `/bin/ls $XENDOMAINS_AUTO | wc -l` -eq 0; then return 0; fi 1.80 + if ! contains_something "$XENDOMAINS_AUTO" 1.81 + then 1.82 + return 0 1.83 + fi 1.84 missing= 1.85 for nm in $XENDOMAINS_AUTO/*; do 1.86 rdname $nm 1.87 @@ -399,8 +427,10 @@ check_all_auto_domains_up() 1.88 1.89 check_all_saved_domains_up() 1.90 { 1.91 - if test -z "$XENDOMAINS_SAVE" -o ! -d "$XENDOMAINS_SAVE" \ 1.92 - -o `/bin/ls $XENDOMAINS_SAVE | wc -l` -eq 0; then return 0; fi 1.93 + if ! contains_something "$XENDOMAINS_SAVE" 1.94 + then 1.95 + return 0 1.96 + fi 1.97 missing=`/bin/ls $XENDOMAINS_SAVE` 1.98 echo -n " MISS SAVED: " $missing 1.99 return 1