Commit Graph

6489 Commits

Author SHA1 Message Date
Christian Brauner
86a78f1733
commands: add missing translation
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-07-09 00:14:46 +02:00
Christian Brauner
bbf5cf35a3
commands: mv lxc_make_abstract_socket_name()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-07-09 00:14:46 +02:00
Christian Brauner
92e3501832
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>
2017-07-09 00:14:46 +02:00
Christian Brauner
54446942fe
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>
2017-07-08 23:50:19 +02:00
Christian Brauner
8130d8646d
lxc static init: report exec*() failure
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-07-08 23:50:19 +02:00
Christian Brauner
3df9fa8211
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>
2017-07-08 23:50:19 +02:00
Christian Brauner
7cb19d44a1
lxccontainer: non-functional changes
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-07-08 23:50:19 +02:00
Christian Brauner
a6b6ad7bbc
lxccontainer: make sure memory is free()ed
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-07-08 23:50:18 +02:00
Christian Brauner
5e5576a4ef
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>
2017-07-08 23:50:18 +02:00
Christian Brauner
47a46cf1d2
start: generalize lxc_check_inherited()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-07-08 23:50:18 +02:00
Christian Brauner
7935833c23
utils: lxc_make_abstract_socket_name()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-07-08 23:50:16 +02:00
Serge Hallyn
616e0593cd Merge pull request #1665 from brauner/2017-07-01/deprecate_lxc_rootfs_backend
prepare for LXC 2.1
2017-07-08 21:25:17 +00:00
Christian Brauner
4ea447b752 Merge pull request #1683 from 0x0916/2017-07-08/remove-unlink
af_unix: remove unlink operation
2017-07-08 16:56:34 +02:00
Christian Brauner
186f27db32 Merge pull request #1684 from 0x0916/2017-07-08/remove-dead-code
state: remove lxc_rmstate declaration
2017-07-08 08:16:50 +02:00
Christian Brauner
022f1ba31b Merge pull request #1685 from 0x0916/2017-07-08/remove-workaround-code
lxc_abstract_unix_connect: remove the workaround-code
2017-07-08 08:16:43 +02:00
Christian Brauner
4359b5a962 Merge pull request #1686 from 0x0916/2017-07-08/close-parent-end-after-fork
utils: close parent end in child process after fork
2017-07-08 08:16:35 +02:00
Long Wang
6e67032161
utils: close parent end in child process after fork
Signed-off-by: Long Wang <w@laoqinren.net>
2017-07-08 13:27:16 +08:00
Long Wang
b34cf53b7d
lxc_abstract_unix_connect: remove the workaround-code
commit bdb3f44147 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>
2017-07-08 10:52:17 +08:00
Long Wang
5b6235cd83
state: remove lxc_rmstate declaration
Signed-off-by: Long Wang <w@laoqinren.net>
2017-07-08 10:40:41 +08:00
Long Wang
42c6141c5a
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>
2017-07-08 10:29:57 +08:00
Stéphane Graber
996b20c4e2 Merge pull request #1682 from brauner/2017-07-07/enable_apparmor_namespaces
Allow containers to start in AppArmor namespaces
2017-07-07 17:43:19 -04:00
Frédéric Dalleau
d680929bbc 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>
2017-07-07 12:33:38 +02:00
Christian Brauner
6262244de9 Merge pull request #1675 from 0x0916/2017-07-05/lxc-init
lxc-init: some enhancements
2017-07-06 15:31:37 +02:00
Stéphane Graber
6da35cc1b2 Merge pull request #1673 from brauner/2017-07-04/update_readme
README: update
2017-07-05 12:27:28 -04:00
Christian Brauner
20069fa3ee Merge pull request #1677 from 0x0916/2017-07-05/fix-parse-config-file
tests: delete the intermediate file and directory.
2017-07-05 11:50:01 +02:00
Christian Brauner
d552fc35c9 Merge pull request #1676 from 0x0916/2017-07-05/fix-headers
fix headers
2017-07-05 11:32:14 +02:00
Long Wang
a6638e2e98 tests: remove temp lxcpath for attach testcase
Signed-off-by: Long Wang <w@laoqinren.net>
2017-07-05 15:39:02 +08:00
Long Wang
df24d43699 tests: remove the temp container directory
c->destory() will not remove the temp container directory.
This patch fix that.

