]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cleanup: use lxc-info --state-is
authorNatanael Copa <ncopa@alpinelinux.org>
Fri, 28 Dec 2012 08:24:55 +0000 (09:24 +0100)
committerStéphane Graber <stgraber@ubuntu.com>
Wed, 2 Jan 2013 17:52:37 +0000 (12:52 -0500)
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 <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/lxc-clone.in
src/lxc/lxc-destroy.in
src/lxc/lxc-netstat.in
src/lxc/lxc-shutdown.in

index 46401490c8bd89a4b00e50d570e94bc54b52a59c..22f0376e4418726153e8b39d05f978ebff3bcbc3 100644 (file)
@@ -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 --state-is RUNNING || container_running=False
 
 sed -i '/lxc.rootfs/d' $lxc_path/$lxc_new/config
 if [ -b $oldroot ]; then
index 0c27e4a1a7d31cfa1a48d9e9829bd7b9f0117a44..497acbe51b043fa2b2e17267b642a085191c3057 100644 (file)
@@ -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
index 6d08ce3797a51cb9997b886a965673ed941cb4a5..2fa2d23aeb4e205ec782edab95e594600e7b3684 100644 (file)
@@ -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
index c0d1702f9a11e9a8a288b29f37b4e8782afc4954..f30e22b86b2d158d79b7e9496fbfcf06ab293c02 100644 (file)
@@ -130,11 +130,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