]> git.ipfire.org Git - thirdparty/lxc.git/log
thirdparty/lxc.git
11 years agocgroup: re-introduce ns cgroup support
Serge Hallyn [Wed, 11 Sep 2013 16:50:54 +0000 (11:50 -0500)] 
cgroup: re-introduce ns cgroup support

If a cgroup hierarchy has ns cgroup composed, then we need to treat
that differently:

1. The container init will have already been switched to a new cgroup
called after its pid.
2. We can't move the container init to new deeper cgroup directories.

So, if we detect an ns cgroup, don't bother trying to construct a new
name according to the pattern.  Just rename the current one to the
container name, and save that path for us to later enter and remove.

Note I'm not dealing with the subpaths so nested containers probably
won't work.  However as ns cgroup is very much legacy, that should be
ok.  Eventually we should be able to drop ns cgroup support altogether,
but not just yet.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoapparmor.c: drop newline when reading current profile
Serge Hallyn [Tue, 10 Sep 2013 22:23:22 +0000 (17:23 -0500)] 
apparmor.c: drop newline when reading current profile

Otherwise we fail to recognize if we are already unconfined.  Then,
if we want to *start* unconfined, and /proc is readonly, start fails
even though it should be able to proceed.

With this patch, that situation works.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Reported-by: Andre nathan <andre@digirati.com.br>
11 years agoFix some typos
Stéphane Graber [Wed, 11 Sep 2013 14:01:16 +0000 (10:01 -0400)] 
Fix some typos

Signed-off-by: KATOH Yasufumi karma@jazz.email.ne.jp
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agopin_rootfs: be quiet and don't fail container start
Serge Hallyn [Wed, 11 Sep 2013 04:17:46 +0000 (23:17 -0500)] 
pin_rootfs: be quiet and don't fail container start

It's a legitimate use case to use read-only $lxcpath.  If we can't
create the pin file, then we're not worried about marking the fs
readonly on exit.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc_cgroup_process_info_free_and_remove should recursively call itself
Serge Hallyn [Tue, 10 Sep 2013 19:33:40 +0000 (14:33 -0500)] 
lxc_cgroup_process_info_free_and_remove should recursively call itself

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agodon't use cgroup_path_components un-initialized
Serge Hallyn [Tue, 10 Sep 2013 19:33:00 +0000 (14:33 -0500)] 
don't use cgroup_path_components un-initialized

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocgroup: Major rewrite of cgroup logic
Christian Seiler [Sun, 8 Sep 2013 18:50:03 +0000 (20:50 +0200)] 
cgroup: Major rewrite of cgroup logic

This patch rewrites most of the cgroup logic. It creates a set of data
structures to store the kernel state of the cgroup hierarchies and
their mountpoints.

Mainly, everything is now grouped with respect to the hierarchies of
the system. Multiple controllers may be mounted together or separately
to different hierarchies, the data structures reflect this.

Each hierarchy may have multiple mount points (that were created
previously using the bind mount method) and each of these mount points
may point to a different prefix inside the cgroup tree. The current
code does not make any assumptions regarding the mount points, it just
parses /proc/self/mountinfo to acquire the relevant information.

The only requirement is that the current cgroup of either init (if
cgroup.pattern starts with '/' and the tools are executed as root) or
the current process (otherwise) are accessible. The root cgroup need
not be accessible.

The configuration option cgroup.pattern is introduced. For
root-executed containers, it specifies which format the cgroups should
be in. Example values may include '/lxc/%n', 'lxc/%n', '%n' or
'/machine/%n.lxc'. Any occurrence of '%n' is replaced with the name of
the container (and if clashes occur in any hierarchy, -1, -2, etc. are
appended globally). If the pattern starts with /, new containers'
cgroups will be located relative to init's cgroup; if it doesn't, they
will be located relative to the current process's cgroup.

Some changes to the cgroup.h API have been done to make it more
consistent, both with respect to naming and with respect to the
parameters. This causes some changes in other parts of the code that
are included in the patch.

There has been some testing of this functionality, but there are
probably still quite a few bugs in there, especially for people with
different configurations.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoremove unused lxc_read_line_from_file()
Serge Hallyn [Tue, 10 Sep 2013 19:30:43 +0000 (14:30 -0500)] 
remove unused lxc_read_line_from_file()

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoutils: Add utility functions that write/read to entire files
Christian Seiler [Sun, 8 Sep 2013 12:14:48 +0000 (14:14 +0200)] 
utils: Add utility functions that write/read to entire files

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoutils: Add string and array utility functions
Christian Seiler [Sun, 8 Sep 2013 11:51:50 +0000 (13:51 +0200)] 
utils: Add string and array utility functions

