Commit Graph

1923 Commits

Author SHA1 Message Date
Dwight Engen
8bfcb981de valgrind: fix small leak in cgroup
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-27 12:09:18 -05:00
Christian Seiler
a2ff31c710 Automatic mounting: document options in lxc.conf(5) manpage
Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-27 10:14:14 -05:00
Christian Seiler
7997d7da4d Automatic mounting: add more ways to mount the cgroup filesystem
This adds quite a few more ways to mount the cgroup filesystem
automatically:

 - Specify ro/rw/mixed:
       - ro: everything mounted read-only
       - rw: everything mounted read-write
       - mixed: only container's own cgroup is rw, rest ro
                (default)
 - Add cgroup-full that mounts the entire cgroup tree to the
   corresponding directories. ro/rw/mixed also apply here.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-27 10:14:14 -05:00
Christian Seiler
5f62730e91 Automatic mounting: write lxc.mount.auto in write_config
Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-27 10:14:14 -05:00
Christian Seiler
b06b851168 Automatic mounts: improvements for /proc and /sys
Improve lxc.mount.auto code: allow the user to specify whether to mount
certain things read-only or read-write. Also make the code much more
easily extensible for the future.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-27 10:14:14 -05:00
Stéphane Graber
211e51e81e
lxc-info: Allow printing IP addresses
This adds a new -i flag to lxc-info to print the container's IP
addresses using get_ips().

Example:
$ lxc-info -n lxc-dev -s -p -i
state:  RUNNING
pid:    21331
ip:     10.0.3.165
ip:     2607:f2c0:f00f:2751:e9ca:842f:efa9:97d1
ip:     2607:f2c0:f00f:2751:216:3eff:fe3a:f1c1

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-09-27 09:31:17 -04:00
Stéphane Graber
a9ac16e2cc
lxc-info: Port to LXC API
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-09-27 09:30:52 -04:00
Serge Hallyn
566981770e drop now-useless have_tpath bool
(Which will also break failure-to-build in the !HAVE_LIBGNUTLS
case)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-26 08:14:50 -05:00
Dwight Engen
85db5535c3 fix segfault on lxc-create with bad template name
- change get_template_path() to only return NULL or non-NULL since one of
  the callers was doing a free(-1) which caused the segfault. Handle the
  NULL template case in the lxcapi_create() caller.

- make sure to free(tpath) in the sha1sum_file() failure case

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-09-26 08:11:59 -05:00
Dwight Engen
fe4de9a66d refactor AppArmor into LSM backend, add SELinux support
Currently, a maximum of one LSM within LXC will be initialized and
used. If in the future stacked LSMs become a reality, we can support it
without changing the configuration syntax and add support for more than
a single LSM at a time to the lsm code.

Generic LXC code should note that lsm_process_label_set() will take
effect "now" for AppArmor, and upon exec() for SELinux.

- fix Oracle template mounting of proc and sysfs, needed when using SELinux

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-25 17:12:36 -05:00
Serge Hallyn
3a0abb3aa2 free kernel_subsystems in success case
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-25 15:23:49 -05:00
Serge Hallyn
0ccf7c2a63 REALLY always free(line)
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-25 15:05:52 -05:00
Serge Hallyn
2cdafc545c fix up a few snafu's in forward-port of last commit
Make sure to free line.

Don't free 'info' when freeing base_info will later free info.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-25 15:01:54 -05:00
Dwight Engen
178938fe0a fix some larger memory leaks in cgroup code
Don't worry about saved_errno since none of the *_free routines will set it

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-25 11:07:38 -05:00
Serge Hallyn
b653309a4a split up lxc_cgroup_load_meta2
This one's easier to review by looking at the before and after files.  It
splits up lxc_cgroup_load_meta2() by adding 3 helpers.

The result seems easier to reason about.  A question I had, is, should
the kernel_subsystems ** be freed in the success case?  I assumed it was
being used elsewhere but I can't find where.  Currently it is only being
freed in the error case.  I suspect we want to free it in the success
case as well.

