Commit Graph

1197 Commits

Author SHA1 Message Date
Stéphane Graber
59b3bc264c Remove zombie_handler from python-lxc code
This code was addeed to deal with stopped/dead containers but
really shouldn't be implemented there. Instead the setsid() call in
start() should be enough to prevent python from getting the SIGCHLD and
having to deal with it.
2012-11-12 13:17:54 -05:00
Stéphane Graber
cbd4c46406 Raise exception when getting Container instance as non-root in python3-lxc
The liblxc API currently doesn't work as non-root, so check that the euid
is 0 when getting a Container instance in the python API.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:17:54 -05:00
Serge Hallyn
767d4c6743 premount hook is implemented in git
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 13:17:54 -05:00
Serge Hallyn
472c97e976 document lxc.hooks in lxc.conf manpage
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 13:17:54 -05:00
Serge Hallyn
8eb5694baf Add lxc_conf_free()
Then after lxcapi container->create(), free whatever lxc_conf may be
loaded and reload from the newly created configuration file.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 13:17:30 -05:00
Serge Hallyn
64fca455ae get_item(utsname): don't dereference utsname if it is NULL
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 13:17:30 -05:00
Serge Hallyn
4a7c7daa26 Fix passing non-const char* in for const char*
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 13:17:30 -05:00
Serge Hallyn
c278cef2ec check chdir(/) return value
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 13:17:30 -05:00
Serge Hallyn
89eaa05ed1 replace HOOK define with proper code.
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 13:17:30 -05:00
Stéphane Graber
e0de36d791 Add better example/test of the python3-lxc API
Replaced python-lxc/test.py by a new api_test.py script that
uses all the available function of the API to run a batch of
basic tests.

This example is useful both as a test of the API and as a guide on
how to use the python API to manage containers.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:17:30 -05:00
Stéphane Graber
38b280ca2c Remove unused v1 and v2 variables in main()
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:17:30 -05:00
Stéphane Graber
85a9d07827 Cleanup lxc_wait
- Remove unused timeout_handler function.
 - Remove unsused variables from main()

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:17:30 -05:00
Stéphane Graber
fe88b9d2f3 Remove unused "i" variable in lxc_get_item_nic
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:17:30 -05:00
Stéphane Graber
427b3a21ef Change lxc_remove_nic from returning int to void
The function wasn't returning anything and none of the callers
were checking for a return code.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:17:30 -05:00
Stéphane Graber
525421c923 Make building the API tests/examples optional
Add a new --enable-tests option to configure which is used to
optionally build the tests/examples. Default is off.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:17:30 -05:00
Serge Hallyn
5ea6163a62 Add lxc.hook.pre-mount
This happens in the container's namespace, but before the rootfs is
setup and mounted.  This gives us a chance to mangle the rootfs - i.e.
ecryptfs-mount it.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 13:17:30 -05:00
Serge Hallyn
06200a37fc lxc-wait: initialize timeout to -1
Otherwise it defaults to 0, meaning don't wait.  -1 means wait forever,
which is what we want as the default behavior.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 13:17:30 -05:00
Stéphane Graber
69d66f1e72 Add lxc.aa_profile example to all templates
LXC has optional apparmor support, default profile is lxc-container-default.
This change adds a commented "lxc.aa_profile = default" line to all templates,
uncommenting this will bypass apparmor for the container.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:16:50 -05:00
Stéphane Graber
0a8722fd78 Rename runapitests.bash to runapitests.sh and make it use /bin/sh
This is a simple POSIX shell script, so no need for the weird extension
or for the explicit use of /bin/bash

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:16:16 -05:00
Stéphane Graber
cbe3a58b13 Remove duplicate copy of runapitests.bash
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:16:16 -05:00
Stéphane Graber
be2e4e54da Add python-lxc based on the new liblxc API.
This adds a basic python binding done in C and a python overlay to
extend some features and provide a user-friendlier API.

This python API only supports python 3.x and was tested with >= 3.2.

It's disabled by default in configure and can be turned on by using
--enable-python.

A basic example of the API can be found in src/python-lxc/test.py.
More documentation and examples will be added soon.
2012-11-12 13:16:16 -05:00
Stéphane Graber
7a44c8b447 When starting a container daemonized, wait for it to reach RUNNING state before returning the result of start().
If the container doesn't reach RUNNING state in 5 seconds, a failure will be
returned to the user.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:16:16 -05:00
Stéphane Graber
72d0e1cb2f Merge the liblxc API work by Serge Hallyn.
This turns liblxc into a public library implementing a container structure.
The container structure is meant to cover most LXC commands and can easily be
used to write bindings in other programming languages.

More information on the new functions can be found in src/lxc/lxccontainer.h
Test programs using the API can also be found in src/tests/

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-12 13:16:16 -05:00
Christian Seiler
7a0b0b5672 lxc-attach: Add -R option to remount /sys and /proc when only partially attaching
When attaching to only some namespaces of the container but not the mount
namespace, the contents of /sys and /proc of the host system do not properly
reflect the context of the container's pid and/or network namespaces, and
possibly others.

