Commit Graph

6329 Commits

Author SHA1 Message Date
Christian Brauner
8deca6c986
start: intelligently use clone() on ns sharing
When I first solved this problem I went for a fork() + setns() + clone() model.
This works fine but has unnecessary overhead for a couple of reasons:

- doing a full fork() including copying file descriptor table and virtual
  memory
- using pipes to retrieve the pid of the second child (the actual container
  process)

This can all be avoided by being a little smart in how we employ the clone()
syscall:

- using CLONE_VM will let us get rid of using pipes since we can simply write
  to the handler because we share the memory with our parent
- using CLONE_VFORK will also let us get rid of using pipes since the execution
  of the parent is suspended until the child returns
- using CLONE_VM will not cause virtual memory to be copied
- using CLONE_FILES will not cause the file descriptor table to be copied

Note that the intermediate clone() is used with CLONE_VM. Some glibc versions
used to reset the pid/tid to -1 when CLONE_VM was used without CLONE_THREAD.
But since the memory between parent and child is shared on CLONE_VM this would
invalidate the getpid() cache that glibc used to maintain and so getpid() in
the child would return the parent's pid. This is all fixed in newer glibc
versions where the getpid() cache is removed and the pid/tid is not reset
anymore. However, if for whatever reason you - dear commiter - somehow need to
get the pid of the dummy intermediate process for do_share_ns() you need to
call syscall(__NR_getpid) directly. The next lxc_clone() call does not employ
CLONE_VM and will be fine.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 19:15:25 +01:00
Christian Brauner
bc9724f76c
coverity: #1425879
do not double close file descriptor

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 12:02:37 +01:00
Christian Brauner
3151d4e2d8
coverity: #1425883
ensure \0-termination

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 12:02:37 +01:00
Christian Brauner
8810408c6b
coverity: #1425884
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 12:02:36 +01:00
Christian Brauner
7fd3d41810
coverity: #1428855
remove logically dead code

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 12:02:36 +01:00
Christian Brauner
edeb1836ba
coverity: #1425886
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 12:02:36 +01:00
Christian Brauner
29f133bc33
coverity: #1425893
used calculated string length when copying into buffer

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 12:02:36 +01:00
Christian Brauner
b44c0a6787
coverity: #1426029
fix use after free

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 12:02:34 +01:00
Christian Brauner
e409b21402
conf: lxc.sysctl coding style fixes
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 11:27:24 +01:00
Christian Brauner
ed20740bca
Merge pull request #2009 from lifeng68/add_sysctl
confile: add lxc.sysctl config
2017-12-11 11:21:07 +01:00
LiFeng
7edd05402c confile: Add lxc.sysctl config
Signed-off-by: LiFeng <lifeng68@huawei.com>
2017-12-11 09:24:11 -05:00
Stéphane Graber
9f3b360c2b
Merge pull request #2019 from brauner/2017-12-11/fix_legacy_network_parser
legacy confile: fix legacy network parser
2017-12-11 00:40:27 -05:00
Christian Brauner
b668653c52
conf: fix lxc.prlimit clearing
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 06:22:56 +01:00
Christian Brauner
4bc717d6e3
legacy confile: fix legacy network parser
This fixes a bug introduced by:

commit 94f0035bf6
Author: Christian Brauner <christian.brauner@ubuntu.com>
Date:   Thu Dec 7 15:07:26 2017 +0100

    coverity: #1425924

    remove logically dead condition

    Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>

Coverity's bug analysis is correct but my fix wasn't.

This commit fixes a bunch of other bugs I just spotted as well.

This unblocks #2009.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-11 06:03:45 +01:00
Stéphane Graber
b826fe7df3
travis: Fix build failure
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2017-12-09 01:51:14 -05:00
Serge Hallyn
8a82c80b7d
Merge pull request #2016 from flx42/lxc-oci-misc-improvements
lxc-oci misc improvements
2017-12-08 22:56:14 -06:00
Felix Abecassis
a787c33229 lxc-oci: add support for WorkingDir
Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
2017-12-08 20:38:43 -08:00
Serge Hallyn
6d75f4cb0b
Merge pull request #2012 from marcosps/pthread_mtx_msg
lxc: Distinguish pthread_mutex_unlock error messages
2017-12-08 22:10:50 -06:00
Serge Hallyn
be459e9997
Merge pull request #1950 from brauner/2017-11-27/criu_fixes
bugfixes
2017-12-08 21:59:09 -06:00
Felix Abecassis
8f54d926c5 lxc-oci: add IPv6 support to /etc/hosts
Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
2017-12-08 19:36:49 -08:00
Felix Abecassis
e86dcc912f lxc-oci: add basic handling of numerical uid/gid
Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
2017-12-08 19:36:40 -08:00
Tycho Andersen
4be4832738 add --share-$NS= support to lxc-execute
Signed-off-by: Tycho Andersen <tycho@tycho.ws>
2017-12-08 21:37:12 +00:00
Marcos Paulo de Souza
81a14ca944 lxc: Distinguish pthread_mutex_unlock error messages
The same message exists in lxclock.c and cgmanager.c, so print the
filename along with the message.

