[packages/xen] xendomains.init 'status' action fixes

jajcus jajcus at pld-linux.org
Sat Nov 17 14:34:53 CET 2012


commit bf0f888a6411b41ca9649b1850f62c8875f4e199
Author: Jacek Konieczny <jajcus at jajcus.net>
Date:   Sat Nov 17 13:30:52 2012 +0100

    xendomains.init 'status' action fixes
    
    - shell syntax errors fixed
    – made compatible with 'xl' output (I hope 'xm' still works if anybody
      needs the obsolete tool)
    
    That is still a very, very ugly hack. I just made it work.

 xendomains.init | 45 ++++++++++++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 19 deletions(-)
---
diff --git a/xendomains.init b/xendomains.init
index 3dc2a77..1ecefe9 100644
--- a/xendomains.init
+++ b/xendomains.init
@@ -47,7 +47,8 @@ contains_something() {
 
 # read name from xen config file
 rdname() {
-	NM=$($CMD create --quiet --dryrun --defconfig "$1" | sed -n 's/^.*(name \(.*\))$/\1/p')
+	NM=$($CMD create --quiet --dryrun --defconfig "$1" 2>&1 | sed -n 's/^.*\(name \(.*\)\)\|\("name": "\([^"]*\)",\?\)$/\2\4/p')
+	NM=$(echo $NM)
 }
 
 rdnames() {
@@ -66,11 +67,16 @@ rdnames() {
 }
 
 parseln() {
-    if [[ "$1" = "*(domain*" ]]; then
+    if [[ "$1" = *"(domain"* ]]; then
         name=;id=
-    elif [[ "$1" = "*(name*" ]]; then
+    elif [[ "$1" = *"\"domid\"":* ]]; then
+        name=
+		id=$(echo $1 | sed -s 's/^.*: \([0-9]*\),$/\1/')
+    elif [[ "$1" = *"\"name\":"* ]]; then
+		name=$(echo $1 | sed -s 's/^.*: "\([^"]*\)",$/\1/')
+    elif [[ "$1" = *"(name"* ]]; then
         name=$(echo $1 | sed -e 's/^.*(name \(.*\))$/\1/')
-    elif [[ "$1" = "*(domid*" ]]; then
+    elif [[ "$1" = *"(domid"* ]]; then
         id=$(echo $1 | sed -e 's/^.*(domid \(.*\))$/\1/')
     fi
     [ -n "$name" -a -n "$id" ] && return 0 || return 1
@@ -79,7 +85,7 @@ parseln() {
 is_running() {
     rdname $1
     name=;id=
-    $CMD list -l | grep '(\(domain\|domid\|name\)' | \
+    $CMD list -l | grep '[("]\(domain\|domid\|name\)' | \
     while read LN; do
 	parseln "$LN" || continue
 	[ $id = 0 ] && continue
@@ -157,7 +163,7 @@ start() {
 
 all_zombies() {
     name=;id=
-    $CMD list -l | grep '(\(domain\|domid\|name\)' | \
+    $CMD list -l | grep '[("]\(domain\|domid\|name\)' | \
     while read LN; do
 	parseln "$LN" || continue
 	if test $id = 0; then continue; fi
@@ -204,7 +210,7 @@ stop() {
     fi
     echo -n "Shutting down Xen domains:"
     name=;id=
-    $CMD list -l | grep '(\(domain\|domid\|name\)' | \
+    $CMD list -l | grep '[("]\(domain\|domid\|name\)' | \
     while read LN; do
 	parseln "$LN" || continue
 	if test $id = 0; then continue; fi
@@ -313,18 +319,18 @@ stop() {
 
 check_domain_up()
 {
+	local result
+	result=1
     name=;id=
-    $CMD list -l | grep '(\(domain\|domid\|name\)' | \
+    $CMD list -l | grep '[("]\(domain\|domid\|name\)' | \
     while read LN; do
-	parseln "$LN" || continue
-	if test $id = 0; then continue; fi
-	case $name in 
-	    ($1)
-		return 0
-		;;
-	esac
+	  parseln "$LN" || continue
+	  if test $id = 0; then continue; fi
+	  if [ "$name" = "$1" ] ; then
+	  	echo 1
+ 		break
+	  fi
     done
-    return 1
 }
 
 check_all_auto_domains_up()
@@ -336,8 +342,8 @@ check_all_auto_domains_up()
     for nm in $XENDOMAINS_AUTO/*; do
 	rdname $nm
 	found=0
-	if check_domain_up "$NM"; then 
-	    echo -n " $name"
+	if [ -n "$(check_domain_up "$NM")" ] ; then 
+	    echo -n " $NM"
 	else 
 	    missing="$missing $NM"
 	fi
@@ -377,10 +383,11 @@ case "$1" in
     start
 	;;
     status)
-	if [ -f /var/lock/subsys/xendomains; then
+	if [ -f /var/lock/subsys/xendomains ]; then
 	    echo -n "Checking for xendomains:" 
 	    check_all_auto_domains_up
 	    check_all_saved_domains_up
+		echo
 	fi
 	;;
     *)
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/xen.git/commitdiff/291689a11152f9ea4bb81d2b0549fd0a5fedd10a



More information about the pld-cvs-commit mailing list