The introduced -R option adds the possibility to additionally unshare the
mount namespace (when it is not being attached) and remount /sys and /proc
in order for those filesystems to properly reflect the container's context
even when only attaching to some of the namespaces.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
Cc: Daniel Lezcano <daniel.lezcano@free.fr>
2012-11-12 13:16:16 -05:00
Christian Seiler
e13eeea2db lxc-attach: Add -s option to select namespaces to attach to
This patch allows the user to select any list of namespaces (network, pid,
mount, uts, ipc, user) that lxc-attach should use when attaching to the
container; all other namespaces will not be attached to.

This allows the user to for example attach to just the network namespace and
use the host's (and not the container's) network tools to reconfigure the
network of the container.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Cc: Daniel Lezcano <daniel.lezcano@free.fr>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
2012-11-12 13:15:17 -05:00
Christian Seiler
39a5d5feee lxc-unshare: Move functions to determine clone flags from command line options to namespace.c
In order to be able to reuse code in lxc-attach, the functions
lxc_namespace_2_cloneflag and lxc_fill_namespace_flags are moved from
lxc_unshare.c to namespace.c.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Cc: Daniel Lezcano <daniel.lezcano@free.fr>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
2012-11-12 13:13:52 -05:00
Christian Seiler
fc763ab77d lxc-attach: Detect which namespaces to attach to dynamically
Use the command interface to contact lxc-start to receive the set of
flags passed to clone() when starting the container. This allows lxc-attach
to determine which namespaces were used for the container and select only
those to attach to.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Cc: Daniel Lezcano <daniel.lezcano@free.fr>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
2012-11-12 13:13:52 -05:00
Christian Seiler
c8f7c5630e lxc-attach: Remodel cgroup attach logic and attach to namespaces again in parent process
With the introduction of lxc-attach's functionality to attach to cgroups,
the setns() calls were put in the child process after the fork() and not the
parent process before the fork() so the parent process remained outside the
namespaces and could add the child to the correct cgroup.

Unfortunately, the pid namespace really affects only children of the current
process and not the process itself, which has several drawbacks: The
attached program does not have a pid inside the container and the context
that is used when remounting /proc from that process is wrong. Thus, the
previous logic of first setting the namespaces and then forking so the child
process (which then exec()s to the desired program) is a real member of the
container.

However, inside the container, there is no guarantee that the cgroup
filesystem is still be mounted and that we are allowed to write to it (which
is why the setns() was moved in the first place).

To work around both problems, we separate the cgroup attach functionality
into two parts: Preparing the attach process, which just opens the tasks
files of all cgroups and keeps the file descriptors open and the writing to
those fds part. This allows us to open all the tasks files in lxc_attach,
then call setns(), then fork, in the child process close them completely and
in the parent process just write the pid of the child process to all those
fds.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Cc: Daniel Lezcano <daniel.lezcano@free.fr>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
2012-11-12 13:13:52 -05:00
Christian Seiler
d5088cf2d3 lxc-start: Add command to retrieve the clone flags used to start the container.
Add the LXC_COMMAND_CLONE_FLAGS that retrieves the flags passed to clone(2)
when the container was started. This allows external programs to determine
which namespaces the container was unshared from.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Cc: Daniel Lezcano <daniel.lezcano@free.fr>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
2012-11-12 13:13:52 -05:00
Serge Hallyn
1881820ae4 lxc-create: Make location of container rootfs configurable
Make 'dir' an explicit backing store type, which accepts '--dir rootfs'
as an option to specify a custom location for the container rootfs.  Also
update lxc-destroy to now remove the rootfs separately, as removing
@LXCPATH@/$name may not hit it.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 13:13:52 -05:00
Jan Kiszka
74a2b5864f Add network-down script
Analogously to lxc.network.script.up, add the ability to register a down
script. It is called before the guest network is finally destroyed,
allowing to clean up resources that are not reset/destroyed
automatically. Parameters of the down script are identical to the up
script except for the execution context "down".

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 12:04:30 -05:00
Serge Hallyn
c8dee0f165 Makefile.am: use right .h file name for seccomp
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 12:04:30 -05:00
Serge Hallyn
e767dd5599 fix configure.ac for seccomp and apparmor
Use --enable-XXX=check when not specified to get reasonable defaults.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 12:04:30 -05:00
Serge Hallyn
0d0527a929 seccomp: include lxcseccomp.h in start.c
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 12:04:30 -05:00
Serge Hallyn
09ad624693 confile: support 'lxc.include' option to include other config files
For instance

lxc.include = /var/lib/lxc/commonopts

in /var/lib/lxc/q1/config would cause the configuration in
/var/lib/lxc/commonopts to be loaded when container q1 starts.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 12:04:30 -05:00
Serge Hallyn
8f2c3a702a Introduce support for seccomp.
Hi,

This patch is so far just a proof of concept.  The libseccomp api will be
changing soon so it probably wouldn't be worth pulling this until it is
updated for the new API.

