]> git.ipfire.org Git - thirdparty/lxc.git/log
thirdparty/lxc.git
8 years agoconfile: clear vlan id 1707/head
Christian Brauner [Mon, 17 Jul 2017 11:34:20 +0000 (13:34 +0200)] 
confile: clear vlan id

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconfile: clear macvlan mode
Christian Brauner [Mon, 17 Jul 2017 11:33:03 +0000 (13:33 +0200)] 
confile: clear macvlan mode

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconfile: clear network flags
Christian Brauner [Mon, 17 Jul 2017 11:30:41 +0000 (13:30 +0200)] 
confile: clear network flags

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconfile: clear ipv{4,6} gateway
Christian Brauner [Mon, 17 Jul 2017 11:21:15 +0000 (13:21 +0200)] 
confile: clear ipv{4,6} gateway

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agocgfsng: only output debug info when we set cgroup data
Long Wang [Mon, 10 Jul 2017 03:38:33 +0000 (11:38 +0800)] 
cgfsng: only output debug info when we set cgroup data

Only output debug info `cgroup 'xxxx' set to 'yyyy'` when we set
cgroup data.

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agoutils: set_stdfds()
Christian Brauner [Mon, 10 Jul 2017 09:46:54 +0000 (11:46 +0200)] 
utils: set_stdfds()

non-functional changes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agostart: dup std{in,out,err} to pty slave
Li Feng [Mon, 10 Jul 2017 09:19:52 +0000 (17:19 +0800)] 
start: dup std{in,out,err} to pty slave

In the case the container has a console with a valid slave pty file descriptor
we duplicate std{in,out,err} to the slave file descriptor so console logging
works correctly. When the container does not have a valid slave pty file
descriptor for its console and is started daemonized we should dup to
/dev/null.

Closes #1646.

Signed-off-by: Li Feng <lifeng68@huawei.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoutils: use access instead of stat
Long Wang [Sun, 9 Jul 2017 00:34:27 +0000 (08:34 +0800)] 
utils: use access instead of stat

we shoud test whether the file exists and grants
execute permissions.

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agocommonds: fix typo
Long Wang [Sun, 9 Jul 2017 00:10:34 +0000 (08:10 +0800)] 
commonds: fix typo

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agocommands: delete meaningless comments
Long Wang [Sun, 9 Jul 2017 00:08:54 +0000 (08:08 +0800)] 
commands: delete meaningless comments

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agocommands: handle EINTR
Christian Brauner [Tue, 4 Jul 2017 17:16:08 +0000 (19:16 +0200)] 
commands: handle EINTR

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agocommands: abstract cmd socket handling + logging
Christian Brauner [Mon, 3 Jul 2017 21:43:56 +0000 (23:43 +0200)] 
commands: abstract cmd socket handling + logging

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agocommands: add missing translation
Christian Brauner [Mon, 3 Jul 2017 21:37:31 +0000 (23:37 +0200)] 
commands: add missing translation

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agocommands: mv lxc_make_abstract_socket_name()
Christian Brauner [Mon, 3 Jul 2017 21:31:04 +0000 (23:31 +0200)] 
commands: mv lxc_make_abstract_socket_name()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agocommands: make state server interface flexible
Christian Brauner [Sun, 2 Jul 2017 13:42:07 +0000 (15:42 +0200)] 
commands: make state server interface flexible

This adds a little more flexibility to the state server. The idea is to have a
command socket function "lxc_cmd_add_state_client()" whose only task is to add
a new state client to the container's in-memory handler. This function returns
either the state of the container if it is already in the requested state or it
will return the newly registered client's fd in one of its arguments to the
caller. We then provide a separate helper function "lxc_cmd_sock_rcv_state()"
which can be passed the returned client fd and listens on the fd for the
requested state.
This is useful when we want to first register a client, then send a signal to
the container and wait for a state. This ensure that the client fd is
registered before the signal can have any effect and can e.g. be used to catch
something like the "STOPPING" state that is very ephemeral.

Additionally we provide a convenience function "lxc_cmd_sock_get_state()" which
combines both tasks and is used in e.g. "lxc_wait()".

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agocommands: rename to lxc_cmd_add_state_client()
Christian Brauner [Sun, 2 Jul 2017 12:47:02 +0000 (14:47 +0200)] 
commands: rename to lxc_cmd_add_state_client()

