aboutsummaryrefslogtreecommitdiff
blob: 185b36706cada083c5b08c3061201d649c9a7be0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash

localstatedir=@LOCALSTATEDIR@
lxcpath=@LXCPATH@

if [ ! -r $lxcpath ]; then
    exit 0
fi

function get_cgroup()
{
	local mount_string
	mount_string=$(mount -t cgroup |grep -E -e '^lxc ')
	if test -n "$mount_string"; then
		mount_point=$(echo $mount_string |cut -d' ' -f3)
		return
	fi
	mount_string=`grep -m1 -E '^[^ \t]+[ \t]+[^ \t]+[ \t]+cgroup' /proc/self/mounts`;
	if test -z "$mount_string"; then
		echo "failed to find mounted cgroup"
		exit 1
	fi
	mount_point=`echo "$mount_string" |cut -d' ' -f2`;
}

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