This patch introduces support for seccomp to lxc.  Seccomp lets a program
restrict its own (and its children's) future access to system calls.  It
uses a simple whitelist system call policy file.  It would probably be
better to switch to something more symbolic (i.e specifying 'open' rather
than the syscall #, especially given container arch flexibility).

I just wanted to get this out there as a first step.  You can also get
source for an ubuntu package based on this patch at
https://code.launchpad.net/~serge-hallyn/ubuntu/quantal/lxc/lxc-seccomp

Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com>
2012-11-12 12:04:30 -05:00
Jan Kiszka
b486346aa2 lxc-wait: Add timeout option
Allow to specify a timeout for waiting on state changes via lxc-wait.
Helpful for scripts that need to handle errors or excessive delays in
state changing procedures.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-11-12 12:03:23 -05:00
Daniel Lezcano
4aa7ac3569 Version 0.8.0
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-11-11 03:34:22 +01:00
Daniel Lezcano
aa69e175ff fix git location
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-11-11 03:32:51 +01:00
Daniel Lezcano
5480b13b1c clearer error message when interface name to long
Signed-off-by: Tomas Pospisek <tpo_deb@sourcepole.ch>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-10-31 17:15:35 +01:00
Dwight Engen
a24c5a40dc Fix lxc-netstat -- argument processing
Commit 21e487f2 introduced the use of getopt, but getopt will fail when
it sees arguments meant for netstat that are not in [short|long]options.
There should not be any ambiguity about arguments with the same letter:
those to the left of the -- are destined for lxc-netstat and those to
the right for the real netstat, which the original code handles by
shifting out all arguments it recognizes before the -- is hit.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-10-31 17:08:13 +01:00
Dwight Engen
a3812bf0c7 Fix lxc-ps -- argument processing
lxc-ps is supposed to pass arguments after the -- on to ps. The problem is
that i is expanded once from $@ and the loop will iterate over all the
arguments that were in $@ at the time of expansion. Inside the loop, there
are shifts (in the name case for example) that are trying to remove more
than a single argument. This changes fixes that and makes lxc-ps work as
documented.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-10-31 17:08:13 +01:00
Dwight Engen
f7a81eeb14 Remove unneeded ksrc spec file macro
Change 910bb4fa obviated the need for the --with-linuxdir configure
option which means that the ksrc rpm macro no longer makes sense either.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-10-31 17:08:13 +01:00
Dwight Engen
c4b697f261 Add %{dist} tag to differentiate RPM distributions and releases
Note that an additional Release field is not necessary for the devel package
as it will follow the primary Release field. For more information on the dist
tag, see http://fedoraproject.org/wiki/Packaging:DistTag

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-10-31 17:08:13 +01:00
Daniel Lezcano
7f99e33936 Merge branch 'upstream-bugfix' of https://github.com/lxc/lxc
* 'upstream-bugfix' of https://github.com/lxc/lxc: (47 commits)
  replace HOOK define with proper code.
  Remove lxc-start-ephemeral from configure.ac
  revert devtmpfs in ubuntu templates
  lxc-ubuntu{-cloud}: Fix missing "fi" in new devtmpfs code
  fix "make rpm"
  display warning when yum missing in fedora template
  templates: mount devtmpfs in ubuntu containers
  handle clone of btrfs snapshots
  if the rootfs is a btrfs subvolume, delete it instead of rm -rf
  lxc-debian: replace isc-dhcp-server by isc-dhcp-client
  lxc-ls: Scan cgroup mount points from fstype and not device
  Allow short -h and -n options to lxc-ps
  lxc-ubuntu: fix printing of default user
  lxc-debian: specify isc-dhcp-server in package list
  try to better handle out of date container caches.
  link /dev/kmsg to /dev/console in the container
  lxc-clone: fix the '--name' parameter
  lxc-ls: Use readlink on $directory
  lxc-busybox: Use relative mounts in lxc.mount.entry
  busybox: for all lib dirs create mounts only if directories exist
  ...

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-10-31 16:40:11 +01:00
Serge Hallyn
773fb9cad7 replace HOOK define with proper code.
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-10-25 10:51:09 +02:00
Stéphane Graber
8215fe8e41 Remove lxc-start-ephemeral from configure.ac
lxc-start-ephemeral.in ended up in configure.ac as a result of the
cherry-pick. This new tool hasn't been pulled in yet.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-10-25 10:43:59 +02:00
Serge Hallyn
192df6e2eb revert devtmpfs in ubuntu templates
devtmpfs is shared between host and containers, and it messes up
lucid containers too.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-10-25 10:37:59 +02:00
Stéphane Graber
c215bff6df lxc-ubuntu{-cloud}: Fix missing "fi" in new devtmpfs code
The "if" statement to add devtmpfs was missing a matching "fi" causing parsing
error when using the template.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-10-25 10:37:54 +02:00
Dwight Engen
0b53175846 fix "make rpm"
RPM doesn't like "-" in the version number and gives:
"error: line 24: Illegal char '-' in: Version: 0.8.0-rc2"
Other packages (bind-utils for example) have used . instead
of - as a seperator.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-10-25 10:37:38 +02:00