The new wait commands API is not yet stable so this change is ok.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agolxc static init: report exec*() failure
Christian Brauner [Fri, 30 Jun 2017 13:30:18 +0000 (15:30 +0200)] 
lxc static init: report exec*() failure

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agotest: shortlived daemonized containers
Christian Brauner [Thu, 29 Jun 2017 13:01:11 +0000 (15:01 +0200)] 
test: shortlived daemonized containers

Add a test to see if we can start daemonized containers that have a very
short-lived init process. The point of this is to see whether we can correctly
retrieve the state.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agolxccontainer: non-functional changes
Christian Brauner [Thu, 29 Jun 2017 18:53:07 +0000 (20:53 +0200)] 
lxccontainer: non-functional changes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agolxccontainer: make sure memory is free()ed
Christian Brauner [Thu, 29 Jun 2017 18:49:56 +0000 (20:49 +0200)] 
lxccontainer: make sure memory is free()ed

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agostart: use separate socket on daemonized start
Christian Brauner [Thu, 29 Jun 2017 10:16:00 +0000 (12:16 +0200)] 
start: use separate socket on daemonized start

Since we killed lxc-monitord we rely on the container's command socket to wait
for the container. This doesn't work nicely on daemonized startup since a
container's init process might be something that is so short-lived that we
won't even be able to add a state client before the mainloop closes. But the
container might still have been RUNNING and executed the init binary correctly.
In this case we would erroneously report that the container failed to start
when it actually started just fine.
This commit ensures that we really all cases where the container successfully
ran by switching to a short-lived per-container anonymous unix socket pair that
uses credentials to pass container states around. It is immediately closed once
the container has started successfully.
This should also make daemonized container start way more robust since we don't
rely on the command socket handler to be running.

For the experienced developer: Yes, I did think about utilizing the command
socket directly for this. The problem is that when the mainloop starts it may
end up end accept()ing the connection that we want
do_wait_on_daemonized_start() to accept() so this won't work and might cause us
to hang indefinitely. The same problem arises when the container fails to start
before the mainloop is created. In this case we would hang indefinitely as
well.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agostart: generalize lxc_check_inherited()
Christian Brauner [Wed, 28 Jun 2017 11:30:05 +0000 (13:30 +0200)] 
start: generalize lxc_check_inherited()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoutils: lxc_make_abstract_socket_name()
Christian Brauner [Wed, 28 Jun 2017 22:50:19 +0000 (00:50 +0200)] 
utils: lxc_make_abstract_socket_name()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoutils: close parent end in child process after fork
Long Wang [Sat, 8 Jul 2017 05:27:16 +0000 (13:27 +0800)] 
utils: close parent end in child process after fork

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agolxc_abstract_unix_connect: remove the workaround-code
Long Wang [Sat, 8 Jul 2017 02:48:15 +0000 (10:48 +0800)] 
lxc_abstract_unix_connect: remove the workaround-code

commit bdb3f44147bc1a55a97131b4b39d42844ae4fb9e says that we may undo
the change in august 2014.

I think that it is time to do that.

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agostate: remove lxc_rmstate declaration
Long Wang [Sat, 8 Jul 2017 02:40:41 +0000 (10:40 +0800)] 
state: remove lxc_rmstate declaration

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agoaf_unix: remove unlink operation
Long Wang [Sat, 8 Jul 2017 02:29:57 +0000 (10:29 +0800)] 
af_unix: remove unlink operation

It is not necessary to unlink the abstract socket pathname when
we have finished using the socket. The abstract name is automatically
removed when the socket is closed.

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agoAllow containers to start in AppArmor namespaces
Frédéric Dalleau [Fri, 7 Jul 2017 09:26:45 +0000 (11:26 +0200)] 
Allow containers to start in AppArmor namespaces

This patch allows users to start containers in AppArmor namespaces.
Users can define their own profiles for their containers, but
lxc-start must be allowed to change to a namespace.

A container configuration file can wrap a container in an AppArmor
profile using lxc.aa_profile.

A process in an AppArmor namespace is restricted to view
or manage only the profiles belonging to this namespace, as if no
other profiles existed. A namespace can be created as follow:
sudo mkdir /sys/kernel/security/apparmor/policy/namespaces/$NAMESPACE

AppArmor can stack profiles so that the contained process is bound
by the intersection of all profiles of the stack. This is achieved
using the '//&' operator as follow:

lxc.aa_profile = $PROFILE//&:$NAMESPACE://unconfined

