On 12/28/2012 03:24 AM, Natanael Copa wrote:
> We now have the possibility to test for a given state. Use this feature
> instead of parsing output with grep or awk
> 
> Signed-off-by: Natanael Copa <nc...@alpinelinux.org>

Looks like you didn't test the lxc-clone part as --status-is doesn't
exist, it's --state-is. Diff updated and applied. Thanks.

Acked-by: Stéphane Graber <stgra...@ubuntu.com>



> ---
>  src/lxc/lxc-clone.in    | 2 +-
>  src/lxc/lxc-destroy.in  | 5 ++---
>  src/lxc/lxc-netstat.in  | 3 +--
>  src/lxc/lxc-shutdown.in | 6 +-----
>  4 files changed, 5 insertions(+), 11 deletions(-)
> 
> diff --git a/src/lxc/lxc-clone.in b/src/lxc/lxc-clone.in
> index 4640149..cf349ea 100644
> --- a/src/lxc/lxc-clone.in
> +++ b/src/lxc/lxc-clone.in
> @@ -193,7 +193,7 @@ oldroot=`grep lxc.rootfs $lxc_path/$lxc_orig/config | awk 
> -F'[= \t]+' '{ print $
>  rootfs=`echo $oldroot |sed "s/$lxc_orig/$lxc_new/"`
>  
>  container_running=True
> -lxc-info -s -n $lxc_orig|grep RUNNING >/dev/null 2>&1 || 
> container_running=False
> +lxc-info -n $lxc_orig --status-is RUNNING || container_running=False
>  
>  sed -i '/lxc.rootfs/d' $lxc_path/$lxc_new/config
>  if [ -b $oldroot ]; then
> diff --git a/src/lxc/lxc-destroy.in b/src/lxc/lxc-destroy.in
> index 0c27e4a..497acbe 100644
> --- a/src/lxc/lxc-destroy.in
> +++ b/src/lxc/lxc-destroy.in
> @@ -104,13 +104,12 @@ if [ ! -d "$lxc_path/$lxc_name" ]; then
>  fi
>  
>  # make sure the container is stopped
> -state=`lxc-info -n $lxc_name 2>/dev/null | head -1 |awk '{print $2}'`
> -if [ $state != "STOPPED" ]; then
> +if ! lxc-info -n $lxc_name --state-is "STOPPED"; then
>      if [ $force -eq 1 ]; then
>          lxc-stop -n $lxc_name
>          lxc-wait -n $lxc_name -s STOPPED
>      else
> -        echo "$(basename $0): '$lxc_name' is $state; aborted" >&2
> +        echo "$(basename $0): '$lxc_name' $(lxc-info -n $lxc_name -s); 
> aborted" >&2
>          exit 1
>      fi
>  fi
> diff --git a/src/lxc/lxc-netstat.in b/src/lxc/lxc-netstat.in
> index 6d08ce3..2fa2d23 100644
> --- a/src/lxc/lxc-netstat.in
> +++ b/src/lxc/lxc-netstat.in
> @@ -96,8 +96,7 @@ if [ -z "$exec" ]; then
>      exec @BINDIR@/lxc-unshare -s MOUNT -- $0 -n $name --exec "$@"
>  fi
>  
> -lxc-info -n $name 2>&1 | grep -q 'STOPPED'
> -if [ $? -eq 0 ]; then
> +if lxc-info -n $name --state-is 'STOPPED'; then
>      echo "$(basename $0): container '$name' is not running" >&2
>      exit 1
>  fi
> diff --git a/src/lxc/lxc-shutdown.in b/src/lxc/lxc-shutdown.in
> index cf1d603..ad8395b 100644
> --- a/src/lxc/lxc-shutdown.in
> +++ b/src/lxc/lxc-shutdown.in
> @@ -134,11 +134,7 @@ if [ $timeout != "-1" ]; then
>      alarmpid=$!
>  fi
>  
> -while [ 1 ]; do
> -    s=`lxc-info -s -n $lxc_name | awk '{ print $2 }'`
> -    if [ "$s" = "STOPPED" ]; then
> -        break;
> -    fi
> +while ! lxc-info -n $lxc_name --state-is STOPPED; do
>      sleep 1
>  done
>  
> 


-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com

Attachment: signature.asc
Description: OpenPGP digital signature

------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to