]> git.proxmox.com Git - mirror_lxc.git/log
mirror_lxc.git
6 years agocommands: fix state socket implementation
Christian Brauner [Mon, 20 Nov 2017 21:16:40 +0000 (22:16 +0100)]
commands: fix state socket implementation

Remove dead state clients from state client list. Consider the following
scenario:

01 start container
02 issue shutdown request
03 state_client_fd is added to lxc_handler
03 container doesn't respond to shutdown request
04 user aborts shutdown request
05 lxc_cmd_fd_cleanup() removes state_client_fd from lxc_mainloop
06 invalid state_client_fd is still recorded in the lxc_handler
07 user issues lxc_cmd_stop() request via SIGKILL
08 container reaches STOPPED state and sends message to state_client_fd
09 state_client_fd number has been reused by lxc_cmd_stop_callback()
10 invalid data gets dumped to lxc_cmd_stop()

Reproducer:
Set an invalid shutdown signal to which the init system does not respond with a
shutdown via lxc.signal.halt e.g. "lxc.signal.halt = SIGUSR1". Then do:

1. start container
    root@conventiont|~
    > lxc-start -n a1

2. try to shutdown container
    root@conventiont|~
    > lxc-stop -n a1

3. abort shutdown
^C

4. SIGKILL the container (lxc.signal.stop = SIGKILL)
    root@conventiont|~
    > lxc-stop -n a1 -k
    lxc-stop: a1: commands.c: lxc_cmd_rsp_recv: 165 File too large - Response data for command "stop" is too long: 12641 bytes > 8192

To not let this happen we remove the state_client_fd from the lxc_handler when
we detect a cleanup event in lxc_cmd_fd_cleanup().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agolxccontainer: non-functional changes
Christian Brauner [Mon, 20 Nov 2017 15:50:00 +0000 (16:50 +0100)]
lxccontainer: non-functional changes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocommands: non-functional changes
Christian Brauner [Mon, 20 Nov 2017 15:49:30 +0000 (16:49 +0100)]
commands: non-functional changes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #1930 from lifeng68/Fix_parse_err
Christian Brauner [Mon, 20 Nov 2017 10:19:08 +0000 (11:19 +0100)]
Merge pull request #1930 from lifeng68/Fix_parse_err

Fix lxc_inherit_namespace function error

6 years agoFix namespace config parse error
LiFeng [Mon, 20 Nov 2017 11:42:30 +0000 (06:42 -0500)]
Fix namespace config parse error

Signed-off-by: LiFeng <lifeng68@huawei.com>
6 years agoMerge pull request #1925 from brauner/2017-11-14/console_config_keys
Serge Hallyn [Sat, 18 Nov 2017 00:04:59 +0000 (18:04 -0600)]
Merge pull request #1925 from brauner/2017-11-14/console_config_keys

console: add lxc.console.buffer.size, lxc.console.buffer.logfile, lxc.console.rotate

6 years agotest: expand console log tests
Christian Brauner [Wed, 15 Nov 2017 15:05:49 +0000 (16:05 +0100)]
test: expand console log tests

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocommands: rotate console log file
Christian Brauner [Wed, 15 Nov 2017 12:29:49 +0000 (13:29 +0100)]
commands: rotate console log file

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocommands: truncate console ringbuffer log file
Christian Brauner [Thu, 9 Nov 2017 18:39:59 +0000 (19:39 +0100)]
commands: truncate console ringbuffer log file

When a "clear" request is sent to the console ringbuffer we should truncate the
console log file as well.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoconsole: split console setup into logical parts
Christian Brauner [Wed, 15 Nov 2017 11:18:51 +0000 (12:18 +0100)]
console: split console setup into logical parts

The lxc_console_create() function used to munge the ringbuffer setup and the
log file setup already. This made somewhat sense when we didn't have a separate
ringbuffer log file. Now it's just plain confusing. So split this into logical
helpers that future maintainers can understand:

- lxc_console_create_log_file()
- lxc_console_create_ringbuf(console);
- lxc_console_create_ringbuf_log_file(console);

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocommands: only set ringbuffer datalen when needed
Christian Brauner [Wed, 15 Nov 2017 15:04:12 +0000 (16:04 +0100)]
commands: only set ringbuffer datalen when needed

If we do it unconditionally a request to only clear the ringbuffer and not read
or write anything will fail.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoconfile: add lxc.console.rotate
Christian Brauner [Tue, 14 Nov 2017 23:35:02 +0000 (00:35 +0100)]
confile: add lxc.console.rotate

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoconfile: add lxc.console.buffer.logfile
Christian Brauner [Tue, 14 Nov 2017 23:23:07 +0000 (00:23 +0100)]
confile: add lxc.console.buffer.logfile

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoconfile: add lxc.console.buffer.size
Christian Brauner [Tue, 14 Nov 2017 22:55:33 +0000 (23:55 +0100)]
confile: add lxc.console.buffer.size