In this case, even the guest process appears unconfined in the
namespace, it is still confined by $PROFILE.

A guest allowed to access "/sys/kernel/security/apparmor/** rwklix,"
will be able to manage its own profile set, while still being
enclosed in the topmost profile $PROFILE:

Different guests can be assigned the same namespace or different
namespaces. In the first case, they will share their profiles.
In the second case, they will have distinct sets of profiles.

This is validated on privileged containers.

Signed-off-by: Frédéric Dalleau <frederic.dalleau@collabora.com>
8 years agouse same ifndef/define format for all headers
Long Wang [Wed, 5 Jul 2017 04:20:28 +0000 (12:20 +0800)] 
use same ifndef/define format for all headers

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agocaps.h: move ifndef/define to the top
Long Wang [Wed, 5 Jul 2017 04:19:37 +0000 (12:19 +0800)] 
caps.h: move ifndef/define to the top

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agolxc-init: move initialization of act to outside of the loop
Long Wang [Wed, 5 Jul 2017 04:01:16 +0000 (12:01 +0800)] 
lxc-init: move initialization of act to outside of the loop

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agolxc-init: adjust include statements
Long Wang [Wed, 5 Jul 2017 03:54:25 +0000 (11:54 +0800)] 
lxc-init: adjust include statements

* Use `#include <lxc/lxccontaienr.h>` style for exported haeders.
* remove used header `caps.h`

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agolxc-init: non-functional changes
Long Wang [Wed, 5 Jul 2017 02:57:14 +0000 (10:57 +0800)] 
lxc-init: non-functional changes

This patch mainly update the message format to:

* upper the first letter
* end without a dot

all changes are relate to `lxc-init`

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agolxc-init: add comment for exclude 32 and 33 signals
Long Wang [Wed, 5 Jul 2017 02:53:02 +0000 (10:53 +0800)] 
lxc-init: add comment for exclude 32 and 33 signals

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agolxc-execute: print error message when failed
Long Wang [Tue, 4 Jul 2017 08:16:30 +0000 (16:16 +0800)] 
lxc-execute: print error message when failed

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agoREADME: update
Christian Brauner [Mon, 3 Jul 2017 22:15:05 +0000 (00:15 +0200)] 
README: update

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoREADME: add CII Best Practices badge to README
Christian Brauner [Mon, 3 Jul 2017 18:39:59 +0000 (20:39 +0200)] 
README: add CII Best Practices badge to README

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agolxclock: non-functional changes
Long Wang [Mon, 3 Jul 2017 07:43:34 +0000 (15:43 +0800)] 
lxclock: non-functional changes

This patch mainly updates comments based on the current code.

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agolxclock: return the right error when open lock file failed
Long Wang [Mon, 3 Jul 2017 07:41:25 +0000 (15:41 +0800)] 
lxclock: return the right error when open lock file failed

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agoremove the unused macro
0x0916 [Sun, 2 Jul 2017 11:45:41 +0000 (19:45 +0800)] 
remove the unused macro

Signed-off-by: Long Wang <w@laoqinren.net>
8 years agostart: send state to legacy lxc-monitord state server even if no state clients registered
0x0916 [Sat, 1 Jul 2017 05:44:41 +0000 (13:44 +0800)] 
start: send state to legacy lxc-monitord state server even if no state clients registered

This pr https://github.com/lxc/lxc/pull/1618 kill lxc-monitord, for backwards compatibility,
we also send state to legacy lxc-monitord state server in function `lxc_set_state`.

we should also send state if there is no state clients registered, otherwise `lxc-monitor` client will
not get state change event if container changed state to `STARTING` or `RUNNING`.

Signed-off-by: 0x0916 <w@laoqinren.net>
8 years agolxc-monitord: exit when got a quit command
0x0916 [Sat, 1 Jul 2017 06:04:14 +0000 (14:04 +0800)] 
lxc-monitord: exit when got a quit command

lxc-monitor has an option to tell lxc-monitord to quit.

```
~/lxc (master) # lxc-monitor --help
lxc-monitor monitors the state of the NAME container

Options :
  -n, --name=NAME   NAME of the container
                    NAME may be a regular expression
  -Q, --quit        tell lxc-monitord to quit
```
But it does not work. This patch fix that.

Signed-off-by: 0x0916 <w@laoqinren.net>
8 years agoremove the `__func__` macro
0x0916 [Mon, 26 Jun 2017 09:55:12 +0000 (17:55 +0800)] 
remove the `__func__` macro