Cc: Christian Seiler <christian@iwakd.de>
Cc: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-25 11:07:35 -05:00
KATOH Yasufumi
7cb14f34a9 doc: Japanese man pages is not generated when docbook-utils is used
Character encoding of Japanese man pages is UTF-8. But docbook-utils
can't treat it (and don't have --encoding option that use in
Makefile). So change to Japanese man pages is not generated when
docbook-utils is used.

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-09-25 09:50:26 -04:00
Qiang Huang
89cd779348 utils: move remove_trailing_slashes to utils
Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-24 09:37:18 -05:00
Qiang Huang
e555005b15 arguments: remove trailing slashes for the input lxcpath
In lxc_cmd(), we use
snprintf(path, len, "%s/%s/command", lxcpath ? lxcpath : inpath, name);
to fill sock name, this assume lxcpath have no trailing slashes, so
if we use
lxc-info -n test -P /usr/local/var/lib/lxc_anon/
to get a running container's state, we will get state: STOPPED which
is wrong, because we combine a wrong sock name.

To fix this, just remove trailing slashes when parsing arguments.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-24 09:37:09 -05:00
Stéphane Graber
9d0cda4f22 doc: Fixed my first name
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-23 15:30:45 -05:00
Stéphane Graber
faefa7f858 doc: Make everything use the @docdtd@ variable
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-23 15:30:35 -05:00
Stéphane Graber
c75c30ec73 Add some missing comments to configure.ac
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-23 15:30:24 -05:00
Stéphane Graber
948955a2d6 Consistently use <lxc/lxccontainer.h> for the API
The API header was included in a variety of ways before, standardize
those to "include <lxc/lxccontainer.h>" as this will always work both in
tree and on a system with the headers installed.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-23 15:30:05 -05:00
Qiang Huang
48e2f384e0 When callback of one config line fail, we'd better give the exactly
info to help users locate the misconfig.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-23 11:23:27 -05:00
S.Çağlar Onur
49badbbef6 return the result of the lxcapi_want_close_all_fds call to the caller
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-23 10:20:29 -05:00
S.Çağlar Onur
130a188840 Expose underlying close_all_fds config value via API
Being able to set close_all_fds via API would be usefull for the
situations like running an application (let's say web server)
that controls the lifecycle of the container using the LXC API.
We don't want forked process to inherit parent's resource (file, socket, ...)

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-09-20 23:48:20 -05:00
Serge Hallyn
6711ffc122 fix console deadlocks
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-09-20 15:28:32 -05:00
Serge Hallyn
e3f46bfbcf lxc-create: add -P to --lxcpath option help text
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-09-18 16:40:04 -05:00
Stéphane Graber
8900b9eb25
Remove trailing whitespaces
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2013-09-18 14:40:20 -05:00
S.Çağlar Onur
799f29ab69 Add get_interfaces to the API
get_ips accepts an interface name as a parameter but there was no
way to get the interfaces names from the container. This patch
introduces a new get_interfaces call to the API so that users
can obtain the name of the interfaces.

Support for python bindings also introduced as a part of this version.

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-09-18 14:35:49 -05:00
Serge Hallyn
025ed0f391 make heavier use of process_lock (v2)
pthread_mutex_lock() will only return an error if it was set to
PTHREAD_MUTEX_ERRORCHECK and we are recursively calling it (and
would otherwise have deadlocked).  If that's the case then log a
message for future debugging and exit.  Trying to "recover" is
nonsense at that point.

process_lock() was held over too long a time in lxcapi_start()
in the daemonize case.  (note the non-daemonized case still needs a
check to enforce that it must NOT be called while threaded).  Add
process_lock() at least across all open/close/socket() calls.

Anything done after a fork() doesn't need the locks as it is no
longer threaded - so some open/close/dups()s are not locked for
that reason.  However, some common functions are called from both
threaded and non-threaded contexts.  So after doing a fork(), do
a possibly-extraneous process_unlock() to make sure that, if we
were forked while pthread mutex was held, we aren't deadlocked by
nobody.

Tested that lp:~serge-hallyn/+junk/lxc-test still works with this
patch.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Tested-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-09-18 13:49:08 -05:00
Dwight Engen
beb6d93ee2 add arguments with getopt to concurrent tester
- add ability to run for multiple iterations
- can also run non-threaded for comparison to threaded case

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-16 16:49:55 -05:00
Dwight Engen
72899b34f1 .gitignore generated Japanese manpages
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-09-16 16:29:46 -04:00
Serge Hallyn
4d7bcfb638 ubuntu templates: make pstore fstab entry optional
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-16 11:48:38 -05:00
Qiang Huang
740d1928fa
cgroup: add bdev.h to fix the build error
Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-09-15 21:56:49 -04:00
Serge Hallyn
4575a9f939 Revert "api_create and api_start: work toward making them thread-safe"
This should deadlock with daemonized start due to af_unix changes.

Do this later, but do it more carefully.

This reverts commit 002f3cff4d.
2013-09-14 13:09:53 -05:00
Serge Hallyn
002f3cff4d api_create and api_start: work toward making them thread-safe
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-14 13:02:50 -05:00
Serge Hallyn
103a2fc072 concurrent: take lxc template to use as argument
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-14 12:54:46 -05:00
Serge Hallyn
84bce17b8b add pstore to container fstab
Otherwise user-namespace containers will hang on mountall.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-09-13 15:55:08 -05:00
S.Çağlar Onur
b130964dd7 use busybox instead of ubuntu to test as it's much more lightweight, also wait containers to enter desired state
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-13 14:06:13 -05:00
S.Çağlar Onur
f209d63a97 tests: Introduce lxc-test-concurrent for testing basic actions concurrently
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-12 17:47:10 -05:00
Serge Hallyn
813a483765 snapshots: add man page and fix up help info a bit.
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-09-12 15:49:16 -05:00
Christian Seiler
b7ed4bf0e2 Change rootfs pinning mechnism
Chane pinning mechanism: Use $rootfs/lxc.hold instead of $rootfs.hold
(in case $rootfs is a mountpoint itself), but delete the file
immediately after creating it (but keep it open). This will keep the
root filesystem busy but does not leave any unnecessary files lying
around.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-12 15:33:58 -05:00
Christian Seiler
368bbc02ba Support for automatic mounting of filesystems
This patch adds the lxc.mount.auto configuration option that allows the
user to specify that certain standard filesystems should be
automatically pre-mounted when the container is started.

Currently, four things are implemented:

 - /proc          (mounted read-write)
 - /sys           (mounted read-only)
 - /sys/fs/cgroup (special logic, see mailing list discussions)
 - /proc/sysrq-trigger (see below)

/proc/sysrq-trigger may be used from within a container to trigger a
forced host reboot (echo b > /proc/sysrq-trigger) or do other things
that a container shouldn't be able to do. The logic here is to
bind-mount /dev/null over /proc/sysrq-trigger, so that that cannot
happen. This obviously only protects fully if CAP_SYS_ADMIN is not
available inside the container (otherwise that bind-mount could be
removed).

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-12 15:33:57 -05:00
Christian Seiler
aae1f3c47b cgroup: Add lxc_setup_mount_cgroup to setup /sys/fs/cgroup inside the container
Add funbction to mount cgroup filesystem hierarchy into the container,
allowing only access to the parts that the container should have access
to, but none else.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-12 11:45:35 -05:00
Christian Seiler
47d8fb3be0 cgroup: Split legacy 'ns' cgroup handling off from main cgroup handling
This patch splits off ns legacy cgroup handling from main cgroup
handling. It moves the creation of the cgroups before clone(), so that
the child will easily know which cgroups it will later belong to. Since
this is not possible for the renaming of the 'ns' cgroup, keep that
part after clone.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-12 11:45:34 -05:00
Christian Seiler
24b514827d utils: Add lxc_append_paths to join two paths.
Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-12 11:45:33 -05:00
S.Çağlar Onur
4bee03bc9d Update .gitignore
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-12 11:45:28 -05:00
Serge Hallyn
b336d7246a ignore ability to init /lxc-monitord.log
We may long-term want to instead decide on a convention under
/var/log, but for now just ignore it.  This will only happen
if lxcpath is read-only.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-12 11:17:16 -05:00
Dwight Engen
b45c701178 hash lxcname for use in monitor unix socket sun_path[108]
- Also convert to unix abstract socket
- A simple FNV hash is used instead of SHA-1 since we may not HAVE_GNUTLS

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-12 09:35:05 -05:00
Serge Hallyn
cea0552efb cgroup: address some style+safety issues
three issues raised by Christian Seiler: use pid_t, use snprintf,
and use const.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-09-11 17:04:59 -05:00