Determines the size of the ringbuffer.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #1920 from brauner/2017-11-12/console_exit_clean_on_sigterm
Serge Hallyn [Mon, 13 Nov 2017 15:28:46 +0000 (09:28 -0600)]
Merge pull request #1920 from brauner/2017-11-12/console_exit_clean_on_sigterm

console: exit mainloop on SIGTERM

6 years agoMerge pull request #1922 from brauner/2017-11-13/generate_new_uuid_for_xfs_and_btrfs_...
Serge Hallyn [Mon, 13 Nov 2017 15:28:24 +0000 (09:28 -0600)]
Merge pull request #1922 from brauner/2017-11-13/generate_new_uuid_for_xfs_and_btrfs_snapshots

lvm: generate new UUID for xfs + btrfs filesystems

6 years agolvm: generate new UUID for xfs + btrfs filesystems
Christian Brauner [Mon, 13 Nov 2017 14:01:42 +0000 (15:01 +0100)]
lvm: generate new UUID for xfs + btrfs filesystems

Closes #1909.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoconsole: exit mainloop on SIGTERM
Christian Brauner [Sun, 12 Nov 2017 16:51:11 +0000 (17:51 +0100)]
console: exit mainloop on SIGTERM

This allows cleanly exiting a console session without control sequences.

Relates to https://github.com/lxc/lxd/pull/4001 .

Note that the existence of a signal handler now doesn't guarantee that ts->node
is allocated. Instead, ts->node will now only be added to if stdinfd is a tty.
New checks need to take that into account.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoconsole: prepare for generic signal handler
Christian Brauner [Sun, 12 Nov 2017 14:25:19 +0000 (15:25 +0100)]
console: prepare for generic signal handler

Non-functional changes to enable handling more signals.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #1919 from brauner/2017-11-11/console_fix_escape_sequence
Serge Hallyn [Sun, 12 Nov 2017 04:38:34 +0000 (22:38 -0600)]
Merge pull request #1919 from brauner/2017-11-11/console_fix_escape_sequence

console: use correct escape sequence check

6 years agoconsole: use correct escape sequence check
Christian Brauner [Sat, 11 Nov 2017 22:05:33 +0000 (23:05 +0100)]
console: use correct escape sequence check

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #1918 from brauner/2017-11-11/daemonized_execute
Serge Hallyn [Sat, 11 Nov 2017 03:41:29 +0000 (21:41 -0600)]
Merge pull request #1918 from brauner/2017-11-11/daemonized_execute

lxccontainer: enable daemonized execute

6 years agoMerge pull request #1907 from brauner/2017-11-08/cgfsng
Serge Hallyn [Sat, 11 Nov 2017 00:54:26 +0000 (18:54 -0600)]
Merge pull request #1907 from brauner/2017-11-08/cgfsng

cgroups/cgfsng: adapt to new cgroup2 delegation

6 years agotools: add "--daemonize/-d"
Christian Brauner [Fri, 10 Nov 2017 23:22:09 +0000 (00:22 +0100)]
tools: add "--daemonize/-d"

This lets's users run daemonized application containers with our minimal init
as pid 1 and the requested program as pid 2.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agolxccontainer: enable daemonized app containers
Christian Brauner [Fri, 10 Nov 2017 23:21:09 +0000 (00:21 +0100)]
lxccontainer: enable daemonized app containers

This enables daemonized application containers with our minimal init running as
pid one and the requested program running as second pid.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #1917 from brauner/2017-11-10/report_console_detach_only_when_needed
Stéphane Graber [Fri, 10 Nov 2017 19:22:44 +0000 (14:22 -0500)]
Merge pull request #1917 from brauner/2017-11-10/report_console_detach_only_when_needed

console: report detach message on demand

6 years agoconsole: report detach message on demand
Christian Brauner [Fri, 10 Nov 2017 18:51:57 +0000 (19:51 +0100)]
console: report detach message on demand

When users pass -1 there's there won't be an escape sequence to exit the
console so no need to print a misleading info message about how to detach.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #1916 from brauner/2017-11-10/fix_console_info_output
Stéphane Graber [Fri, 10 Nov 2017 18:28:32 +0000 (13:28 -0500)]
Merge pull request #1916 from brauner/2017-11-10/fix_console_info_output

console: fix console info message

6 years agoAdd missing dependency libunistring
CC-Hsu [Fri, 10 Nov 2017 15:22:29 +0000 (23:22 +0800)]
Add missing dependency libunistring

Hi,