Our logging function will always spew out the function name.

Signed-off-by: 0x0916 <w@laoqinren.net>
8 years agoAPI doc: update note for get_config_item
0x0916 [Mon, 26 Jun 2017 09:28:47 +0000 (17:28 +0800)] 
API doc: update note for get_config_item

Fix issue: https://github.com/lxc/lxc/issues/505

Signed-off-by: 0x0916 <w@laoqinren.net>
8 years agouse altarch mirror for CentOS on arches other than i386 and x86_64
Evgeni Golov [Sat, 24 Jun 2017 16:53:05 +0000 (18:53 +0200)] 
use altarch mirror for CentOS on arches other than i386 and x86_64

CentOS only has i386 and x86_64 listed in mirrorlist.centos.org,
use http://mirror.centos.org/altarch/ for all other arches instead

See: https://bugs.centos.org/view.php?id=11250

Signed-off-by: Evgeni Golov <evgeni@debian.org>
8 years agotemplates/debian: add aarch64 → arm64 mapping
Evgeni Golov [Sat, 24 Jun 2017 15:24:49 +0000 (17:24 +0200)] 
templates/debian: add aarch64 → arm64 mapping

uname -m reports aarch64, but Debian calls the arch arm64

Signed-off-by: Evgeni Golov <evgeni@debian.org>
8 years agoupdate .gitignore
0x0916 [Fri, 23 Jun 2017 15:17:29 +0000 (23:17 +0800)] 
update .gitignore

Signed-off-by: 0x0916 <w@laoqinren.net>
8 years agoUse strerror(errno) instead of %m
0x0916 [Fri, 23 Jun 2017 11:41:34 +0000 (19:41 +0800)] 
Use strerror(errno) instead of %m

Signed-off-by: 0x0916 <w@laoqinren.net>
8 years agofix memory and resource leak
0x0916 [Fri, 23 Jun 2017 12:36:56 +0000 (20:36 +0800)] 
fix memory and resource leak

Signed-off-by: 0x0916 <w@laoqinren.net>
8 years agoRevert "Add a prefix to the lxc.pc"
0x0916 [Fri, 23 Jun 2017 11:46:52 +0000 (19:46 +0800)] 
Revert "Add a prefix to the lxc.pc"

This reverts commit 758243d8af0406e63cc5446c65d415298fa3cef2.

Signed-off-by: 0x0916 <w@laoqinren.net>
8 years agoconfile: do not check for empty value twice
Christian Brauner [Wed, 21 Jun 2017 09:13:57 +0000 (11:13 +0200)] 
confile: do not check for empty value twice

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoFix memory leak of 'lxc_tty_state'
Li Feng [Wed, 21 Jun 2017 05:38:06 +0000 (13:38 +0800)] 
Fix memory leak of 'lxc_tty_state'

Signed-off-by: Li Feng <lifeng68@huawei.com>
8 years agodoc: Tweak Japanese lxc.container.conf(5)
KATOH Yasufumi [Tue, 20 Jun 2017 08:28:49 +0000 (17:28 +0900)] 
doc: Tweak Japanese lxc.container.conf(5)

Add description of new network configuration, and tweak.

Update for commit b9986e437ba334a3860472a3e01ed2fa221603ab

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
8 years agoutils: use 1LU otherwise we overflow
Christian Brauner [Tue, 20 Jun 2017 00:48:47 +0000 (02:48 +0200)] 
utils: use 1LU otherwise we overflow

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoutils: fix the way to detect blocking signal
Yifeng Tan [Mon, 19 Jun 2017 10:36:13 +0000 (18:36 +0800)] 
utils: fix the way to detect blocking signal

Signed-off-by: Yifeng Tan <tanyifeng1@huawei.com>
8 years agonetwork: add arg to config clear method
Christian Brauner [Thu, 15 Jun 2017 17:08:22 +0000 (19:08 +0200)] 
network: add arg to config clear method

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agonetwork: add lxc_log_configured_netdevs()
Christian Brauner [Wed, 14 Jun 2017 14:32:27 +0000 (16:32 +0200)] 
network: add lxc_log_configured_netdevs()

This logs the configured networks on the trace level to support debugging.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agonetwork: perform network validation at creation time
Christian Brauner [Wed, 14 Jun 2017 11:53:23 +0000 (13:53 +0200)] 
network: perform network validation at creation time