Adds a few useful string and array manipulation functions to utils.[ch]

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agofopen_cloexec: simplify open call
Serge Hallyn [Tue, 10 Sep 2013 19:29:10 +0000 (14:29 -0500)] 
fopen_cloexec: simplify open call

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoAdd fopen_cloexec function to emulate 'e' mode
Christian Seiler [Sun, 8 Sep 2013 11:43:46 +0000 (13:43 +0200)] 
Add fopen_cloexec function to emulate 'e' mode

Newer glibc versions (that we can't require) allow for an additional
letter 'e' in the fopen mode that will cause the file to be opened with
the O_CLOEXEC flag, so that it will be closed if the program exec()s
away. This is important because if liblxc is used in a multithreaded
program, another thread might want to run a program. This options
prevents the leakage of file descriptors from LXC. This patch adds an
emulation for that that uses the open(2) syscall and fdopen(3). At some
later point in time, it may be dropped against fopen(..., "...e").

This commit also converts all fopen() calls in utils.c (where the
function is added) to fopen_cloexec(). Subsequently, other calls to
fopen() and open() should also be adapted.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoAdd cgroup.pattern global configuration option
Christian Seiler [Sun, 8 Sep 2013 11:43:13 +0000 (13:43 +0200)] 
Add cgroup.pattern global configuration option

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoglobal config: Unify parsing, add additional checks
Christian Seiler [Sun, 8 Sep 2013 11:38:55 +0000 (13:38 +0200)] 
global config: Unify parsing, add additional checks

Instead of duplicating the code for parsing the global config file for
each option, write one main function, lxc_global_config_value, that
does the parsing for an arbitrary option name and just call that
function from the existing ones.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoerror.c: don't return error if container init signaled
Serge Hallyn [Mon, 9 Sep 2013 20:35:52 +0000 (15:35 -0500)] 
error.c: don't return error if container init signaled

We log that at INFO level in case it is needed.  However, in a modern
kernel a container which was shut down using 'shutdown' will always
have been signaled with SIGINT.  Making lxc-start return an error to
reflect that seems overkill.

It's *conceivable* that someone is depending on this behavior, so I'm
sending this out for anyone to NACK, but if I hear no complaints I'll
apply.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agointroduce lxc-snapshot
Serge Hallyn [Fri, 6 Sep 2013 23:11:05 +0000 (18:11 -0500)] 
introduce lxc-snapshot

Hopefully someone else will come in and spruce it up :)  This
version is as simple as can be

lxc-snapshot -n a1
create a snapshot of a1
echo "second commit" > /tmp/a
lxc-snapshot -n a1 -c /tmp/a
create a snapshot of a1 with /tmp/a as a commit comment
lxc-snapshot -n a1 -L
list a1's snapshots
lxc-snapshot -n a1 -L -C
list a1's snapshots along with commit comments
lxc-snapshot -n a1 -r snap0 a2
restore snapshot 0 of a1 as container a2

Some easy nice-to-haves:

1. sort snapshots in the list
2. allow a comment to be given in-line
3. an option to remove a snapshot?

Removing a snapshot can just as well be done with

lxc-destroy -P /var/lib/lxcsnaps/c1 -n snap2

so I leave it to others to decide whether they really want
it, and provide the patch if so.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoAPI support for container snapshots (v2)
Serge Hallyn [Fri, 6 Sep 2013 23:07:47 +0000 (18:07 -0500)] 
API support for container snapshots (v2)

The api allows for creating, listing, and restoring of container
snapshots.  Snapshots are created as snapshot clones of the
original container - i.e. btrfs and lvm will be done as snapshot,
a directory-backed container will have overlayfs snapshots.  A
restore is a copy-clone, using the same backing store as the
original container had.

Changelog:

 . remove lxcapi_snap_open, which wasn't defined anyway.
 . rename get_comment to get_commentpath
 . if no newname is specified at restore, use c->name (as we meant to)
   rather than segving.
 . when choosing a snapshot index, use the correct path to check for.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoFixed opensuse template to make lxc-shutdown work.