I try to create a Slackware container in a Slackware64 14.2 current and
find that wget depends on libunistring.

So I add libunistring to the package list.

Closes #1915

Signed-off-by: Chia-Chun Hsu a12321aabb@gmail.com
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
6 years agoconsole: fix console info message
Christian Brauner [Fri, 10 Nov 2017 18:07:38 +0000 (19:07 +0100)]
console: fix console info message

Now it will be displayed nicely formatted:

a1 login: chb@conventiont|~
> lxc console a1

Connected to tty 0
Type <Ctrl+a q> to exit the console, <Ctrl+a Ctrl+a> to enter Ctrl+a itself

Ubuntu 17.10 a1 console

a1 login:

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #1910 from brauner/2017-11-08/attach_without_conf
Stéphane Graber [Fri, 10 Nov 2017 07:16:52 +0000 (02:16 -0500)]
Merge pull request #1910 from brauner/2017-11-08/attach_without_conf

attach: allow attach with empty conf

6 years agoMerge pull request #1914 from flx42/lxc-oci-fix-url-long-option
Stéphane Graber [Fri, 10 Nov 2017 07:16:23 +0000 (02:16 -0500)]
Merge pull request #1914 from flx42/lxc-oci-fix-url-long-option

lxc-oci: correctly handle --url

6 years agolxc-oci: correctly handle --url
Felix Abecassis [Fri, 10 Nov 2017 06:49:35 +0000 (22:49 -0800)]
lxc-oci: correctly handle --url

Fix: #1898
Signed-off-by: Felix Abecassis <fabecassis@nvidia.com>
6 years agoMerge pull request #1913 from AustinReichert/remove-api-calls
Christian Brauner [Fri, 10 Nov 2017 00:19:26 +0000 (01:19 +0100)]
Merge pull request #1913 from AustinReichert/remove-api-calls

First tools/ refactor for review

6 years agotools/lxc_attach: removed api logging
Austin Reichert [Thu, 9 Nov 2017 23:33:29 +0000 (17:33 -0600)]
tools/lxc_attach: removed api logging

Signed-off-by: Austin Reichert <austinskyreichert@utexas.edu>
6 years agoMerge pull request #1908 from Cypresslin/fix-overlayfs
Christian Brauner [Thu, 9 Nov 2017 18:44:10 +0000 (19:44 +0100)]
Merge pull request #1908 from Cypresslin/fix-overlayfs

lxc-test-unpriv: fix the overlayfs mount error

6 years agoMerge pull request #1871 from brauner/2017-10-21/api_extension_console_ringbuffer
Serge Hallyn [Wed, 8 Nov 2017 22:20:24 +0000 (16:20 -0600)]
Merge pull request #1871 from brauner/2017-10-21/api_extension_console_ringbuffer

API: add console ringbuffer extension

6 years agoattach: allow attach with empty conf
Christian Brauner [Wed, 8 Nov 2017 21:13:48 +0000 (22:13 +0100)]
attach: allow attach with empty conf

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agolxc-test-unpriv: fix the overlayfs mount error
Po-Hsu Lin [Wed, 8 Nov 2017 09:13:58 +0000 (04:13 -0500)]
lxc-test-unpriv: fix the overlayfs mount error

This patch fixes the missing workdir issue for the overlayfs mount command in
the lxc-test-unpriv test.

link: https://bugs.launchpad.net/bugs/1730915
Signed-off-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
6 years agocgroups/cgfsng: adapt to new cgroup2 delegation
Christian Brauner [Wed, 8 Nov 2017 00:50:55 +0000 (01:50 +0100)]
cgroups/cgfsng: adapt to new cgroup2 delegation

In order to enable proper unprivileged cgroup delegation on newer kernels we not
just need to delegate the "cgroup.procs" file but also "cgroup.threads". But
don't report an error in case it doesn't exist. Also delegate
"cgroup.subtree_control" to enable delegation of controllers to descendant
cgroups.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #1891 from brauner/2017-10-31/cgfsng_fixes
Serge Hallyn [Tue, 7 Nov 2017 19:16:48 +0000 (13:16 -0600)]
Merge pull request #1891 from brauner/2017-10-31/cgfsng_fixes

cgroups/cgfsng: fixes, features, and improved cgroup2 handling

6 years agoMerge pull request #1903 from brauner/2017-11-06/storage_new_default_fs
Serge Hallyn [Tue, 7 Nov 2017 18:23:12 +0000 (12:23 -0600)]
Merge pull request #1903 from brauner/2017-11-06/storage_new_default_fs

storage: switch to ext4 as default fs