Some of the checks were previously performed when parsing the network config.
But since we allow for a little more flexibility now it doesn't work anymore.
Instead, let's validate the network at creation time.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agonetwork: implement lxc_get_netdev_by_idx()
Christian Brauner [Wed, 14 Jun 2017 11:42:27 +0000 (13:42 +0200)] 
network: implement lxc_get_netdev_by_idx()

lxc_get_netdev_by_idx() takes care of checking whether a given netdev struct
for a given index is already allocated. If so it returns a pointer to it to the
caller.
If it doesn't find it it will allocate a new netdev struct and insert it into
the network list at the right position. For example, let's say you have the
following networks defined in your config file:

lxc.network.0.type=veth
lxc.network.0.link=lxcbr0
lxc.network.0.name=eth0
lxc.network.0.flags=up

lxc.network.3.type=veth
lxc.network.3.link=lxcbr0
lxc.network.3.name=eth1
lxc.network.3.flags=up
lxc.network.3.hwaddr = 00:16:3e:5d:7d:65

lxc.network.1.type=veth
lxc.network.1.link=lxcbr0
lxc.network.1.name=eth0
lxc.network.1.flags=up

lxc_get_netdev_by_idx() will take care that the internal network list appears
in the order:

0
1
3

The ordering of the keys themselves can also be random, meaning you could do:

lxc.network.3.type=veth
lxc.network.0.link=lxcbr0
lxc.network.0.name=eth0
lxc.network.3.hwaddr = 00:16:3e:5d:7d:65
lxc.network.0.flags=up
lxc.network.3.flags=up
lxc.network.0.type=veth
lxc.network.3.link=lxcbr0
lxc.network.3.name=eth1

and lxc_get_netdev_by_idx() would still figure out the correct ordering since
it keeps track of the index.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agonetwork: add network counter
Christian Brauner [Tue, 13 Jun 2017 22:42:06 +0000 (00:42 +0200)] 
network: add network counter

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agonetwork: add data arg to set callback
Christian Brauner [Tue, 13 Jun 2017 22:39:35 +0000 (00:39 +0200)] 
network: add data arg to set callback

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agonetwork: mv config_value_empty() to confile_utils
Christian Brauner [Tue, 13 Jun 2017 11:48:04 +0000 (13:48 +0200)] 
network: mv config_value_empty() to confile_utils

and rename it to lxc_config_value_empty()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agotree-wide: priority -> level
Christian Brauner [Thu, 15 Jun 2017 10:13:04 +0000 (12:13 +0200)] 
tree-wide: priority -> level

When we merged the new logging function for the api we exposed the log level
argument in the struct as "priority" which we actually requested to be changed
to "level" which somehow didn't happen and we missed it. Given the fact there
has been no new liblxc release let's fix it right now before it hits users.
Also, take the chance to change the terminology in the log from "priority" to
"level" globally. This is to prevent confusion with syslog's "priority"
argument which we also support.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agotests: don't fail when no processes for user exist
Christian Brauner [Mon, 12 Jun 2017 14:06:17 +0000 (16:06 +0200)] 
tests: don't fail when no processes for user exist

Since we kicked lxc-monitord there will very likely be no user processes around
anymore after all container's have been stopped. Which is a very very very good
thing. So let's not error out when pkill doesn't find any processes.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconf: fix wrong path on overlayfs
Christian Brauner [Mon, 12 Jun 2017 09:18:05 +0000 (11:18 +0200)] 
conf: fix wrong path on overlayfs

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agolxccontainer: cleanup + bugfixes
Christian Brauner [Sun, 11 Jun 2017 04:33:06 +0000 (06:33 +0200)] 
lxccontainer: cleanup + bugfixes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years ago{start,lxccontainer}: add lxc_free_handler()
Christian Brauner [Sun, 11 Jun 2017 03:44:52 +0000 (05:44 +0200)] 
{start,lxccontainer}: add lxc_free_handler()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agocommands: add lxc_cmd_state_server()
Christian Brauner [Sat, 10 Jun 2017 23:29:45 +0000 (01:29 +0200)] 
commands: add lxc_cmd_state_server()

