Commit Graph

1578 Commits

Author SHA1 Message Date
Serge Hallyn
cf0f903326
detect APT_PROXY from host apt.conf
Introduce a new HTTP_PROXY variable in /etc/default/lxc.  If unset or
set to none, then behavior continues as before.  If set to 'apt', then
any http::proxy set in apt.conf will be used as http_proxy for
debootstrap, and specified in the container's
/etc/apt/apt.conf.d/70proxy.  If set to something else, then the
value of HTTP_PROXY will be used as http_proxy for debootstrap and
specified in the container's 70proxy.

Changelog: (apr 23) merge the two apt proxy detection functions.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-04-24 00:57:18 +02:00
Dwight Engen
051151de89
goto correct cleanup label to ensure fd is closed
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-23 13:49:06 +02:00
Serge Hallyn
bbb8a488ae remove needless check for 'line' which cannot be NULl there
(found by coverity)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-22 15:46:26 -05:00
Serge Hallyn
7e1667d76e cgpath test: don't check path len before checking if it is null
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-22 15:40:57 -05:00
Dwight Engen
ddb17f1f08
make lxc_af_unix_open() safely return error on long pathnames
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-22 17:48:02 +02:00
Stéphane Graber
599d425251
python: Fix get_ips and nesting with lxcpath
When using -P (lxcpath), the parameter path needs to be forwarded
to the various commands being run but not used by the nested lxc-ls
as it's relatively unlikely that both the host and the nested containers
use a custom path.

This isn't ideal but short of having a way to provide the container path
for every single of the nesting (with potential unlimited depth), it's
the best we can do.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-22 09:00:43 +02:00
Stéphane Graber
a2abaa9ec6
ubuntu: Various fixes
- Drop disabled entries from allowed devices list
 - Improve generated config layout a bit
 - Drop redundant uname call
 - Re-generate the SSH host keys on container creation

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-22 08:59:53 +02:00
Christian Bühler
ed4616b1cf Use "uname -m" instead of "arch"
According to "arch"'s manpage, it's identical to "uname -m".

Some distros ship uname but don't ship arch, however all distros ship uname,
therefore it makes sense to use "uname -m" whenever possible.

Signed-off-by: Christian Bühler <christian@cbuehler.de>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-04-21 20:23:40 +02:00
Stéphane Graber
6c5db2af1f python: Various fixes to the python scripts
This fixes a few issues uncovered by the recent C module fix.

In lxc-start-ephemeral, the hwaddr code wasn't actually working.
Replace by code that properly iterates through the network interfaces
and sets a new MAC address for each entry.

In the python overlay, catch the newly emitted KeyError when in
set_config_item (or setting any previously unset variable would fail).

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-18 22:37:10 +02:00
Stéphane Graber
2ebec36f27 python: Lots of fixes in C extension
Fixes a lot of issues found by a code review done by Barry Warsaw.

Those include:
 - Wrong signature for getters
 - Various memory leaks
 - Various optimizations
 - More consistent return values
 - Proper exception handling

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Reported-by: Barry Warsaw <barry@ubuntu.com>
Acked-by: Barry Warsaw <barry@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-18 21:52:54 +02:00
Richard Weinberger
860fc865b0 utils: reimplement/fix mkdir_p() (v2)
Reimplement mkdir_p() such that it:
 ...handles relativ paths correctly. (currently it crashes)
 ...does not rely on dirname().
 ...is not recursive.
 ...is shorter. ;-)

Signed-off-by: Richard Weinberger <richard@nod.at>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-18 10:57:19 +02:00
Stéphane Graber
23154d5764 Revert "start: Detect early failure of the new child"
This reverts commit 5a5c35c3a0.

This commit was preventing startup of containers using lxc hooks and
shutdown of all other containers, requiring the use of a good old
kill -9 to get rid of lxc-start after a container shutdown.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2013-04-18 10:30:33 +02:00
Stéphane Graber
3763ee8591 Revert "utils: reimplement/fix mkdir_p()"
This reverts commit 8de4140644.

This commit was preventing container startup on my machine, making them
all fail with various "No such file or directory" errors.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2013-04-18 10:29:44 +02:00
Richard Weinberger
8de4140644 utils: reimplement/fix mkdir_p()
Reimplement mkdir_p() such that it:
 ...handles relativ paths correctly. (currently it crashes)
 ...does not rely on dirname().
 ...is not recursive.
 ...is shorter. ;-)