6 years agoMerge pull request #1893 from brauner/2017-11-01/attach_handle_namespace_inheritance
Serge Hallyn [Tue, 7 Nov 2017 18:18:39 +0000 (12:18 -0600)]
Merge pull request #1893 from brauner/2017-11-01/attach_handle_namespace_inheritance

attach: handle namespace inheritance

6 years agotests: add tests for console_log()
Christian Brauner [Fri, 27 Oct 2017 19:15:48 +0000 (21:15 +0200)]
tests: add tests for console_log()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoconsole: non-functional changes
Christian Brauner [Thu, 26 Oct 2017 15:33:10 +0000 (17:33 +0200)]
console: non-functional changes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoconsole: add "write_logfile" to console_log struct
Christian Brauner [Thu, 26 Oct 2017 21:49:21 +0000 (23:49 +0200)]
console: add "write_logfile" to console_log struct

If a console log file was specified this flag indicates whether the contents of
the ringbuffer should be written to the logfile when a request is sent to the
ringbuffer.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoconsole: write ringbuffer to disk
Christian Brauner [Thu, 26 Oct 2017 16:32:29 +0000 (18:32 +0200)]
console: write ringbuffer to disk

When users request that the container keep a console ringbuffer we will not
continously write to the on-disk logfile as mirroring the contents of the
in-memory ringbuffer on-disk is costly and complicated. Instead, we dump the
ringbuffer contents on-disk when the container stops or fails to start. This
way users can still diagnose problems or retrieve the last contents of the
ringbuffer on-disk.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoconsole: move ringbuffer into lxc_console_create()
Christian Brauner [Mon, 23 Oct 2017 12:23:12 +0000 (14:23 +0200)]
console: move ringbuffer into lxc_console_create()

This makes the whole setup more flexible.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoconsole: non-functional changes
Christian Brauner [Mon, 23 Oct 2017 11:41:33 +0000 (13:41 +0200)]
console: non-functional changes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agolxccontainer: add console_log() API extension
Christian Brauner [Sun, 22 Oct 2017 20:14:49 +0000 (22:14 +0200)]
lxccontainer: add console_log() API extension

commands: add LXC_CMD_CONSOLE_LOG

Closes #1870.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocommands: non-functional changes
Christian Brauner [Sun, 22 Oct 2017 20:11:33 +0000 (22:11 +0200)]
commands: non-functional changes

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoconfig: remove SIGRTMIN+14 as lxc.signal.stop
Christian Brauner [Tue, 31 Oct 2017 21:19:38 +0000 (22:19 +0100)]
config: remove SIGRTMIN+14 as lxc.signal.stop

We want to be able to SIGKILL an Archlinux container.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroupfs/cgfsng: improve cgroup2 handling
Christian Brauner [Tue, 31 Oct 2017 16:07:57 +0000 (17:07 +0100)]
cgroupfs/cgfsng: improve cgroup2 handling

This fixes a bunch of bugs.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroups/cgfsng: fix get_controllers() for cgroup2
Christian Brauner [Tue, 31 Oct 2017 16:06:58 +0000 (17:06 +0100)]
cgroups/cgfsng: fix get_controllers() for cgroup2

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroups/cgfsng: remove is_lxcfs()
Christian Brauner [Wed, 1 Nov 2017 10:13:18 +0000 (11:13 +0100)]
cgroups/cgfsng: remove is_lxcfs()

We don't need to parse fuse.lxcfs entries.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroupfs/cgfsng: tweak logging
Christian Brauner [Tue, 31 Oct 2017 16:05:22 +0000 (17:05 +0100)]
cgroupfs/cgfsng: tweak logging

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agolog: check for i/o error with vsnprintf()
Christian Brauner [Tue, 31 Oct 2017 11:05:13 +0000 (12:05 +0100)]
log: check for i/o error with vsnprintf()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroups/cgfsng: support MS_READONLY with cgroup ns
Christian Brauner [Tue, 31 Oct 2017 11:01:29 +0000 (12:01 +0100)]
cgroups/cgfsng: support MS_READONLY with cgroup ns

If we lack CAP_SYS_ADMIN this is really useful.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroups/cgfsng: cgfsns_chown() -> cgfsng_chown()
Christian Brauner [Tue, 31 Oct 2017 10:16:46 +0000 (11:16 +0100)]
cgroups/cgfsng: cgfsns_chown() -> cgfsng_chown()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroups/cgfsng: make sure pointer is NULL
Christian Brauner [Tue, 31 Oct 2017 10:55:23 +0000 (11:55 +0100)]
cgroups/cgfsng: make sure pointer is NULL

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgroups/cgfsng: keep mountpoint intact
Christian Brauner [Tue, 31 Oct 2017 10:15:07 +0000 (11:15 +0100)]
cgroups/cgfsng: keep mountpoint intact

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoattach: handle namespace inheritance
Christian Brauner [Wed, 1 Nov 2017 09:44:18 +0000 (10:44 +0100)]
attach: handle namespace inheritance