Cedric Bosdonnat [Tue, 10 Sep 2013 16:00:41 +0000 (18:00 +0200)] 
Fixed opensuse template to make lxc-shutdown work.

The fix is described by:
https://wiki.archlinux.org/index.php/Linux_Containers#Container_cannot_be_shutdown_if_using_systemd

Signed-off-by: Cedric Bosdonnat <cbosdonnat@suse.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoAdd Japanese man pages.
KATOH Yasufumi [Thu, 5 Sep 2013 11:38:32 +0000 (11:38 +0000)] 
Add Japanese man pages.

Japanese man pages is installed under $mandir/ja.
At this time, it is based on version 0.9.0.

11 years agochange version to 1.0.0.alpha1 in configure.ac lxc-1.0.0.alpha1
Daniel Lezcano [Tue, 10 Sep 2013 21:55:26 +0000 (23:55 +0200)] 
change version to 1.0.0.alpha1 in configure.ac

Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr>
11 years agoMerge git://github.com/lxc/lxc
Daniel Lezcano [Mon, 9 Sep 2013 19:07:12 +0000 (21:07 +0200)] 
Merge git://github.com/lxc/lxc

Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr>
11 years agoconfigure: enable Lua if found and continue without if not
Natanael Copa [Fri, 6 Sep 2013 19:09:57 +0000 (21:09 +0200)] 
configure: enable Lua if found and continue without if not

Search for Lua if no --enable-lua/--disable-lua specified but continue
without if not found.

If --enable-lua is specified and Lua is not found then return error.

If --disable-lua is specified, then don't search for Lua.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolxc_spawn: don't close pinfd until container is stopped
Serge Hallyn [Fri, 6 Sep 2013 17:25:47 +0000 (12:25 -0500)] 
lxc_spawn: don't close pinfd until container is stopped

Otherwise containers may be able to remount -o ro their rootfs
at shutdown.

Reported-by: Harald Dunkel <harri@afaics.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolua: fix logic to enable lua support in configure
Natanael Copa [Fri, 6 Sep 2013 07:08:45 +0000 (09:08 +0200)] 
lua: fix logic to enable lua support in configure

When there is no --enable-lua or --with-lua-pc, Lua should not be
enabled.

This fixes a bug introduced with 12e93188 (configure/makefile:
Allow specify Lua pkg-config file with --with-lua-pc) that caused
configure script to fail if lua headers was missing.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agosanity-check number of detected capabilities
Serge Hallyn [Fri, 6 Sep 2013 01:31:55 +0000 (20:31 -0500)] 
sanity-check number of detected capabilities

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoadd AS_VAR_COPY for older autoconf versions
Dwight Engen [Thu, 5 Sep 2013 20:40:49 +0000 (16:40 -0400)] 
add AS_VAR_COPY for older autoconf versions

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolua: fix stats gathering
Dwight Engen [Thu, 5 Sep 2013 19:20:44 +0000 (15:20 -0400)] 
lua: fix stats gathering

- remove lxc subdir in cgroup paths (done in commit b98f7d6e)
- remove extraneous debug printfs
- remove extra call to stats_clear

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolua: implement dirname in C rather than depend on external executable
Natanael Copa [Thu, 5 Sep 2013 13:29:20 +0000 (15:29 +0200)] 
lua: implement dirname in C rather than depend on external executable

Instead of popen and run external executable dirname we implement a
dirname in C in the core module.

We also remove the unused basename function.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolua: implement usleep in C module
Natanael Copa [Thu, 5 Sep 2013 12:33:28 +0000 (14:33 +0200)] 
lua: implement usleep in C module

So we avoid running os.execute

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoconfigure/makefile: Allow specify Lua pkg-config file with --with-lua-pc
Natanael Copa [Thu, 5 Sep 2013 15:13:07 +0000 (17:13 +0200)] 
configure/makefile: Allow specify Lua pkg-config file with --with-lua-pc

Enable support for both Lua 5.1 and 5.2 by letting user specify the Lua
pkg-config package name. By default it will use 'lua' and try figure
out which version it is.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolua: prepare for Lua 5.2
Natanael Copa [Thu, 5 Sep 2013 06:45:33 +0000 (08:45 +0200)] 
lua: prepare for Lua 5.2