Signed-off-by: Richard Weinberger <richard@nod.at>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-18 09:36:24 +02:00
Richard Weinberger
5a5c35c3a0 start: Detect early failure of the new child
If the process in the new namespace dies very early
we have currently no chance to detect this.
The parent process will just die due to SIGPIPE
if it write to the fd used for synchronisation and
nobody will notice the real cause of the problem.

Install a SIGCHLD handler to detect the death.
Later when the child does execve() to the init within
the new namespace the handler will be disabled automatically.

Signed-off-by: Richard Weinberger <richard@nod.at>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-17 18:20:37 +02:00
Richard Weinberger
6b28a08631 init: Fix whitespace damage
While we are here, fix the whitespace damage.

Signed-off-by: Richard Weinberger <richard@nod.at>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-17 18:20:34 +02:00
Richard Weinberger
a81bad13ec init: unnest interrupt_handler
There is no need to use nested functions voodoo.

Signed-off-by: Richard Weinberger <richard@nod.at>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-17 18:20:31 +02:00
Dwight Engen
2c7d90ac6e quiet gcc 4.4.7 warning about saveptr use before initialization
The recent change to use strtok_r causes a build warning with this older
gcc version, so initialize saveptr to NULL to quiet the compiler and
unbreak the build. There was no warning with gcc 4.7.2 that I
originally tested with.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-04-16 18:16:11 +02:00
Serge Hallyn
98663823e4 fix spacing
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-16 07:41:17 -05:00
Serge Hallyn
883f4a1eae mkdir_p: account for '//foo/bar'
As Richard reported, dirname('//') returns //.  But mkdir_p only stops
when called with '/', resulting in infinite recursion when given a
pathname '//foo/bar'.

Reported-by: richard -rw- weinberger <richard.weinberger@gmail.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-16 07:40:57 -05:00
Bogdan Purcareata
ce4c4ca435 lxc-template: enable chroot + chpasswd functionality for Busybox hosts
This patch supports the scenario where a user wants to install a
busybox container on a busybox host.

When running the template, in order to change the root password,
the template needs to do the chroot. On busybox-powered hosts, chroot
is not part of the coreutils package - it's part of busybox. And the
busybox implementation or chroot only works if it has /lib in the new
root populated with the right binaries (or at least that's the
solution I found to make it work).

The temporarily bind-mounts /lib in the NEWROOT, chroots there,
changes the password, goes back and unmounts. This set of operations
is contained in a new MOUNT namespace, using the lxc-unshare call.

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-16 12:21:25 +02:00
Dwight Engen
8e7da691af fix checking hook script exit code
pclose returns the exit status from wait, we need to check that to see if
the script itself failed or not. Tested a script that returned 0, 1, and
also one that did a sleep and then was killed by a signal.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-16 12:16:53 +02:00
Dwight Engen
2796cf790f fortify: use reentrant safe strtok_r
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-16 12:16:41 +02:00
Dwight Engen
e6a19d2683 fortify: minor cleanups for unused variables, stricter types
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-16 12:15:56 +02:00
Dwight Engen
0a2188544a fortify: check the value returned from write(2)
Also check that we wrote the amount we expected to. The write on the pty
is blocking but we could still get a short write on EINTR, so we should
SYSERROR it.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-16 12:15:29 +02:00
Dwight Engen
03027ad99f fix lxc-attach usage
This makes it match the manpage and be consistent with lxc-execute

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-16 12:12:23 +02:00
Serge Hallyn
4d44e274dc fix coverity-found errors.
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-14 22:57:46 -05:00
Serge Hallyn
00b6be440f coverity resource leak fixes
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-14 22:44:09 -05:00
Serge Hallyn
5371906219 fix coverity-found resource leaks on error paths.
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-14 22:22:10 -05:00
Serge Hallyn
2802732032 fix coverity-found resource leaks in config_network_ipv6
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-14 22:16:26 -05:00
Serge Hallyn
bb1d227404 fix free of alloca()d buffer (found by coverity)
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-14 22:02:03 -05:00
Serge Hallyn
022de5f317 fix resource leak of netdev on error path found by coverity
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-14 21:59:20 -05:00
Serge Hallyn
b6f24d54f5 fix resource leak of utsname in error path found by coverity
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-14 21:56:51 -05:00
Serge Hallyn
a6537fbbfb genl.c: fix a resource leak found by coverity
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-14 21:48:49 -05:00
Serge Hallyn
a741a85d8e lxcapi_create: fix leak of tpath when a container already exists
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-14 21:45:00 -05:00
Serge Hallyn
b4e4ca49c7 lxc_monitor: make sure msg.name is null terminated (bug found by coverity)
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-14 21:39:34 -05:00
Serge Hallyn
c928f41fc0 ifdef out skipped startone test code
Unfortunately installing a working lxc-init is somewhat hairy and
distro-dependent.  So we skipped it before, but Coverity didn't
like that, so just ifdef it out.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-14 21:18:53 -05:00
Serge Hallyn
4167078838 lxccontaienr: fix missing va_end in error case.
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-14 21:17:09 -05:00
Serge Hallyn
586d4e9be1 lxcccontainer: add missing va_end found by coverity
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-14 21:12:58 -05:00
Serge Hallyn
af41709c42 af_unix.c: fix coverity-found bug: pass addr size
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-12 15:15:22 -05:00
Serge Hallyn
bdb539b89b lxclock: fix coverity-found leak
if sem_init fails, free what we mallocd.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-12 15:11:29 -05:00
Serge Hallyn
8767795058 lxclock: indentation
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-12 15:11:11 -05:00
Serge Hallyn
43d1aa34aa Fix up struct lxc_container locking
1. in container_free, set c->privlock to NULL before calling
sem_destroy, to prevent a window where another thread could call
sem_wait(c->privlock) while c->privlock is not NULL but is already
destroyed.

