Bug #40697: Fix `xm list` parsing For managed inactive domains `xm list` does not output a domain-ID and a state. | # xm list | Name ID Mem VCPUs State Time(s) | Domain-0 0 3884 2 r----- 71.6 | yyy 512 1 0.0 | xxx 7 512 1 -b---- 1.1 Also cpu is not output. Rewrite parseln() to use IFS for splitting and use number of output columns to parse the lines. --- a/debian/xen-utils-common.xendomains.init 2016-03-30 09:58:03.670755440 +0200 +++ b/debian/xen-utils-common.xendomains.init 2016-03-30 10:18:55.998019561 +0200 @@ -126,12 +126,16 @@ done } -parseln() -{ - name=`echo $1 | cut -d\ -f1` - name=${name%% *} - rest=`echo $1 | cut -d\ -f2-` - read id mem cpu vcpu state tm < <(echo "$rest") +parseln () { + local IFS=' ' + set -- $1 # IFS + case "$#" in + 4) name=$1 id= mem=$2 cpu= vcpu=$3 state= tm=$4 ;; + 5) name=$1 id= mem=$2 cpu=$3 vcpu=$4 state= tm=$5 ;; + 6) name=$1 id=$2 mem=$3 cpu= vcpu=$4 state=$5 tm=$6 ;; + 7) name=$1 id=$2 mem=$3 cpu=$4 vcpu=$5 state=$6 tm=$7 ;; + *) name= id= mem= cpu= vcpu= stat= tm= ; echo "Unknown 'xm list' output: $*" >&2 ;; + esac } is_running() @@ -140,7 +144,7 @@ RC=1 while read LN; do parseln "$LN" - if test $id = 0; then continue; fi + if [ -z "$id" ] || test $id = 0; then continue; fi case $name in ($NM) RC=0 @@ -208,7 +212,7 @@ { while read LN; do parseln "$LN" - if test $id = 0; then continue; fi + if [ -z "$id" ] || test $id = 0; then continue; fi if test "$state" != "-b---d" -a "$state" != "-----d"; then return 1; fi @@ -250,7 +254,7 @@ echo -n "Shutting down Xen domains:" while read LN; do parseln "$LN" - if test $id = 0; then continue; fi + if [ -z "$id" ] || test $id = 0; then continue; fi echo -n " $name" if test "$XENDOMAINS_AUTO_ONLY" = "true"; then case $name in @@ -350,7 +354,7 @@ { while read LN; do parseln "$LN" - if test $id = 0; then continue; fi + if [ -z "$id" ] || test $id = 0; then continue; fi case $name in ($1) return 0