Adjust code for Lua 5.2 and keep compatibility with Lua 5.1.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolua: fix a bug in the parsing of /proc/mounts
Natanael Copa [Thu, 5 Sep 2013 19:07:51 +0000 (15:07 -0400)] 
lua: fix a bug in the parsing of /proc/mounts

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoclone: don't copy rdepends when not doing a snapshot clone
Serge Hallyn [Thu, 5 Sep 2013 23:05:34 +0000 (18:05 -0500)] 
clone: don't copy rdepends when not doing a snapshot clone

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agofix typo
Serge Hallyn [Thu, 5 Sep 2013 22:59:28 +0000 (17:59 -0500)] 
fix typo

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agointroduce lxc.cap.keep
Serge Hallyn [Fri, 14 Jun 2013 03:43:01 +0000 (22:43 -0500)] 
introduce lxc.cap.keep

The lxc configuration file currently supports 'lxc.cap.drop', a list of
capabilities to be dropped (using the bounding set) from the container.
The problem with this is that over time new capabilities are added.  So
an older container configuration file may, over time, become insecure.

Walter has in the past suggested replacing lxc.cap.drop with
lxc.cap.preserve, which would have the inverse sense - any capabilities
in that set would be kept, any others would be dropped.

Realistically both have the same problem - the sendmail capabilities
bug proved that running code with unexpectedly dropped privilege can be
dangerous.  This patch gives the admin a choice:  You can use either
lxc.cap.keep or lxc.cap.drop, not both.

Both continue to be ignored if a user namespace is in use.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agobdev: free after bdev_init
Serge Hallyn [Thu, 5 Sep 2013 21:56:54 +0000 (16:56 -0500)] 
bdev: free after bdev_init

(Except in cases where we will immediately exit)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agovalgrind: fix memory leak on container new/put
Dwight Engen [Wed, 4 Sep 2013 21:04:51 +0000 (17:04 -0400)] 
valgrind: fix memory leak on container new/put

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-alpine: add hwaddr for a single macvlan interface
Natanael Copa [Wed, 4 Sep 2013 15:01:09 +0000 (17:01 +0200)] 
lxc-alpine: add hwaddr for a single macvlan interface

We already add harware address for a single veth interface. Do the same
with a single macvlan interface.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agobdev_copy segfaults if bdevtype is NULL
S.Çağlar Onur [Tue, 3 Sep 2013 20:21:15 +0000 (16:21 -0400)] 
bdev_copy segfaults if bdevtype is NULL

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agotests: Add lxc-test-usernic to the dist tarball
Stéphane Graber [Tue, 3 Sep 2013 19:11:07 +0000 (15:11 -0400)] 
tests: Add lxc-test-usernic to the dist tarball

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolicensing: Add missing headers and FSF address
Stéphane Graber [Tue, 3 Sep 2013 18:29:46 +0000 (14:29 -0400)] 
licensing: Add missing headers and FSF address

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoubuntu: iproute is now called iproute2
Stéphane Graber [Tue, 3 Sep 2013 15:36:09 +0000 (11:36 -0400)] 
ubuntu: iproute is now called iproute2

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agolua: update license
Serge Hallyn [Tue, 3 Sep 2013 12:56:11 +0000 (07:56 -0500)] 
lua: update license

As with other files, update to be LGPL since these are part
of the lxc library.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agopython: Fix api_test to use the new attach() API
Stéphane Graber [Fri, 30 Aug 2013 21:27:14 +0000 (17:27 -0400)] 
python: Fix api_test to use the new attach() API

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-commands: add a comment explaining CMD_* rules
Serge Hallyn [Tue, 3 Sep 2013 13:08:39 +0000 (08:08 -0500)] 
lxc-commands: add a comment explaining CMD_* rules

We wish to ensure that, henceforth, newer lxc tools are always compatible
with older lxc monitors.  Add a comment to commands.c to explain the
rule we wish to enforce to this end.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoremove old stale comments (lxc-clone is now implemented)
Serge Hallyn [Fri, 30 Aug 2013 20:51:31 +0000 (15:51 -0500)] 
remove old stale comments (lxc-clone is now implemented)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoAdd a section about licensing to CONTRIBUTING
Stéphane Graber [Fri, 30 Aug 2013 19:56:21 +0000 (15:56 -0400)] 
Add a section about licensing to CONTRIBUTING

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agofix license text in ubuntu and ubuntu-cloud templates
Serge Hallyn [Fri, 30 Aug 2013 19:43:09 +0000 (14:43 -0500)] 
fix license text in ubuntu and ubuntu-cloud templates

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agofix wrong license text for parts of liblxc library
Serge Hallyn [Fri, 30 Aug 2013 19:42:20 +0000 (14:42 -0500)] 
fix wrong license text for parts of liblxc library

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoavoid zgrep -q as it's failing on some distros
Stéphane Graber [Fri, 30 Aug 2013 16:08:26 +0000 (12:08 -0400)] 
avoid zgrep -q as it's failing on some distros