2. in container_get, check for numthreads < 0 before calling lxclock.
Once numthreads is 0, it never goes back up.

Following is a comment added to lxccontainer.c:

/*
 * Consider the following case:
freer                         |    racing get()er
==================================================================
lxc_container_put()           |   lxc_container_get()
\ lxclock(c->privlock)        |   c->numthreads < 1? (no)
\ c->numthreads = 0           |   \ lxclock(c->privlock) -> waits
\ lxcunlock()                 |   \
\ lxc_container_free()        |   \ lxclock() returns
                              |   \ c->numthreads < 1 -> return 0
\ \ (free stuff)              |
\ \ sem_destroy(privlock)     |

 * When the get()er checks numthreads the first time, one of the following
 * is true:
 * 1. freer has set numthreads = 0.  get() returns 0
 * 2. freer is between lxclock and setting numthreads to 0.  get()er will
 *    sem_wait on privlock, get lxclock after freer() drops it, then see
 *    numthreads is 0 and exit without touching lxclock again..
 * 3. freer has not yet locked privlock.  If get()er runs first, then put()er
 *    will see --numthreads = 1 and not call lxc_container_free().
*/

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Seth Arnold <seth.arnold@canonical.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-04-11 19:15:42 +02:00
Stéphane Graber
e649c8032f python: Fix memory management
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2013-04-11 14:29:39 +02:00
Dwight Engen
75129865d4 ubuntu template: fix installation when LANG=C
The ubuntu template will silently fail (because it is set -e) on
the locale-gen command when LANG=C

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-10 23:11:05 +02:00
Dwight Engen
9eee2f7739 oracle template: install additional user specified pkgs
Fix lxc-create to not word split template arguments. This makes
lxc-create -n ol -t oracle -- -r "at cronie wget" work since the argument
to -r will be passed as one arg instead of three.

Fix oracle template -u option to shift the correct amount.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-10 23:11:02 +02:00
Wojciech Izykowski
33892746e3 lxc-start-ephemeral: fixed bug with wrong ssh option (-k instead of -i)
Corrected ssh option for custom key (from -k to -i). Just see ssh
manpage for justification.

Signed-off-by: Wojciech Izykowski <wizykowski@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-10 23:09:37 +02:00
Dwight Engen
6efdcb6a3c debian template: set arch when dpkg doesn't exist on host
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-04-10 23:05:47 +02:00
Dwight Engen
fe19f236a2 fix wait status in pid reuse case
Commit 37c3dfc9 sets the wait status on only the child pid. It
intended to match the pid only once to protect against pid reuse but it
won't because the indicator was reset to 0 every time at the top of the
loop. If the child pid is reused, the wait status will be set again.
Fix by setting indicator outside the loop.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-10 15:24:58 -05:00
Dwight Engen
1354f95287 minor documentation fixes / clarification
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-04-10 15:24:56 -05:00