Signed-off-by: Long Wang <w@laoqinren.net>
2017-07-05 15:17:58 +08:00
Long Wang
6cd5db20bc tests: create temp file before lxc_container_new
Signed-off-by: Long Wang <w@laoqinren.net>
2017-07-05 14:51:03 +08:00
Long Wang
3705503ac3 use same ifndef/define format for all headers
Signed-off-by: Long Wang <w@laoqinren.net>
2017-07-05 14:06:01 +08:00
Long Wang
74a99f40b3 caps.h: move ifndef/define to the top
Signed-off-by: Long Wang <w@laoqinren.net>
2017-07-05 12:19:37 +08:00
Long Wang
16affc24a5 lxc-init: move initialization of act to outside of the loop
Signed-off-by: Long Wang <w@laoqinren.net>
2017-07-05 12:13:09 +08:00
Long Wang
1574fc2495 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>
2017-07-05 12:12:38 +08:00
Long Wang
1bfb12006f 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>
2017-07-05 12:12:13 +08:00
Long Wang
55684fd822 lxc-init: add comment for exclude 32 and 33 signals
Signed-off-by: Long Wang <w@laoqinren.net>
2017-07-05 12:10:54 +08:00
Christian Brauner
978a73831c Merge pull request #1674 from 0x0916/2017-07-04/lxc-execute
lxc-execute: print error message when failed
2017-07-04 15:18:55 +02:00
Long Wang
6de247e335 lxc-execute: print error message when failed
Signed-off-by: Long Wang <w@laoqinren.net>
2017-07-04 16:16:30 +08:00
Christian Brauner
ea033bbcac
README: update
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-07-04 00:15:05 +02:00
Stéphane Graber
b5398df96c Merge pull request #1672 from brauner/2017-07-03/add_cii_best_practices_badge_to_readme
README: add CII Best Practices badge to README
2017-07-03 14:51:51 -04:00
Christian Brauner
0b39b2a9cc
README: add CII Best Practices badge to README
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-07-03 20:42:18 +02:00
Christian Brauner
cf4a661bda Merge pull request #1668 from 0x0916/2017-07-03/lxclock
lxclock: bugfix and update some comment
2017-07-03 11:30:59 +02:00
Long Wang
ccfc84ca9f lxclock: non-functional changes
This patch mainly updates comments based on the current code.

Signed-off-by: Long Wang <w@laoqinren.net>
2017-07-03 15:43:34 +08:00
Long Wang
98375790a4 lxclock: return the right error when open lock file failed
Signed-off-by: Long Wang <w@laoqinren.net>
2017-07-03 15:41:25 +08:00
Christian Brauner
b51eb5ca3a Merge pull request #1667 from 0x0916/2017-07-02/fix-cppcheck-warnings
fix some cppcheck warnings
2017-07-02 17:47:36 +02:00
Christian Brauner
26b9df9dc7 Merge pull request #1666 from 0x0916/2017-07-02/remove-unused-code
remove the unused macro
2017-07-02 17:46:29 +02:00
0x0916
6fc7d8b63e fix some cppcheck warnings
use cppcheck tools `cppcheck --enable=warning  .` on lxc source directory.

This patch fix the following warnning

```
[src/lxc/cgroups/cgfs.c:794]: (warning) %ld in format string (no. 3) requires 'long' but the argument type is 'unsigned long'.
[src/lxc/confile.c:4441]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.
[src/lxc/confile.c:4502]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.
[src/lxc/confile_legacy.c:921]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.
[src/lxc/confile_legacy.c:938]: (warning) %d in format string (no. 2) requires 'int' but the argument type is 'unsigned int'.
[src/lxc/lxclock.c:63]: (warning) %zd in format string (no. 1) requires 'ssize_t' but the argument type is 'size_t {aka unsigned long}'.
[src/lxc/tools/lxc_info.c:118]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'.
[src/lxc/tools/lxc_info.c:118]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.
[src/lxc/tools/lxc_info.c:123]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'.
[src/lxc/tools/lxc_info.c:127]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'.
[src/lxc/tools/lxc_info.c:130]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'.
[src/lxc/tools/lxc_top.c:212]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'.
[src/lxc/tools/lxc_top.c:212]: (warning) %u in format string (no. 2) requires 'unsigned int' but the argument type is 'signed int'.
[src/lxc/tools/lxc_top.c:217]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'.
[src/lxc/tools/lxc_top.c:221]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'.
[src/lxc/tools/lxc_top.c:224]: (warning) %u in format string (no. 1) requires 'unsigned int' but the argument type is 'signed int'.
```

Signed-off-by: Long Wang <w@laoqinren.net>
2017-07-02 22:18:16 +08:00
0x0916
157ad8d409 remove the unused macro
Signed-off-by: Long Wang <w@laoqinren.net>
2017-07-02 22:17:01 +08:00
Christian Brauner
0b427da0e7
confile: lxc.seccomp --> lxc.seccomp.profile
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-07-02 14:40:07 +02:00
Christian Brauner
232763d645
confile: lxc.pts --> lxc.pty.max
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-07-02 14:40:07 +02:00
Christian Brauner
fe1c588797
confile: lxc.tty --> lxc.tty.max
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-07-02 14:40:07 +02:00