We need to have lxc_attach() distinguish between a caller specifying specific
namespaces to attach to and a caller not requesting specific namespaces. The
latter is taken by lxc_attach() to mean that all namespaces will be attached.
This also needs to include all inherited namespaces.

Closes #1890.
Closes #1897.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agotools: fix help output of lxc-create
Christian Brauner [Mon, 6 Nov 2017 11:54:06 +0000 (12:54 +0100)]
tools: fix help output of lxc-create

Closes #1899.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agostorage: switch to ext4 as default filesystem
Christian Brauner [Mon, 6 Nov 2017 11:52:43 +0000 (12:52 +0100)]
storage: switch to ext4 as default filesystem

Closes #1899.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #1906 from brauner/2017-11-06/cgns_check_before_preserve
Stéphane Graber [Mon, 6 Nov 2017 22:45:07 +0000 (17:45 -0500)]
Merge pull request #1906 from brauner/2017-11-06/cgns_check_before_preserve

start: only preserve CLONE_NEWCGROUP when supported

6 years agostart: only preserve CLONE_NEWCGROUP when supported
Christian Brauner [Mon, 6 Nov 2017 22:24:01 +0000 (23:24 +0100)]
start: only preserve CLONE_NEWCGROUP when supported

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #1901 from jacmet/fix-no-new-privs-check
Christian Brauner [Mon, 6 Nov 2017 11:15:40 +0000 (12:15 +0100)]
Merge pull request #1901 from jacmet/fix-no-new-privs-check

lxc/start.c: Fix legacy PR_{G,S}ET_NO_NEW_PRIVS handling

6 years agolxc/start.c: Fix legacy PR_{G,S}ET_NO_NEW_PRIVS handling
Peter Korsgaard [Mon, 6 Nov 2017 08:35:48 +0000 (09:35 +0100)]
lxc/start.c: Fix legacy PR_{G,S}ET_NO_NEW_PRIVS handling

The configure checks for these use AC_CHECK_DECLS, which define the symbol
to 0 if not available - So adjust the code to match.  From the autoconf
manual:

https://www.gnu.org/software/autoconf/manual/autoconf-2.65/html_node/Generic-Declarations.html)

For each of the symbols (comma-separated list), define HAVE_DECL_symbol (in
all capitals) to ‘1’ if symbol is declared, otherwise to ‘0’.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
6 years agoMerge pull request #1884 from brauner/2017-10-28/move_tools_to_api_only
Serge Hallyn [Sun, 5 Nov 2017 03:27:45 +0000 (22:27 -0500)]
Merge pull request #1884 from brauner/2017-10-28/move_tools_to_api_only

confile: add lxc.namespace.<namespace-key> + add user namespace sharing + rework start logic

6 years agoconf: reap child in all cases
Christian Brauner [Wed, 1 Nov 2017 20:58:24 +0000 (21:58 +0100)]
conf: reap child in all cases

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agonetwork: reap child in all cases
Christian Brauner [Wed, 1 Nov 2017 20:52:07 +0000 (21:52 +0100)]
network: reap child in all cases

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agostart: rework ns sharing + add userns sharing
Christian Brauner [Sun, 29 Oct 2017 22:11:22 +0000 (23:11 +0100)]
start: rework ns sharing + add userns sharing

- Implement inheriting user namespaces.
  - When inheriting user namespaces make sure to not try and map ids again. The
    kernel will not allow you to do this.
- Change clone() logic:
  1. If we inherit no namespaces simply call lxc_clone().
  2. If we inherit any namespaces call lxc_fork_attach_clone(). Here's why:
     - Causes one syscall (fork()) instead of two syscalls (setns() to
       inherited namespace and setns() back to parent namespace) to be
       performed.
     - Allows us to get rid of a bunch of variables and helper functions/code.
     - Sharing a user namespaces requires us to setns() to the inherited user
       namespace but the kernel does not allow reattaching to a parent user
       namespace. So the old logic made user namespace inheritance impossible.
       By using the lxc_fork_attach_clone() model we can simply setns() to the
       inherited user namespace in the fork()ed child and be done with it.
       The only thing we need to do is to specify CLONE_PARENT when calling
       clone() in lxc_fork_attach_clone() so that we can wait on the child.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agomonitor: do not log useless warnings
Christian Brauner [Sun, 29 Oct 2017 16:26:13 +0000 (17:26 +0100)]
monitor: do not log useless warnings

lxc-monitord is deprecated so this is expected to fail.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agostart: close data socket in parent
Christian Brauner [Sun, 29 Oct 2017 16:03:57 +0000 (17:03 +0100)]
start: close data socket in parent