Reported-by: Filirom1
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agofedora: Add missing double-quotes.
Stéphane Graber [Fri, 30 Aug 2013 15:47:58 +0000 (11:47 -0400)] 
fedora: Add missing double-quotes.

Reported-by: tlc
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoFix some typos
Stéphane Graber [Fri, 30 Aug 2013 15:43:19 +0000 (11:43 -0400)] 
Fix some typos

Signed-off-by: Dmitry Shachnev <mitya57@ubuntu.com>
Reported-by: Vincent Ladeuil
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agostart.c: handle potential signal flood
Serge Hallyn [Thu, 29 Aug 2013 15:41:19 +0000 (10:41 -0500)] 
start.c: handle potential signal flood

Signalfd does not guarantee that we'll get an event for every signal.
So if 3 tasks exit at the same time, we may get only one sigchld
event.  Therefore, in signal_handler(), always check whether init has
exited.  Do with with WNOWAIT so that we can still wait4 to cleanup
the init after lxc_poll() exists (rather than complicating the code).

Note - there is still a race in the kernel which can cause the
container init to become a defunct child of the host init (!).  This
doesn't solve that, but is a potential (if very unlikely) race which
apw pointed out while we were trying to create a reproducer for the
kernel bug.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolxc-alpine: create /dev/zero
Natanael Copa [Mon, 26 Aug 2013 11:47:58 +0000 (13:47 +0200)] 
lxc-alpine: create /dev/zero

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoconfig_ipv6: run inet_pton on the addr value without mask
Serge Hallyn [Fri, 23 Aug 2013 17:45:15 +0000 (12:45 -0500)] 
config_ipv6: run inet_pton on the addr value without mask

otherwise a "$addr/$mask" results in failure.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoapi: convert lxc_start
Serge Hallyn [Thu, 22 Aug 2013 15:27:40 +0000 (10:27 -0500)] 
api: convert lxc_start

Normal lxc-start usage tends to be "lxc-start -n name [-P lxcpath]".
This causes $lxcpath/$name/config to be the configuration for the
container.  However, lxc-start is more flexible than that.  You can
specify a custom configuration file, in which case $lxcpath/$name/config
is not used.  You can also (in addition or in place of either of these)
specify configuration entries one-by-one using "-s lxc.utsname=xxx".

To support this using the API, if we are not using
$lxcpath/$name/config then we put ourselves into a custom lxcpath
called (configurable using LXCPATH) /var/lib/lxc_anon.  To stop a
container so created, then, you would use

lxc-stop -P /var/lib/lxc_anon -n name

TODO: we should walk over the list of &defines by hand and set them
using c->set_config_item.  I haven't done that in this patch.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agohooks/ubuntu-cloud-prep: add hostname to meta-data
Scott Moser [Thu, 22 Aug 2013 19:38:48 +0000 (15:38 -0400)] 
hooks/ubuntu-cloud-prep: add hostname to meta-data

prior to my enabling of the clone hook, the setting of the hostname
was being done by writing to /etc/hostname.  Instead of relying on that
we're now writing 'local-hostname' into the metadata for the instance.

cloud-init then reads this and sets the hostname properly.

We are also writing /etc/hostname with the new hostname explicitly.  This is
useful/necessary because on network bringup of eth0, dhclient will submit its
hosname.  The updating done by cloud-init occurs to late, and thus
the dhcp request goes out with the un-configured hostname and dns doens't
work correctly.

Signed-off-by: Scott Moser <smoser@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoapi: convert lxc_wait, lxc_freeze, and lxc_unfreeze
Serge Hallyn [Wed, 21 Aug 2013 21:53:52 +0000 (16:53 -0500)] 
api: convert lxc_wait, lxc_freeze, and lxc_unfreeze