Before this patch:
lxc-destroy -n u1
pthread_mutex_unlock returned:1 Operation not permitted

After this patch:
xc-destroy -n u1
lxclock.c: pthread_mutex_unlock returned:1 Operation not permitted

Signed-off-by: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
2017-12-08 00:02:18 -02:00
Serge Hallyn
f6812e7f2e
Merge pull request #2011 from brauner/generic/coverity
coverity: bugfixes
2017-12-07 14:46:09 -06:00
Christian Brauner
2d7bf7442c
coverity: #1425888
check return value of getifaddrs()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-07 15:24:28 +01:00
Christian Brauner
2a7de7ea85
coverity: #1425889
do not call close on bad file descriptor

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-07 15:21:57 +01:00
Christian Brauner
fd41e9b7bf
coverity: #1425890
silence complaint about unchecked return value from library function

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-07 15:18:35 +01:00
Christian Brauner
dcbc861eda
coverity: #1425895
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-07 15:17:11 +01:00
Christian Brauner
f4e1fa60b2
coverity: #1425921
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-07 15:14:37 +01:00
Christian Brauner
8e0c662051
coverity: #1425922
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-07 15:11:16 +01:00
Christian Brauner
9d6514f222
coverity: #1425923
avoid NULL-pointer dereference

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-07 15:09:46 +01:00
Christian Brauner
94f0035bf6
coverity: #1425924
remove logically dead condition

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-07 15:07:26 +01:00
Christian Brauner
3ee9e4fb38
coverity: #1425928
Avoid NULL-pointer dereference. Apparently monitor.{c,h} calls
lxc_check_inherited() with NULL passed for the config. This isn't really a big
issue since monitor.{c,h} is effectively dead for all liblxc versions that have
the state client patch. Also, the patch that introduces the relevant lines into
lxc_check_inherited() is only in master and yet unreleased.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-07 15:01:51 +01:00
Christian Brauner
e1e7642342
coverity: #1425929
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-07 14:59:55 +01:00
Stéphane Graber
fb398f0786
Merge pull request #2007 from brauner/2017-12-06/bugfixes
coverity: bugfixes
2017-12-06 17:32:22 -05:00
Serge Hallyn
49be8a144a
Merge pull request #1934 from brauner/2017-11-21/implement_do_lxc_reboot_correctly
commands: improve and simplify locking + lxccontainer: add reboot2() API extension
2017-12-06 16:31:50 -06:00
Christian Brauner
070a05af28
coverity: #1425743
remove logically dead code

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-06 23:13:20 +01:00
Christian Brauner
adcdf4e4a7
coverity: #1425742
fix error condition check

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-06 23:13:20 +01:00
Christian Brauner
3a29fb5546
coverity: #1425740
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-06 23:13:20 +01:00
Christian Brauner
cf22313188
coverity: #1425739
check snprintf() return value

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-06 23:13:20 +01:00
Christian Brauner
5384511cea
coverity: #1425737
free allocated memory

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-06 23:13:20 +01:00
Christian Brauner
97ebced3e5
coverity: #1425735
use correct inequality comparison

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-06 23:13:15 +01:00
Christian Brauner
6b9be52337
coverity: #1425734
free memory on error

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-06 22:32:51 +01:00
Christian Brauner
77f76f316a
tests: expand tests for shortlived init processes
This adds additional test for app containers.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-06 21:47:15 +01:00
Christian Brauner
6dcd0821c8
Merge pull request #2006 from Ricardo-Yoshi-LXC/master
Move lxc_init up to lxc/src and add argument parser
2017-12-06 18:43:09 +01:00
RicardoSanchezA
d51dde8ae7 lxc_init: changed minor details
Signed-off-by: RicardoSanchezA <ricardo.sanchez@utexas.edu>
2017-12-06 11:01:04 -06:00
RicardoSanchezA
5ee606bc8e lxc_init: add custom argument parser
lxc_init.c should not depend on tools/arguments.{c,h}, thus it needs its own custom argument parser

Signed-off-by: RicardoSanchezA <ricardo.sanchez@utexas.edu>
2017-12-06 09:30:44 -06:00
RicardoSanchezA
a729880178 lxc_init: move up to src/lxc
lxc_init.c is actually not a tool, thus it doesn't belong to the tools/ subfolder

Signed-off-by: RicardoSanchezA <ricardo.sanchez@utexas.edu>
2017-12-06 09:28:19 -06:00
Christian Brauner
fa30091bb5
lxccontainer: handle execute containers correctly
It doesn't make sense to error out when an app container doesn't pass explicit
arguments through c->start{l}(). This is especially true since we implemented
lxc.execute.cmd. However, even before we could have always relied on
lxc.init.cmd and errored out after that.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-06 16:01:24 +01:00
Christian Brauner
8f98ac7b0f
execute: pass logfile to lxc-init
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-06 16:01:23 +01:00