From 65cb447f9b8d1ac8dcf9df24a4f877180444f003 Mon Sep 17 00:00:00 2001 From: Michel Normand Date: Thu, 26 Nov 2009 16:46:22 +0100 Subject: [PATCH] lxc-ls to report also active containers With previous changes that allow to start a container without the need to create it; the lxc-ls was only reporting the created containers. With this patch, the lxc-ls is now reporting created and active containers. Signed-off-by: Michel Normand Signed-off-by: Daniel Lezcano --- src/lxc/lxc-ls.in | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/lxc/lxc-ls.in b/src/lxc/lxc-ls.in index 6a77ebef6..7d2dad034 100644 --- a/src/lxc/lxc-ls.in +++ b/src/lxc/lxc-ls.in @@ -6,4 +6,26 @@ if [ ! -r $lxcpath ]; then exit 0 fi +function get_cgroup() +{ + local mount_string + mount_string=$(mount -t cgroup |grep -E -e '^lxc ') + if test -z "$mount_string"; then + mount_string=$(mount |grep -m1 'type cgroup') + fi + if test -n "$mount_string"; then + mount_point=$(echo $mount_string |cut -d' ' -f3) + fi +} + ls $* $lxcpath + +active=$(netstat -xa | grep $lxcpath | \ + sed -e 's#.*'"$lxcpath/"'\(.*\)/command#\1#'); + +if test -n "$active"; then + get_cgroup + if test -n "$mount_point"; then + cd $mount_point; ls $* -d $active + fi +fi -- 2.39.5