From 6a85cf91247b7dd9c3faeddceca8dacb96d02cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Tue, 4 Dec 2012 12:12:36 -0500 Subject: [PATCH] Install legacy scripts when built without python. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Re-introduce the old lxc-ls script and manpage under a new legacy sub-directory. Those will be installed in place of their python equivalent when LXC is built without --enable-python. Any other script ported to python should be added to those lists. Signed-off-by: Stéphane Graber Acked-by: Serge E. Hallyn --- .gitignore | 1 + configure.ac | 2 + doc/Makefile.am | 9 ++- doc/legacy/lxc-ls.sgml.in | 156 ++++++++++++++++++++++++++++++++++++++ src/lxc/Makefile.am | 2 + src/lxc/legacy/lxc-ls.in | 94 +++++++++++++++++++++++ 6 files changed, 263 insertions(+), 1 deletion(-) create mode 100644 doc/legacy/lxc-ls.sgml.in create mode 100644 src/lxc/legacy/lxc-ls.in diff --git a/.gitignore b/.gitignore index 76c95338f..79dd77af9 100644 --- a/.gitignore +++ b/.gitignore @@ -64,6 +64,7 @@ src/lxc/lxc-unfreeze src/lxc/lxc-unshare src/lxc/lxc-version src/lxc/lxc-wait +src/lxc/legacy/lxc-ls src/python-lxc/lxc/__pycache__/ diff --git a/configure.ac b/configure.ac index b73e07b16..626d20244 100644 --- a/configure.ac +++ b/configure.ac @@ -229,6 +229,7 @@ AC_CONFIG_FILES([ doc/lxc.sgml doc/common_options.sgml doc/see_also.sgml + doc/legacy/lxc-ls.sgml doc/rootfs/Makefile @@ -266,6 +267,7 @@ AC_CONFIG_FILES([ src/lxc/lxc-shutdown src/lxc/lxc-start-ephemeral src/lxc/lxc-destroy + src/lxc/legacy/lxc-ls src/python-lxc/Makefile diff --git a/doc/Makefile.am b/doc/Makefile.am index 16171866e..86de2fedb 100644 --- a/doc/Makefile.am +++ b/doc/Makefile.am @@ -19,7 +19,6 @@ man_MANS = \ lxc-unfreeze.1 \ lxc-monitor.1 \ lxc-wait.1 \ - lxc-ls.1 \ lxc-ps.1 \ lxc-cgroup.1 \ lxc-kill.1 \ @@ -29,15 +28,23 @@ man_MANS = \ \ lxc.7 +if ENABLE_PYTHON + man_MANS += lxc-ls.1 +else + man_MANS += legacy/lxc-ls.1 +endif %.1 : %.sgml $(db2xman) $< + test "$(shell basename $@)" != "$@" && mv $(shell basename $@) $@ || true %.5 : %.sgml $(db2xman) $< + test "$(shell basename $@)" != "$@" && mv $(shell basename $@) $@ || true %.7 : %.sgml $(db2xman) $< + test "$(shell basename $@)" != "$@" && mv $(shell basename $@) $@ || true lxc-%.sgml : common_options.sgml see_also.sgml diff --git a/doc/legacy/lxc-ls.sgml.in b/doc/legacy/lxc-ls.sgml.in new file mode 100644 index 000000000..c04a4a4c2 --- /dev/null +++ b/doc/legacy/lxc-ls.sgml.in @@ -0,0 +1,156 @@ + + + + +]> + + + + @LXC_GENERATE_DATE@ + + + lxc-ls + 1 + + + + lxc-ls + + + list the containers existing on the system + + + + + + lxc-ls + --active + ls option + + + + + Description + + lxc-ls list the containers existing on the + system. + + + + + Options + + + + + + + + + List active containers. + + + + + + + + + + + The option passed to lxc-ls are the + same as the ls command. + + + + + + + + + + Examples + + + lxc-ls -l + + + list all the container and their permissions. + + + + + + lxc-ls --active -1 + + + list active containers and display the list in one column. + + + + + + + + + See Also + + + + ls + 1 + , + + + + + &seealso; + + + Author + Daniel Lezcano daniel.lezcano@free.fr + + + + + diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am index de227c70d..bf675f9d0 100644 --- a/src/lxc/Makefile.am +++ b/src/lxc/Makefile.am @@ -100,6 +100,8 @@ if ENABLE_PYTHON bin_SCRIPTS += lxc-device bin_SCRIPTS += lxc-ls bin_SCRIPTS += lxc-start-ephemeral +else + bin_SCRIPTS += legacy/lxc-ls endif bin_PROGRAMS = \ diff --git a/src/lxc/legacy/lxc-ls.in b/src/lxc/legacy/lxc-ls.in new file mode 100644 index 000000000..f26572da2 --- /dev/null +++ b/src/lxc/legacy/lxc-ls.in @@ -0,0 +1,94 @@ +#!/bin/bash + +# +# lxc: linux Container library + +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. + +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +lxc_path=@LXCPATH@ + +usage() +{ + echo "usage: $(basename $0) [--active] [--] [LS_OPTIONS...]" >&2 +} + +help() { + usage + echo >&2 + echo "List containers existing on the system." >&2 + echo >&2 + echo " --active list active containers" >&2 + echo " LS_OPTIONS ls command options (see \`ls --help')" >&2 +} + +get_parent_cgroup() +{ + local hierarchies hierarchy fields subsystems init_cgroup mountpoint + + parent_cgroup="" + + # Obtain a list of hierarchies that contain one or more subsystems + hierarchies=$(tail -n +2 /proc/cgroups | cut -f 2) + + # Iterate through the list until a suitable hierarchy is found + for hierarchy in $hierarchies; do + # Obtain information about the init process in the hierarchy + fields=$(grep -E "^$hierarchy:" /proc/1/cgroup | head -n 1) + if [ -z "$fields" ]; then continue; fi + fields=${fields#*:} + + # Get a comma-separated list of the hierarchy's subsystems + subsystems=${fields%:*} + + # Get the cgroup of the init process in the hierarchy + init_cgroup=${fields#*:} + + # Get the filesystem mountpoint of the hierarchy + mountpoint=$(grep -E "^[^ ]+ [^ ]+ cgroup ([^ ]+,)?$subsystems(,[^ ]+)? " /proc/self/mounts | cut -d ' ' -f 2) + if [ -z "$mountpoint" ]; then continue; fi + + # Return the absolute path to the containers' parent cgroup + # (do not append '/lxc' if the hierarchy contains the 'ns' subsystem) + if [[ ",$subsystems," == *,ns,* ]]; then + parent_cgroup="${mountpoint}${init_cgroup%/}" + else + parent_cgroup="${mountpoint}${init_cgroup%/}/lxc" + fi + break + done +} + +directory=$(readlink -f "$lxc_path") + +for i in "$@"; do + case $i in + --help) + help; exit;; + --active) + get_parent_cgroup; directory="$parent_cgroup"; shift;; + --) + shift; break;; + *) + break;; + esac +done + +containers="" +if [ ! -z "$directory" ]; then + containers=$(find $directory -mindepth 1 -maxdepth 1 -type d -printf "%f\n" 2>/dev/null) +fi + +cd "$directory" +ls -d $@ -- $containers