These are the last of the simpler conversions.  Start, execute,
kill, info and attach remain to be done.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
11 years agolxc_cgroup: convert to using API
Serge Hallyn [Wed, 21 Aug 2013 19:35:28 +0000 (14:35 -0500)] 
lxc_cgroup: convert to using API

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoTrack snapshot dependencies (v2)
Serge Hallyn [Wed, 21 Aug 2013 19:43:52 +0000 (14:43 -0500)] 
Track snapshot dependencies (v2)

(Will push in a bit barring any objections)

lvm, btrfs, and zfs snapshots each do an ok job of handling deletions
for us - a btrfs snapshot does fine after the original is removed,
while zfs and lvm will both refuse to allow the original to be deleted
while the snapshot exists.

Overlayfs doesn't do this for us.  So, for overlayfs snapshots, track
the dependencies.

When c2 is created as an overlayfs snapshot of dir-backed c1, then

1. c2's lxc_rdepends file will contain

c1_lxcpath
c1_lxcname

2. c1's lxc_snapshots will contain "1"

c1 cannot be deleted so long as lxc_snapshots exists and contains
a non-zero number.

The contents of lxc_snapshots and lxc_rdepends are protected by
container_disk_lock() and at lxc_clone by the new container not yet
being accessible.

(Originally I was going to keep them in the container config, but the
problem with using $lxcpath/$name/config is that api users could end up
calling c->save_config() with a cached old value of snapshots/rdepends.)

Changelog:
aug 21: check for fprintf and fclose failures

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
11 years agoavoid very unlikely race due to EEXIST
Serge Hallyn [Tue, 20 Aug 2013 23:15:06 +0000 (18:15 -0500)] 
avoid very unlikely race due to EEXIST

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocoverity: make indent match nest level
Serge Hallyn [Tue, 20 Aug 2013 23:01:07 +0000 (18:01 -0500)] 
coverity: make indent match nest level

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocoverity: dont dereference before null check
Serge Hallyn [Tue, 20 Aug 2013 22:59:19 +0000 (17:59 -0500)] 
coverity: dont dereference before null check

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocoverity: don't leak partial_fd
Serge Hallyn [Tue, 20 Aug 2013 22:54:19 +0000 (17:54 -0500)] 
coverity: don't leak partial_fd

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocoverity: don't leak open DIR
Serge Hallyn [Tue, 20 Aug 2013 22:48:54 +0000 (17:48 -0500)] 
coverity: don't leak open DIR

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocoverity: correctly handle tpath error case.
Serge Hallyn [Tue, 20 Aug 2013 21:58:24 +0000 (16:58 -0500)] 
coverity: correctly handle tpath error case.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocoverity: ftell returns long, not size_t (which is unsigned)
Serge Hallyn [Tue, 20 Aug 2013 21:50:25 +0000 (16:50 -0500)] 
coverity: ftell returns long, not size_t (which is unsigned)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocoverity: don't bother getting template path if we're not going to measure it
Serge Hallyn [Tue, 20 Aug 2013 21:29:29 +0000 (16:29 -0500)] 
coverity: don't bother getting template path if we're not going to measure it

This should also fix a memory leak, since we were freeing it under ifdef
but always allocating it.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoubuntu-cloud-prep: improve overlayfs workaround
Scott Moser [Mon, 19 Aug 2013 14:18:37 +0000 (10:18 -0400)] 
ubuntu-cloud-prep: improve overlayfs workaround

the previous 'patch_start' can be vastly simplified now that I better
understand what the bug was.  Instead of wrapping 'start', we only
need to ensure that /etc/init exists inside the overlayfs, so that the
directory that upstart watches is guaranteed to be in the overlay, not
the underlay.

The problem is described under bug 1213925.

Signed-off-by: Scott Moser <smoser@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocgroup updates: fix several bugs
Ubuntu [Mon, 19 Aug 2013 13:34:59 +0000 (13:34 +0000)] 
cgroup updates: fix several bugs

1. add cgroup_get_subsys_abspath() which returns the absolute
path for a subsystem mount, and use that where needed to actually
set cgroup values

2. cgroup_devices_has_{allow,deny}: don't mix int and boolean
values.  Also, accept 'a *:* rwm" as any whitelist entry for
has_allow().