Brings the number of open fds in the monitor process for a standard container
without ttys down to 17.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoconfile: add lxc.namespace.<namespace-key>
Christian Brauner [Sat, 28 Oct 2017 20:07:27 +0000 (22:07 +0200)]
confile: add lxc.namespace.<namespace-key>

This commit also gets rid of ~10 unnecessarily file descriptors that were kept
open. Before we kept open:

- A set of file descriptors that refer to the monitor's namespaces. These were
  only used to reattach to the monitor's namespace in lxc_spawn() and were
  never used anywhere else. So close them and don't keep them around.
- A list of inherited file descriptors.
- A list of file descriptors referring to the containers's namespaces to pass
  to lxc.hook.stop. This list duplicated inherited file descriptors.

Let's simply use a single list in the handler that has all file descriptors we
need and get rid of all other ones. As an illustration. Starting a container

1. Without this patch and looking at the fds that the monitor keeps open (26):

chb@conventiont|~
> ls -al /proc/27219/fd
total 0
dr-x------ 2 root root  0 Oct 29 14:30 .
dr-xr-xr-x 9 root root  0 Oct 29 14:30 ..
lrwx------ 1 root root 64 Oct 29 14:30 0 -> /dev/null
lrwx------ 1 root root 64 Oct 29 14:30 1 -> /dev/null
lrwx------ 1 root root 64 Oct 29 14:30 10 -> anon_inode:[signalfd]
lrwx------ 1 root root 64 Oct 29 14:30 11 -> /dev/ptmx
lrwx------ 1 root root 64 Oct 29 14:30 12 -> /dev/pts/10
lr-x------ 1 root root 64 Oct 29 14:30 13 -> net:[4026532553]
lrwx------ 1 root root 64 Oct 29 14:30 15 -> socket:[7909181]
lrwx------ 1 root root 64 Oct 29 14:30 16 -> socket:[7909182]
lr-x------ 1 root root 64 Oct 29 14:30 17 -> uts:[4026531838]
lr-x------ 1 root root 64 Oct 29 14:30 18 -> ipc:[4026531839]
lr-x------ 1 root root 64 Oct 29 14:30 19 -> net:[4026532009]
lrwx------ 1 root root 64 Oct 29 14:30 2 -> /dev/null
lr-x------ 1 root root 64 Oct 29 14:30 20 -> mnt:[4026532611]
lr-x------ 1 root root 64 Oct 29 14:30 21 -> pid:[4026532612]
lr-x------ 1 root root 64 Oct 29 14:30 22 -> uts:[4026532548]
lr-x------ 1 root root 64 Oct 29 14:30 23 -> ipc:[4026532549]
lr-x------ 1 root root 64 Oct 29 14:30 24 -> net:[4026532553]
l-wx------ 1 root root 64 Oct 29 14:30 3 -> /var/log/lxc/a1.log
lr-x------ 1 root root 64 Oct 29 14:30 4 -> uts:[4026532548]
lr-x------ 1 root root 64 Oct 29 14:30 5 -> ipc:[4026532549]
lr-x------ 1 root root 64 Oct 29 14:30 6 -> net:[4026532553]
lrwx------ 1 root root 64 Oct 29 14:30 7 -> anon_inode:[eventpoll]
lrwx------ 1 root root 64 Oct 29 14:30 9 -> socket:[7911594]

2. With this patch and looking at the fds that the monitor keeps open (19):

chb@conventiont|~
> ls -al /proc/28465/fd
total 0
dr-x------ 2 root root  0 Oct 29 14:31 .
dr-xr-xr-x 9 root root  0 Oct 29 14:31 ..
lrwx------ 1 root root 64 Oct 29 14:31 0 -> /dev/null
lrwx------ 1 root root 64 Oct 29 14:31 1 -> /dev/null
lr-x------ 1 root root 64 Oct 29 14:31 10 -> net:[4026532820]
lrwx------ 1 root root 64 Oct 29 14:31 12 -> socket:[7912349]
lrwx------ 1 root root 64 Oct 29 14:31 13 -> socket:[7912350]
lr-x------ 1 root root 64 Oct 29 14:31 14 -> mnt:[4026532611]
lr-x------ 1 root root 64 Oct 29 14:31 15 -> pid:[4026532813]
lr-x------ 1 root root 64 Oct 29 14:31 16 -> uts:[4026532612]
lr-x------ 1 root root 64 Oct 29 14:31 17 -> ipc:[4026532613]
lr-x------ 1 root root 64 Oct 29 14:31 18 -> net:[4026532820]
lrwx------ 1 root root 64 Oct 29 14:31 2 -> /dev/null
l-wx------ 1 root root 64 Oct 29 14:31 3 -> /var/log/lxc/a1.log
lrwx------ 1 root root 64 Oct 29 14:31 4 -> anon_inode:[signalfd]
lrwx------ 1 root root 64 Oct 29 14:31 5 -> /dev/ptmx
lrwx------ 1 root root 64 Oct 29 14:31 6 -> /dev/pts/10
lrwx------ 1 root root 64 Oct 29 14:31 7 -> anon_inode:[eventpoll]
lrwx------ 1 root root 64 Oct 29 14:31 9 -> socket:[7913041]

