]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/legacy/lxc-ls.in
4 # lxc: linux Container library
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 . @DATADIR@
/lxc
/lxc.functions
24 echo "usage: $(basename $0) [--active] [--] [LS_OPTIONS...]" >&2
30 echo "List containers existing on the system." >&2
32 echo " --active list active containers" >&2
33 echo " LS_OPTIONS ls command options (see \`ls --help')" >&2
40 # Obtain a list of hierarchies that contain one or more subsystems
41 hierarchies
=$
(tail -n +2 /proc
/cgroups | cut
-f 2)
43 # Iterate through the list until a suitable hierarchy is found
44 for hierarchy
in $hierarchies; do
45 # Obtain information about the init process in the hierarchy
46 fields
=$
(grep -E "^$hierarchy:" /proc
/1/cgroup |
head -n 1)
47 if [ -z "$fields" ]; then continue; fi
50 # Get a comma-separated list of the hierarchy's subsystems
51 subsystems
=${fields%:*}
53 # Get the cgroup of the init process in the hierarchy
54 init_cgroup
=${fields#*:}
56 # Get the filesystem mountpoint of the hierarchy
57 mountpoint
=$
(awk -v subsysregex
="(^|,)$subsystems(,|\$)" \
58 '$3 == "cgroup" && $4 ~ subsysregex {print $2}' /proc
/self
/mounts
)
59 if [ -z "$mountpoint" ]; then continue; fi
61 # Return the absolute path to the containers' parent cgroup
62 # (do not append '/lxc' if the hierarchy contains the 'ns' subsystem)
63 case ",$subsystems," in
64 *,ns
,*) parent_cgroup
="${mountpoint}${init_cgroup%/}";;
65 *) parent_cgroup
="${mountpoint}${init_cgroup%/}/lxc";;
71 directory
=$
(readlink
-f "$lxc_path")
78 get_parent_cgroup
; directory
="$parent_cgroup"; shift;;
87 if [ ! -z "$directory" ]; then
88 if [ x
"$parent_cgroup" = x
]; then
89 containers
=$
(find $directory -mindepth 2 -maxdepth 2 -name config
-type f |
awk -F "/" '{print $(NF-1)}')
91 containers
=$
(find $directory -mindepth 1 -maxdepth 1 -type d
2>/dev
/null |
sed 's:.*/::')
93 if [ x
"$containers" = x
]; then
99 ls -d $@
-- $containers