3. subsys_lists_match(): fix an off-by-one error in calculating
updated oldlen.  (we need to keep the extra char for '\0')

4. return -1, not 0, if lxc_cgroup_attach fails to open
/proc/self/cgroup.

Signed-off-by: Ubuntu <ubuntu@ip-10-181-158-15.ec2.internal>
11 years agopython/attach: Add function that returns personality for architecture
Christian Seiler [Sun, 18 Aug 2013 22:52:44 +0000 (00:52 +0200)] 
python/attach: Add function that returns personality for architecture

Adds the arch_to_personality function that looks up an architecture
and returns the corresponding personality. This may be used in
conjunction with the attach/attach_wait keyword argument.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agopython/attach: export CLONE_NEW* constants to Python
Christian Seiler [Sun, 18 Aug 2013 22:52:43 +0000 (00:52 +0200)] 
python/attach: export CLONE_NEW* constants to Python

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocgroup: minor bugfixes so start and attach work again
Christian Seiler [Sun, 18 Aug 2013 22:52:40 +0000 (00:52 +0200)] 
cgroup: minor bugfixes so start and attach work again

This fixes some minor bugs in the cgroup logic that made start and
attach fail (at least when all cgroup controllers were mounted
together).

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agopython/attach: Fix minor memory leaks
Christian Seiler [Sun, 18 Aug 2013 22:52:42 +0000 (00:52 +0200)] 
python/attach: Fix minor memory leaks

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoattach: Fix minor memory leak in environment variable handling
Christian Seiler [Sun, 18 Aug 2013 22:52:41 +0000 (00:52 +0200)] 
attach: Fix minor memory leak in environment variable handling

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoRemove all trailing whitespaces
Stéphane Graber [Mon, 19 Aug 2013 12:37:20 +0000 (14:37 +0200)] 
Remove all trailing whitespaces

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoFix lxc-user-nic to work on bionic
Stéphane Graber [Fri, 16 Aug 2013 14:55:40 +0000 (16:55 +0200)] 
Fix lxc-user-nic to work on bionic

This adds a couple of missing includes, uses the local version of
getline on bionic and replaces getpwuid_r by getpwuid.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoAdd missing namespace.h include
Stéphane Graber [Fri, 16 Aug 2013 14:42:39 +0000 (16:42 +0200)] 
Add missing namespace.h include

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoAllow building without confstr
Stéphane Graber [Fri, 16 Aug 2013 14:40:48 +0000 (16:40 +0200)] 
Allow building without confstr

We use confstr to grab the default PATH value. If it's not there, just
use a standard one with bin and sbin for /, /usr and /usr/local.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoDon't define new_personality when building without personalities
Stéphane Graber [Fri, 16 Aug 2013 13:38:13 +0000 (15:38 +0200)] 
Don't define new_personality when building without personalities

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoAdd missing sys/socket.h include
Stéphane Graber [Fri, 16 Aug 2013 13:35:51 +0000 (15:35 +0200)] 
Add missing sys/socket.h include

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoDefine SOCK_CLOEXEC when missing
Stéphane Graber [Fri, 16 Aug 2013 13:35:06 +0000 (15:35 +0200)] 
Define SOCK_CLOEXEC when missing

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoUse srand/rand instead of initstate/random
Stéphane Graber [Fri, 16 Aug 2013 13:22:28 +0000 (15:22 +0200)] 
Use srand/rand instead of initstate/random

initstate/random doesn't work on bionic, srand/rand works on everything,
so let's use that.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoInclude stdio.h in getline.h for FILE
Stéphane Graber [Fri, 16 Aug 2013 13:10:13 +0000 (15:10 +0200)] 
Include stdio.h in getline.h for FILE

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoImport local getline copy on bionic
Stéphane Graber [Fri, 16 Aug 2013 13:08:39 +0000 (15:08 +0200)] 
Import local getline copy on bionic

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoAdd missing sys/select.h include for fd_set
Stéphane Graber [Fri, 16 Aug 2013 13:05:52 +0000 (15:05 +0200)] 
Add missing sys/select.h include for fd_set

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoAdd missing syscall.h include to utils.h
Stéphane Graber [Fri, 16 Aug 2013 10:28:17 +0000 (12:28 +0200)] 
Add missing syscall.h include to utils.h

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoAdd arm defines for __NR_signalfd(4)
Stéphane Graber [Fri, 16 Aug 2013 10:25:28 +0000 (12:25 +0200)] 
Add arm defines for __NR_signalfd(4)

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoAndroid now uses a sane clone() definition
Stéphane Graber [Fri, 16 Aug 2013 10:22:38 +0000 (12:22 +0200)] 
Android now uses a sane clone() definition