A LXC container's lifecycle is regulated by the states STARTING, RUNNING,
STOPPING, STOPPED, ABORTING. These states are tracked in the LXC handler and
can be checked via approriate functions in the command socket callback system.
(The freezer stages are not part of a container's lifecycle since they are not
recorded in the LXC handler. This might change in the future but given that the
freezer controller will be removed from future cgroup implementations it is
unlikely.) So far, LXC was using an external helper to track the states of a
container (lxc-monitord). This solution was error prone. For example, the
external state server would hang in various scenarios that seemed to be caused
by either very subtle internal races or irritation of the external state server
by signals.

LXC will switch from an external state monitor (lxc-monitord) which serves as a
state server for state clients to a native implementation using the indiviual
container's command socket. This solution was discussed and outlined by Stéphane
Graber and Christian Brauner during a LX{C,D} sprint.

The LXC handler will gain an additional field to track state clients. In order
for a state client to receive state notifications from the command server he
will need to register himself via the lxc_cmd_state_server() function in the
state client list. The state client list will be served by lxc_set_state()
during the container's lifecycle. lxc_set_state() will also take care of
removing any clients from the state list in the LXC handler once the requested
state has been reached and sent to the client.
In order to prevent races between adding and serving new state clients the state
client list and the state field in the LXC handler will be protected by a lock.

This commit effectively deprecates lxc-monitord. Instead of serving states to
state clients via the lxc-monitord fifo and socket we will now send the state
of the container via the container's command socket.
lxc-monitord is still useable and will - for the sake of the lxc-monitor
command - be kept around so that non-API state clients can still monitor the
container during it's lifecycle.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agocommands: add TRACE()ers
Christian Brauner [Fri, 9 Jun 2017 15:20:20 +0000 (17:20 +0200)] 
commands: add TRACE()ers

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agolxccontainer: only spawn monitord on demand
Christian Brauner [Thu, 8 Jun 2017 22:12:32 +0000 (00:12 +0200)] 
lxccontainer: only spawn monitord on demand

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agostart: add lxc_init_handler()
Christian Brauner [Wed, 7 Jun 2017 20:23:56 +0000 (22:23 +0200)] 
start: add lxc_init_handler()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agolxc-alpine: Add support for ppc64le
Breno Leitao [Mon, 12 Jun 2017 18:45:52 +0000 (13:45 -0500)] 
lxc-alpine: Add support for ppc64le

Starting at version 3.6, Alpine Linux has support for ppc64le
architecture. Adding the new keys also.

Signed-off-by: Breno Leitao <breno.leitao@gmail.com>
8 years agoSwitch to a new lxc_log_init function
0x0916 [Mon, 5 Jun 2017 06:31:03 +0000 (14:31 +0800)] 
Switch to a new lxc_log_init function

Signed-off-by: 0x0916 <w@laoqinren.net>
8 years agoseccomp: export the seccomp filter after load it into kernel successful
0x0916 [Sat, 20 May 2017 02:49:06 +0000 (10:49 +0800)] 
seccomp: export the seccomp filter after load it into kernel successful

when the log level is TRACE, this patch export the seccomp
filter to log file.

the ouput of `seccomp_export_pfc()` is human readable and this feature
is useful for user to make sure their `seccomp configuration file` is
right.

Output for he default ubuntu container's seccomp filter is the
following:

```
      lxc-start ubuntu 20170520024159.412 INFO     lxc_apparmor - lsm/apparmor.c:apparmor_process_label_set:238 - changed apparmor profile to lxc-container-default-cgns
if ($arch == 3221225534)
  # filter for syscall "finit_module" (313) [priority: 65535]
  if ($syscall == 313)
    action ERRNO(1);
  # filter for syscall "open_by_handle_at" (304) [priority: 65535]
  if ($syscall == 304)
    action ERRNO(1);
  # filter for syscall "kexec_load" (246) [priority: 65535]
  if ($syscall == 246)
    action ERRNO(1);
  # filter for syscall "delete_module" (176) [priority: 65535]
  if ($syscall == 176)
    action ERRNO(1);
  # filter for syscall "init_module" (175) [priority: 65535]
  if ($syscall == 175)
    action ERRNO(1);
  # filter for syscall "umount2" (166) [priority: 65533]
  if ($syscall == 166)
    if ($a1.hi32 & 0x00000000 == 0)
      if ($a1.lo32 & 0x00000001 == 1)
        action ERRNO(13);
  # default action
  action ALLOW;
if ($arch == 1073741827)
  # filter for syscall "finit_module" (350) [priority: 65535]
  if ($syscall == 350)
    action ERRNO(1);
  # filter for syscall "open_by_handle_at" (342) [priority: 65535]
  if ($syscall == 342)
    action ERRNO(1);
  # filter for syscall "kexec_load" (283) [priority: 65535]
  if ($syscall == 283)
    action ERRNO(1);
  # filter for syscall "delete_module" (129) [priority: 65535]
  if ($syscall == 129)
    action ERRNO(1);
  # filter for syscall "init_module" (128) [priority: 65535]
  if ($syscall == 128)
    action ERRNO(1);
  # filter for syscall "umount2" (52) [priority: 65534]
  if ($syscall == 52)
    if ($a1 & 0x00000001 == 1)
      action ERRNO(13);
  # default action
  action ALLOW;
if ($arch == 3221225534)
  # filter for syscall "kexec_load" (1073742352) [priority: 65535]
  if ($syscall == 1073742352)
    action ERRNO(1);
  # filter for syscall "finit_module" (1073742137) [priority: 65535]
  if ($syscall == 1073742137)
    action ERRNO(1);
  # filter for syscall "open_by_handle_at" (1073742128) [priority: 65535]
  if ($syscall == 1073742128)
    action ERRNO(1);
  # filter for syscall "delete_module" (1073742000) [priority: 65535]
  if ($syscall == 1073742000)
    action ERRNO(1);
  # filter for syscall "init_module" (1073741999) [priority: 65535]
  if ($syscall == 1073741999)
    action ERRNO(1);
  # filter for syscall "umount2" (1073741990) [priority: 65534]
  if ($syscall == 1073741990)
    if ($a1 & 0x00000001 == 1)
      action ERRNO(13);
  # default action
  action ALLOW;
action KILL;
      lxc-start ubuntu 20170520024159.412 NOTICE   lxc_start - start.c:start:1470 - Exec'ing "/sbin/init".
```

Signed-off-by: 0x0916 <w@laoqinren.net>
8 years agolxc-opensuse: add Tumbleweed as supported release
Christian Brauner [Sat, 27 May 2017 00:52:35 +0000 (02:52 +0200)] 
lxc-opensuse: add Tumbleweed as supported release

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconf: fix bionic builds
Christian Brauner [Mon, 5 Jun 2017 21:41:59 +0000 (23:41 +0200)] 
conf: fix bionic builds

bionic seems to lack a definition of __S_ISTYPE().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconf: improve lxc_map_ids()
Christian Brauner [Mon, 5 Jun 2017 21:37:25 +0000 (23:37 +0200)] 
conf: improve lxc_map_ids()

Closes https://github.com/lxc/lxd/issues/3384.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconf: improve tty shifting function
Christian Brauner [Sun, 4 Jun 2017 20:33:48 +0000 (22:33 +0200)] 
conf: improve tty shifting function

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agobdev: record output from mkfs.*
Christian Brauner [Sun, 4 Jun 2017 16:01:41 +0000 (18:01 +0200)] 
bdev: record output from mkfs.*

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agobdev: non-functional changes
Christian Brauner [Sun, 4 Jun 2017 14:45:12 +0000 (16:45 +0200)] 
bdev: non-functional changes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agodoc: tweak lxc.container.conf a little
Christian Brauner [Sun, 4 Jun 2017 13:22:20 +0000 (15:22 +0200)] 
doc: tweak lxc.container.conf a little

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agobdev: "detect" loop file
Christian Brauner [Sun, 4 Jun 2017 11:59:34 +0000 (13:59 +0200)] 
bdev: "detect" loop file

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconf: remove dead mount code
Christian Brauner [Sun, 4 Jun 2017 11:25:23 +0000 (13:25 +0200)] 
conf: remove dead mount code

The removed codepath was non-functional for a long time now. All mounting is
handled through bdev.{c,h} and if that fails the other codepath would
necessarily fail as well. So let's remove them. This makes it way clearer what
is going on and simplifies things massively.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoaf_unix: abstract lxc_abstract_unix_{send,recv}_fd
Christian Brauner [Sun, 4 Jun 2017 05:04:27 +0000 (07:04 +0200)] 
af_unix: abstract lxc_abstract_unix_{send,recv}_fd

- Enable lxc_abstract_unix_{send,recv}_fd() to send and receive multiple fds at
  once.
