[lxc-devel] [PATCH] Install legacy scripts when built without python.
Stéphane Graber
stgraber at ubuntu.com
Tue Dec 4 17:15:44 UTC 2012
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 <stgraber at ubuntu.com>
---
.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 76c9533..79dd77a 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 b73e07b..626d202 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 1617186..86de2fe 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 0000000..c04a4a4
--- /dev/null
+++ b/doc/legacy/lxc-ls.sgml.in
@@ -0,0 +1,156 @@
+
+<!--
+
+lxc: linux Container library
+
+(C) Copyright IBM Corp. 2007, 2008
+
+Authors:
+Daniel Lezcano <dlezcano at fr.ibm.com>
+
+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
+
+-->
+
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
+
+<!ENTITY seealso SYSTEM "@builddir@/../see_also.sgml">
+]>
+
+<refentry>
+
+ <docinfo><date>@LXC_GENERATE_DATE@</date></docinfo>
+
+ <refmeta>
+ <refentrytitle>lxc-ls</refentrytitle>
+ <manvolnum>1</manvolnum>
+ </refmeta>
+
+ <refnamediv>
+ <refname>lxc-ls</refname>
+
+ <refpurpose>
+ list the containers existing on the system
+ </refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+ <cmdsynopsis>
+ <command>lxc-ls</command>
+ <arg choice="opt">--active</arg>
+ <arg choice="opt">ls option</arg>
+ </cmdsynopsis>
+ </refsynopsisdiv>
+
+ <refsect1>
+ <title>Description</title>
+ <para>
+ <command>lxc-ls</command> list the containers existing on the
+ system.
+ </para>
+ </refsect1>
+
+ <refsect1>
+ <title>Options</title>
+ <variablelist>
+
+ <varlistentry>
+ <term>
+ <option><optional>--active</optional></option>
+ </term>
+ <listitem>
+ <para>
+ List active containers.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option><optional>ls options</optional></option>
+ </term>
+ <listitem>
+ <para>
+ The option passed to <command>lxc-ls</command> are the
+ same as the <command>ls</command> command.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ </variablelist>
+
+ </refsect1>
+
+ <refsect1>
+ <title>Examples</title>
+ <variablelist>
+ <varlistentry>
+ <term>lxc-ls -l</term>
+ <listitem>
+ <para>
+ list all the container and their permissions.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>lxc-ls --active -1</term>
+ <listitem>
+ <para>
+ list active containers and display the list in one column.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ </variablelist>
+ </refsect1>
+
+ <refsect1>
+ <title>See Also</title>
+
+ <simpara>
+ <citerefentry>
+ <refentrytitle>ls</refentrytitle>
+ <manvolnum>1</manvolnum>
+ </citerefentry>,
+ </simpara>
+
+ </refsect1>
+
+ &seealso;
+
+ <refsect1>
+ <title>Author</title>
+ <para>Daniel Lezcano <email>daniel.lezcano at free.fr</email></para>
+ </refsect1>
+
+</refentry>
+
+<!-- Keep this comment at the end of the file
+Local variables:
+mode: sgml
+sgml-omittag:t
+sgml-shorttag:t
+sgml-minimize-attributes:nil
+sgml-always-quote-attributes:t
+sgml-indent-step:2
+sgml-indent-data:t
+sgml-parent-document:nil
+sgml-default-dtd-file:nil
+sgml-exposed-tags:nil
+sgml-local-catalogs:nil
+sgml-local-ecat-files:nil
+End:
+-->
diff --git a/src/lxc/Makefile.am b/src/lxc/Makefile.am
index de227c7..bf675f9 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 0000000..f26572d
--- /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
--
1.8.0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 899 bytes
Desc: OpenPGP digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20121204/850dc2bf/attachment.pgp>
More information about the lxc-devel
mailing list