Relates to #1881.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agohandler: make name argument const
Christian Brauner [Sat, 28 Oct 2017 20:05:18 +0000 (22:05 +0200)]
handler: make name argument const

There's no obvious need to strdup() the name of the container in the handler.
We can simply make this a pointer to the memory allocated in
lxc_container_new().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agostart: close non-needed file descriptors
Christian Brauner [Sun, 29 Oct 2017 12:07:46 +0000 (13:07 +0100)]
start: close non-needed file descriptors

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agolxc-start: remove unnecessary checks
Christian Brauner [Sat, 28 Oct 2017 13:30:04 +0000 (15:30 +0200)]
lxc-start: remove unnecessary checks

The console struct is internal and liblxc takes care of creating paths.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #1896 from ffontaine/master
Christian Brauner [Thu, 2 Nov 2017 20:40:58 +0000 (23:40 +0300)]
Merge pull request #1896 from ffontaine/master

Fix compilation on toolchain without prlimit

6 years agoFix compilation on toolchain without prlimit
Fabrice Fontaine [Thu, 2 Nov 2017 15:00:33 +0000 (16:00 +0100)]
Fix compilation on toolchain without prlimit

Some toolchains which are not bionic like uclibc does not support
prlimit or prlimit64. In this case, return an error.
Moreover, if prlimit64 is available, use lxc implementation of prlimit.

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
6 years agoMerge pull request #1883 from brauner/2017-10-29/fix_namespace_inheritance_on_attach
Serge Hallyn [Mon, 30 Oct 2017 18:14:40 +0000 (13:14 -0500)]
Merge pull request #1883 from brauner/2017-10-29/fix_namespace_inheritance_on_attach

attach: correctly handle namespace inheritance

6 years agoMerge pull request #1875 from brauner/2017-10-27/tools_allow_undefined_containers
Stéphane Graber [Mon, 30 Oct 2017 17:22:47 +0000 (18:22 +0100)]
Merge pull request #1875 from brauner/2017-10-27/tools_allow_undefined_containers

tools: allow lxc-attach to undefined containers

6 years agoMerge pull request #1888 from brauner/2017-10-30/enable_cgfsng_cgroup_mounting
Serge Hallyn [Mon, 30 Oct 2017 15:30:13 +0000 (10:30 -0500)]
Merge pull request #1888 from brauner/2017-10-30/enable_cgfsng_cgroup_mounting

cgroups: enable container without CAP_SYS_ADMIN

6 years agocgroups: enable container without CAP_SYS_ADMIN
Christian Brauner [Mon, 30 Oct 2017 13:16:46 +0000 (14:16 +0100)]
cgroups: enable container without CAP_SYS_ADMIN

In case cgroup namespaces are supported but we do not have CAP_SYS_ADMIN we
need to mount cgroups for the container. This patch enables both privileged and
unprivileged containers without CAP_SYS_ADMIN.

Closes #1737.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agocgfsng: fix cgroup2 detection
Christian Brauner [Mon, 30 Oct 2017 13:17:20 +0000 (14:17 +0100)]
cgfsng: fix cgroup2 detection

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoattach: correctly handle namespace inheritance
Christian Brauner [Sun, 29 Oct 2017 11:19:43 +0000 (12:19 +0100)]
attach: correctly handle namespace inheritance

When attaching to a container's namespaces we did not handle the case where we
inherited namespaces correctly. In essence, liblxc on start records the
namespaces the container was created with in the handler. But it only records
the clone flags that were passed to clone() and doesn't record the namespaces
we e.g. inherited from other containers. This means that attach only ever
attached to the clone flags. But this is only correct if all other namespaces
not recorded in the handler refer to the namespaces of the caller. However,
this need not be the case if the container has inherited namespaces from
another container. To handle this case we need to check whether caller and
container are in the same namespace. If they are, we know that things are all
good. If they aren't then we need to attach to these namespaces as well.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #1880 from terceiro/lxc-debian
Christian Brauner [Sat, 28 Oct 2017 13:05:05 +0000 (15:05 +0200)]
Merge pull request #1880 from terceiro/lxc-debian

lxc-debian improvements