- lxc_abstract_unix_{send,recv}_fd() -> lxc_abstract_unix_{send,recv}_fds()
- Send tty fds from child to parent all at once.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agotree-wide: log function called in userns_exec_1()
Christian Brauner [Sat, 3 Jun 2017 21:35:07 +0000 (23:35 +0200)] 
tree-wide: log function called in userns_exec_1()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconf: avoid double-frees in userns_exec_1()
Christian Brauner [Sat, 3 Jun 2017 18:28:13 +0000 (20:28 +0200)] 
conf: avoid double-frees in userns_exec_1()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconf: non-functional changes
Christian Brauner [Sat, 3 Jun 2017 17:14:45 +0000 (19:14 +0200)] 
conf: non-functional changes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agostart: log sending and receiving of tty fds
Christian Brauner [Thu, 1 Jun 2017 03:40:59 +0000 (05:40 +0200)] 
start: log sending and receiving of tty fds

This is a potentially security sensitive operation and I really want to keep an
eye on *when exactly* this is send. So add more logging on the TRACE() level.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconf: rework userns_exec_1()
Christian Brauner [Fri, 2 Jun 2017 22:39:50 +0000 (00:39 +0200)] 
conf: rework userns_exec_1()

This also fixes a bug where we caused a double mapping, when the {u,g}id for
the user was mapped to container root {g,u}id.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconf: non-functional changes
Christian Brauner [Fri, 2 Jun 2017 22:39:28 +0000 (00:39 +0200)] 
conf: non-functional changes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agotests: add unit tests for idmap parser
Christian Brauner [Thu, 1 Jun 2017 21:43:34 +0000 (23:43 +0200)] 
tests: add unit tests for idmap parser

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconfile_utils: add new file
Christian Brauner [Thu, 1 Jun 2017 21:43:16 +0000 (23:43 +0200)] 
confile_utils: add new file

This adds confile_utils.{c,h} which will contain a helpers to parse lxc
configuration files.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoadd probe status checking
Shane Chen [Thu, 1 Jun 2017 16:14:01 +0000 (00:14 +0800)] 
add probe status checking

Signed-off-by: Shane Chen <ss1ha3tw@gmail.com>
8 years agotests: enforce all methods for config items
Christian Brauner [Fri, 2 Jun 2017 00:42:42 +0000 (02:42 +0200)] 
tests: enforce all methods for config items

This adds a test that checks LXC's configuration jump table whether all methods
for a given configuration item are implemented. If it is not, we'll error out.
This should provide additional safety since a) the API can now be sure that
dereferencing the pointer for a given method in the config struct is safe and
b) when users implement new configuration keys and forget to implement a
required method we'll see it right away.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconfile: add dummy getter for lxc.include
Christian Brauner [Fri, 2 Jun 2017 00:42:19 +0000 (02:42 +0200)] 
confile: add dummy getter for lxc.include

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconf: use minimal {g,u}id map
Christian Brauner [Mon, 29 May 2017 09:21:29 +0000 (11:21 +0200)] 
conf: use minimal {g,u}id map

Afaict, userns_exec_1() is only used to operate based on privileges for the
user's own {g,u}id on the host and for the container root's unmapped {g,u}id.
This means we require only to establish a mapping from:
- the container root {g,u}id as seen from the host -> user's host {g,u}id
- the container root -> some sub{g,u}id

The former we add, if the user did not specifiy a mapping. The latter we
retrieve from the ontainer's configured {g,u}id mappings.

Closes #1598.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoadding warning for mtu ignoring
Shane Chen [Thu, 1 Jun 2017 05:36:41 +0000 (13:36 +0800)] 
adding warning for mtu ignoring

Signed-off-by: Shane Chen <ss1ha3tw@gmail.com>
8 years agotests: comp retval to exp val whenever we can
Christian Brauner [Thu, 1 Jun 2017 02:10:00 +0000 (04:10 +0200)] 
tests: comp retval to exp val whenever we can

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoconfile: performance tweaks
Christian Brauner [Thu, 1 Jun 2017 02:09:43 +0000 (04:09 +0200)] 
confile: performance tweaks

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
8 years agoUse lxc-stop to stop systemd service
JD Friedrikson [Wed, 31 May 2017 16:41:41 +0000 (12:41 -0400)] 
Use lxc-stop to stop systemd service

Ever since 8eb62c2, systemd has not been able to cleanly stop lxc
containers (via lxc@) because it's still using SIGPWR for systemd-based
containers.

We should now use the nice logic in 330ae3d to stop the containers
instead.

Signed-off-by: JD Friedrikson <yours@decompo.site>