The current Android NDK provides a clone() defintion that's identical to
eglibc's so we can drop the ifdef from that one.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoDefine BLKGETSIZE64 and LO_FLAGS_AUTOCLEAR
Stéphane Graber [Fri, 16 Aug 2013 10:19:44 +0000 (12:19 +0200)] 
Define BLKGETSIZE64 and LO_FLAGS_AUTOCLEAR

Those two aren't always around (specifically on bionic), so add some
defines in case they aren't already defined.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoExport the local getmntent_r implementation
Stéphane Graber [Fri, 16 Aug 2013 10:18:15 +0000 (12:18 +0200)] 
Export the local getmntent_r implementation

New code now uses getmntent_r so we need it exported so that it can be
used when building on bionic.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoReplace all calls to rindex by strrchr
Stéphane Graber [Fri, 16 Aug 2013 09:53:11 +0000 (11:53 +0200)] 
Replace all calls to rindex by strrchr

The two functions are identical but strrchr also works on Bionic.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoAdd a local implementation of ifaddrs.h
Stéphane Graber [Fri, 16 Aug 2013 09:47:10 +0000 (11:47 +0200)] 
Add a local implementation of ifaddrs.h

This adds a local ifaddrs implementation to be used on Bionic or other C
libraries that don't come with a getifaddrs implementation.

This code was written by Kenneth MacKay and is under a two-clause BSD
license (copyright information in the file headers).

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoubuntu-cloud-prep: patch /sbin/start for overlayfs
Scott Moser [Fri, 16 Aug 2013 20:47:32 +0000 (16:47 -0400)] 
ubuntu-cloud-prep: patch /sbin/start for overlayfs

upstart depends on inotify, and overlayfs does not support inotify.

That means that the following results in 'tgt' not running. tgt is simply
used here as an example of a service that installs an upstart job and
starts it on package install.
 lxc-clone -s -B overlayfs -o source-precise-amd64 -n test1
 lxc-start -n test1
 ..
 apt-get install tgt

The change here is to modify /sbin/start inside the container so that when
something explicitly tries 'start', it results in an explicit call to
'initctl reload-configuration' so that upstart is aware of the newly
placed job.

Should overlayfs ever gain inotify support, this should still not cause
any harm.

Signed-off-by: Scott Moser <smoser@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-clone: default to overlaysf for -s clone of dir
Serge Hallyn [Fri, 16 Aug 2013 20:50:25 +0000 (15:50 -0500)] 
lxc-clone: default to overlaysf for -s clone of dir

If you go to the trouble to request a -s (snapshot) clone of
a container which is dir backingstore, then you deserve an
overlayfs clone.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agocgroup.c: remove spurious ERROR messages
Serge Hallyn [Fri, 16 Aug 2013 18:34:36 +0000 (13:34 -0500)] 
cgroup.c: remove spurious ERROR messages

Because they are in probing functions.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoReplace a few more str(n)dupa by str(n)dup + free
Stéphane Graber [Fri, 16 Aug 2013 12:57:44 +0000 (14:57 +0200)] 
Replace a few more str(n)dupa by str(n)dup + free

strdup and strndup still don't exist on bionic, so we need to do the
alloc() call ourselves or free the memory by hand.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoAdd attach_options.h to the list of included files
Stéphane Graber [Fri, 16 Aug 2013 10:09:02 +0000 (12:09 +0200)] 
Add attach_options.h to the list of included files

Without this, make dist doesn't include it and LXC fails to build.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agodocument new lxc-create btrfs behavior
Serge Hallyn [Thu, 15 Aug 2013 20:37:30 +0000 (15:37 -0500)] 
document new lxc-create btrfs behavior

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agobdev: support -B best and -B lvm,dir
Serge Hallyn [Thu, 15 Aug 2013 17:55:50 +0000 (12:55 -0500)] 
bdev: support -B best and -B lvm,dir

-B dev will check whether btrfs, zfs, or lvm can be used,
in that order, and fall back to dir.

-B lvm,btrfs will try lvm first, then btrfs, then fail.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>