6 years agolxc-debian: don't hardcode valid releases
Antonio Terceiro [Sat, 28 Oct 2017 11:20:35 +0000 (09:20 -0200)]
lxc-debian: don't hardcode valid releases

This avoids the dance of updating the list of valid releases every time
Debian makes a new release.

It also fixes the following bug: even though lxc-debian will default to
creating containers of the latest stable by querying the archive, it
won't allow you to explicitly request `stable` because the current list
of valid releases don't include it.

Last, but not least, avoid hitting the mirror in the case the desired
release is one of the ones we know will always be there, i.e. stable,
testing, sid, and unstable.

Signed-off-by: Antonio Terceiro <terceiro@debian.org>
6 years agolxc-debian: don't write C.* locales to /etc/locale.gen
Antonio Terceiro [Fri, 27 Oct 2017 19:13:54 +0000 (17:13 -0200)]
lxc-debian: don't write C.* locales to /etc/locale.gen

Doing that confuses locale generation. lxc-ubuntu does the same check

Signed-off-by: Antonio Terceiro <terceiro@debian.org>
6 years agoMerge pull request #1879 from jordemort/lxc-execute-config-define-load
Christian Brauner [Fri, 27 Oct 2017 23:18:45 +0000 (01:18 +0200)]
Merge pull request #1879 from jordemort/lxc-execute-config-define-load

Call lxc_config_define_load from lxc_execute again

6 years agoMerge pull request #1874 from adrian5/patch-1
Stéphane Graber [Fri, 27 Oct 2017 19:28:24 +0000 (15:28 -0400)]
Merge pull request #1874 from adrian5/patch-1

Fix typo in lxc-net script

6 years agoAdd missing lxc_container_put
Jordan Webb [Fri, 27 Oct 2017 18:30:49 +0000 (13:30 -0500)]
Add missing lxc_container_put

Signed-off-by: Jordan Webb <jordemort@github.com>
6 years agoFix typo in lxc-net script
adrian5 [Thu, 26 Oct 2017 23:47:37 +0000 (01:47 +0200)]
Fix typo in lxc-net script

Signed-off-by: adrian5 <adrian5@users.noreply.github.com>
6 years agoCall lxc_config_define_load from lxc_execute again
Jordan Webb [Fri, 27 Oct 2017 16:53:32 +0000 (11:53 -0500)]
Call lxc_config_define_load from lxc_execute again

Signed-off-by: Jordan Webb <jordemort@github.com>
6 years agotools: allow lxc-attach to undefined containers
Christian Brauner [Fri, 27 Oct 2017 11:41:28 +0000 (13:41 +0200)]
tools: allow lxc-attach to undefined containers

For example the following sequence is expected to work:

lxc-start -n containerName -f /path/to/conf \
-s 'lxc.id_map = u 0 100000 65536' \
-s 'lxc.id_map = g 0 100000 65536' \
-s 'lxc.rootfs = /path/to/rootfs' \
-s 'lxc.init_cmd = /path/to/initcmd'

lxc-attach -n containerName

Closes #984.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoMerge pull request #1873 from terceiro/debian-rolling
Christian Brauner [Fri, 27 Oct 2017 04:02:16 +0000 (06:02 +0200)]
Merge pull request #1873 from terceiro/debian-rolling

lxc-debian: allow creating `testing` and `unstable`

6 years agolxc-debian: allow creating `testing` and `unstable`
Antonio Terceiro [Thu, 26 Oct 2017 22:42:49 +0000 (20:42 -0200)]
lxc-debian: allow creating `testing` and `unstable`

Being able to create `testing` containers, regardless of what's the name
of the next stable, is useful in several contexts, included but not
limited to testing purposes. i.e. one won't need to explicitly switch to
`bullseye` once `buster` is released to be able to continue tracking
`testing`. While we are at it, let's also enable `unstable`, which is
exactly the same as `sid`, but there is no reason for not being able to.

Signed-off-by: Antonio Terceiro <terceiro@debian.org>
6 years agoMerge pull request #1864 from brauner/2017-10-18/ringbuffer
Serge Hallyn [Sat, 21 Oct 2017 17:03:46 +0000 (13:03 -0400)]
Merge pull request #1864 from brauner/2017-10-18/ringbuffer

ringbuffer: implement efficient and performant ringbuffer

6 years agonamespace: use lxc_getpagesize()
Christian Brauner [Sat, 21 Oct 2017 14:27:34 +0000 (16:27 +0200)]
namespace: use lxc_getpagesize()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
6 years agoconsole: add ringbuffer
Christian Brauner [Wed, 18 Oct 2017 18:30:08 +0000 (20:30 +0200)]
console: add ringbuffer

Closes #1857.

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