]> git.proxmox.com Git - mirror_lxc.git/log
mirror_lxc.git
10 years agoA few changes for unprivileged lxc-start
Serge Hallyn [Fri, 10 May 2013 19:35:26 +0000 (12:35 -0700)]
A few changes for unprivileged lxc-start

When doing reboot test, must add clone_newuser to clone flags, else
we can't clone(CLONE_NEWPID).

If we don't have caps at lxc-start, don't refuse to start.  Drop the
lxc_caps_check() function altogether as it is unused now.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
10 years agosend current cgroup to lxc_cgroup_create()
Serge Hallyn [Fri, 19 Jul 2013 03:46:30 +0000 (22:46 -0500)]
send current cgroup to lxc_cgroup_create()

This is needed if we're going to have unprivileged users
create containers inside cgroups which they own.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
10 years agoubuntu-cloud: changes to support unprivileged use
Serge Hallyn [Tue, 16 Jul 2013 01:24:14 +0000 (20:24 -0500)]
ubuntu-cloud: changes to support unprivileged use

don't try to lock if using a specified tarball

The lock/subsys/lxc-ubuntu-cloud lock is to protect the tarballs
managed under /var/cache/lxc/cloud-$release.  Don't lock if we've
been handed a tarball.

fake device creation

Unprivileged users can't create devices, so bind mount null, tty, urandom
and console from the host.

Changelog:
Jul 22: as Stéphane points out, remove a left-over debug line

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
10 years agolxc-create: support unpriv users
Serge Hallyn [Thu, 9 May 2013 01:25:06 +0000 (20:25 -0500)]
lxc-create: support unpriv users

Just make sure we are root if we are asked to deal with something other
than a directory, and make sure we have permission to create the
container in the given lxcpath.

The templates will need much more work.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
10 years agotemplates: require running as root
Serge Hallyn [Thu, 9 May 2013 01:15:29 +0000 (20:15 -0500)]
templates: require running as root

Up to now lxc-create ensured that you were running as root.  Now the
templates which require root need to do it for themselves.  Templates
which do mknod definately require root.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
10 years agoteach lxc-cirros about the --rootfs argument
Serge Hallyn [Thu, 18 Jul 2013 21:08:12 +0000 (16:08 -0500)]
teach lxc-cirros about the --rootfs argument

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agoubuntu templates: add some kernel filesystems to container fstab
Serge Hallyn [Wed, 17 Jul 2013 14:38:28 +0000 (09:38 -0500)]
ubuntu templates: add some kernel filesystems to container fstab

The debugfs, fusectl, and securityfs may not be mounted inside a
non-init userns.  But mountall hangs waiting for them to be
mounted.  So just pre-mount them using $lxcpath/$name/fstab as
bind mounts, which will prevent mountall from trying to mount
them.

If the kernel doesn't provide them, then the bind mount failure
will be ignored, and mountall in the container will proceed
without the mount since it is 'optional'.  But without these
bind mounts, starting a container inside a user namespace
hangs.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
10 years agoclone: only update <rootfs>/etc/hostname if it exists
Dwight Engen [Tue, 16 Jul 2013 14:35:02 +0000 (10:35 -0400)]
clone: only update <rootfs>/etc/hostname if it exists

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agoMake get_ips timeout poll configurable
John McFarlane [Fri, 12 Jul 2013 21:06:20 +0000 (14:06 -0700)]
Make get_ips timeout poll configurable

This commit increases the default timeout used by lxc-start-ephemeral
from 5 to 10, and adds support for an LXC_IP_TIMEOUT override.

Patchset 2:
  - Previous patch used a command line arg.

Signed-off-by: John McFarlane <john@rockfloat.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
10 years agolxccontainer: don't define certain variables if !HAVE_GNUTLS
Serge Hallyn [Tue, 16 Jul 2013 13:11:56 +0000 (08:11 -0500)]
lxccontainer: don't define certain variables if !HAVE_GNUTLS

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agouserns: clear and save id_map (v2)
Serge Hallyn [Mon, 15 Jul 2013 21:42:15 +0000 (16:42 -0500)]
userns: clear and save id_map (v2)

Otherwise (a) there is a memory leak when using user namespaces and
clearing a config, and (b) saving a container configuration file doesn't
maintain the userns mapping.  For instance, if container c1 has
lxc.id_map configuration entries, then

python3
import lxc
c=lxc.Container("c1")
c.save_config("/tmp/config1")

should show 'lxc.id_map =' entries in /tmp/config1.

Changelog for v2:
   1. fix incorrect saving of group types (s/'c'/'g')
   2. fix typo -> idmap->type should be idmap->idtype

Reported-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
Tested-by: Dwight Engen <dwight.engen@oracle.com>
10 years agolxc_create: prepend pretty header to config file (v2)
Serge Hallyn [Fri, 12 Jul 2013 19:07:23 +0000 (14:07 -0500)]
lxc_create: prepend pretty header to config file (v2)

Define a sha1sum_file() function in utils.c.  Use that in lxcapi_create
to write out the sha1sum of the template being used.  If libgnutls is
not found, then the template sha1sum simply won't be printed into the
container config.

This patch also trivially fixes some cases where SYSERROR is used after
a fclose (masking errno) and missing consts in mkdir_p.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agoubuntu-cloud template: accept --rootfs argument
Serge Hallyn [Fri, 12 Jul 2013 20:33:06 +0000 (15:33 -0500)]
ubuntu-cloud template: accept --rootfs argument

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agoremove old lxc-create script.
Serge Hallyn [Fri, 12 Jul 2013 19:08:17 +0000 (14:08 -0500)]
remove old lxc-create script.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agocreate: add a quiet flag
Serge Hallyn [Fri, 12 Jul 2013 14:44:41 +0000 (09:44 -0500)]
create: add a quiet flag

If set, then fds 0,1,2 will be redirected while the creation
template is executed.

Note, as Dwight has pointed out, if fd 0 is redirected, then if
templates ask for input there will be a problem.  We could simply
not redirect fd 0, or we could require that templates work without
interaction.  I'm assuming here that we want to do the latter, but
I'm open to changing that.

Reported-by: "S.Çağlar Onur" <caglar@10ur.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agolxc_clone.c: Allow size subfixes for -L parameter
zoolook [Thu, 11 Jul 2013 23:38:02 +0000 (20:38 -0300)]
lxc_clone.c: Allow size subfixes for -L parameter

lxc-clone ignores size subfixes (K, M, G) when using -L parameter. The
following is a quick patch to allow, for example, lxc-clone -L 10G.

Signed-off-by: Norberto Bensa <nbensa@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agoAccomodate stricter devices cgroup rules
Serge Hallyn [Sat, 6 Jul 2013 00:34:55 +0000 (19:34 -0500)]
Accomodate stricter devices cgroup rules

3.10 kernel comes with proper hierarchical enforcement of devices
cgroup.  To keep that code somewhat sane, certain things are not
allowed.  Switching from default-allow to default-deny and vice versa
are not allowed when there are children cgroups.  (This *could* be
simplified in the kernel by checking that all child cgroups are
unpopulated, but that has not yet been done and may be rejected)

The mountcgroup hook causes lxc-start to break with 3.10 kernels, because
you cannot write 'a' to devices.deny once you have a child cgroup.  With
this patch, (a) lxcpath is passed to hooks, (b) the cgroup mount hook sets
the container's devices cgroup, and (c) setup_cgroup() during lxc startup
ignores failures to write to devices subsystem if we are already in a
child of the container's new cgroup.

((a) is not really related to this bug, but is definately needed.
The followup work of making the other hooks use the passed-in lxcpath
is still to be done)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agolxcapi_create: fix template handling
Serge Hallyn [Thu, 11 Jul 2013 04:30:29 +0000 (23:30 -0500)]
lxcapi_create: fix template handling

1. If no template is passed in, then do not try to execute it.  The user
just wanted to write the configuration.

2. If template is passed in as a full path, then use that instead of
constructing '$templatedir/lxc-$template'.

Reported-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agolxcapi_create: split out the template execution
Serge Hallyn [Thu, 11 Jul 2013 04:29:20 +0000 (23:29 -0500)]
lxcapi_create: split out the template execution

Make it its own function to make both more readable.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agooracle template: use clonehostname hook script
Dwight Engen [Tue, 9 Jul 2013 18:44:36 +0000 (14:44 -0400)]
oracle template: use clonehostname hook script

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agoadd clonehostname hook
Dwight Engen [Tue, 9 Jul 2013 20:19:45 +0000 (16:19 -0400)]
add clonehostname hook

This hook script updates the hostname in various files under /etc in the
cloned container. In order to do so, the old container name is passed in
the LXC_SRC_NAME environment variable.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agolxc-fedora template - Fix retries, use os-release for release, add utsname.
Michael H. Warfield [Tue, 9 Jul 2013 19:40:38 +0000 (15:40 -0400)]
lxc-fedora template - Fix retries, use os-release for release, add utsname.

Hey all!

Patch for the Fedora template.  Several things...

1) A month or so ago, I floated an idea of adding an option for utsname
which Serge seemed to like but we let it float for more feedback (none
came).

2) In private mail to Serge and Stéphane I mentioned the idea of using
the CPE (Common Platform Enumeration) for host distro and version
identification.  I heard back from Serge but not Stéphane.  CPE is a
standard promoted by NIST and Mitre (along with CVE and CVSS) as part of
the security community as a common identification mechanism.  It's
supported by RedHat based distros and many others (notable exception
Ubuntu).  I've patched the Fedora template to parse first
the /etc/os-release file or, alternatively, the /etc/system-release-cpe
file for the distro ID and version instead of the human
readable /etc/redhat-release.  There's more that can be done with that
in the realm of cross distro container builds, I suspect.

3) At the time of working on 1&2 I noticed that the retry logic in the
Fedora template just didn't seem right.  I believe I posted a message
asking for clarification on that behavior.  A recently post in the
-users list indicating that someone could not create a Fedora 19
container (because the release ver string was 19-2 and the template was
only looking for -1) prompted me to rework the retry logic for handling
the mirror list and servers as well as revamp the download logic to
properly identify the correct release package.

The patch for all of the above is attached below the jump.  It's been
tested on Fedora 17 through Fedora 19 hosts and has created containers
for F11, F12, F13, F14, F16, F17, F18, and F19.  F15 failed for rpm
dependency issues that are not worth fixing (IMHO).

Regards,
Mike
--
Michael H. Warfield (AI4NB) | (770) 985-6132 |  mhw@WittsEnd.com
   /\/\|=mhw=|\/\/          | (678) 463-0932 |  http://www.wittsend.com/mhw/
   NIC whois: MHW9          | An optimist believes we live in the best of all
 PGP Key: 0x674627FF        | possible worlds.  A pessimist is sure of it!

--

Signed-off-by: Michael H. Warfield <mhw@WittsEnd.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agofix potential out of bounds pointer deref
Dwight Engen [Tue, 9 Jul 2013 22:07:26 +0000 (18:07 -0400)]
fix potential out of bounds pointer deref

I noticed that if find_first_wholeword() is called with word at the very
beginning of p, we will deref *(p - 1) to see if it is a word boundary.
Fix by considering p = p0 to be a word boundary.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agoubuntu: Tweak layout of the config
Stéphane Graber [Tue, 9 Jul 2013 22:30:52 +0000 (18:30 -0400)]
ubuntu: Tweak layout of the config

Just add an extra white line to both templates.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
10 years agoubuntu: Fix openssh postinst call in >= saucy
Stéphane Graber [Mon, 8 Jul 2013 17:02:52 +0000 (13:02 -0400)]
ubuntu: Fix openssh postinst call in >= saucy

The new openssh uses a different mechanism to start/stop the daemon
which in turn requires a few tweaks in our template to deal with both
the new and old ways of doing that.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
10 years agolxc-start-ephemeral: Fix console() and add storage option
Stéphane Graber [Mon, 8 Jul 2013 15:01:36 +0000 (11:01 -0400)]
lxc-start-ephemeral: Fix console() and add storage option

The introduction of the new console() python API broke
lxc-start-ephemeral's console(tty=1) call, I now changed that to
console() which does the right thing with both API versions.

This also adds a new storage-type option, letting the user choose to use
a standard directory instead of tmpfs for the container (but still have
it ephemeral).

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
10 years agopython: Update scripts to respect PEP-8 spec
Stéphane Graber [Mon, 8 Jul 2013 14:46:20 +0000 (10:46 -0400)]
python: Update scripts to respect PEP-8 spec

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
10 years agopython: Re-introduce timeout in get_ips
Stéphane Graber [Mon, 8 Jul 2013 14:41:32 +0000 (10:41 -0400)]
python: Re-introduce timeout in get_ips

It turns out that most API users want some kind of timeout option for
get_ips, so instead of re-implementing it in every single client
software, let's just have it as a python overlay upstream.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
10 years agofix sshd template
Dwight Engen [Fri, 5 Jul 2013 16:17:15 +0000 (12:17 -0400)]
fix sshd template

Commit a0a2066d introduced an lxc subdir into the lxc-init path, but
this was never reflected in the sshd template. Add it there.

Don't have ssh-keygen ask for passphrase since host keys are not
supposed to use them.

Don't try to symlink kmsg since /dev is bind mounted readonly.

Read-only bind mount some extra /etc directories, and sysfs which are
needed by dhclient on Fedora and Oracle Linux. Fix mounting of /proc.

Find sshd in more places by adding some common paths to $PATH, and
use the found path to it instead of hardcoded /usr/sbin.

Check for ifconfig command, and print out container's IP address.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agolxcapi_set_cgroup_item: remove duplicate == 0
Bogdan Purcareata [Wed, 3 Jul 2013 16:00:53 +0000 (12:00 -0400)]
lxcapi_set_cgroup_item: remove duplicate == 0

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agoallow lxc-info to get running container configuration
Dwight Engen [Mon, 1 Jul 2013 16:38:23 +0000 (12:38 -0400)]
allow lxc-info to get running container configuration

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agofix -c argument handling
Dwight Engen [Mon, 1 Jul 2013 16:38:15 +0000 (12:38 -0400)]
fix -c argument handling

commit 829dd918 added parsing of a -c argument to both the common options
handling and to lxc-start. It is not a common option, and should have only
been added to lxc-start. Because the common code is processing it, no other
command can use -c. Remove -c from being processed by the common code.
Tested that -c still works with lxc-start.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agolxc_conf_init: make sure strdup succeeded
Serge Hallyn [Mon, 1 Jul 2013 20:32:25 +0000 (15:32 -0500)]
lxc_conf_init: make sure strdup succeeded

unlikely as a failure may be...

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agolxc-alpine: make --release work when apk exists
Natanael Copa [Fri, 28 Jun 2013 14:56:51 +0000 (16:56 +0200)]
lxc-alpine: make --release work when apk exists

Use sed to set the specified alpine release in the copied
/etc/apk/repositories

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agolxc-alpine: option for specifying the release to be installed
Kaarle Ritvanen [Wed, 26 Jun 2013 08:15:00 +0000 (11:15 +0300)]
lxc-alpine: option for specifying the release to be installed

Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agolxc-alpine: automatic repository selection
Kaarle Ritvanen [Wed, 26 Jun 2013 08:14:59 +0000 (11:14 +0300)]
lxc-alpine: automatic repository selection

pick random server from mirror list
use the latest stable release

Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agoAdd -n differentiation to lxc-netstat
Andrew Gilbert [Thu, 27 Jun 2013 13:09:05 +0000 (08:09 -0500)]
Add -n differentiation to lxc-netstat

lxc-netstat now only processes an -n argument if it has not previously
received a value for $name from --name or -n. If it _has_ received such
a value, it stops processing arguments and leaves the -n for netstat.
This does not apply to the use of --name after a name has been provided
by --name or -n; the current behaviour continues. The new behaviour
makes
netstat -n <container> -n -a
behave like
netstat -n <container> -a -n
which already will act as though there is '--' between '<container>' and
'-a' (see line 91 of lxc-netstat.in).

Signed-off-by: Andrew Gilbert <andrewg800@gmail.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agoAdd double-dash to lxc-netstat re-call arguments
Andrew Gilbert [Thu, 27 Jun 2013 13:07:14 +0000 (08:07 -0500)]
Add double-dash to lxc-netstat re-call arguments

When lxc-netstat was called by lxc-unshare, it would be given the
arguments intended for netstat from the first invocation, but without
anything to separate them from the arguments intended for lxc-netstat.
This meant that netstat arguments like -n would result in lxc-netstat
trying to process them.

Signed-off-by: Andrew Gilbert <andrewg800@gmail.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agoapi_clone: don't remove storage if we haven't created it
Serge Hallyn [Fri, 21 Jun 2013 19:16:42 +0000 (14:16 -0500)]
api_clone: don't remove storage if we haven't created it

In the best case we'll get errors about failing to remove it.  In the
worst case we'll be trying to delete the original container's rootfs.

Reported-by: zoolook <nbensa+lxcusers@gmail.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
10 years agoAccept more word delimiters when updating hooks
Serge Hallyn [Fri, 21 Jun 2013 19:15:42 +0000 (14:15 -0500)]
Accept more word delimiters when updating hooks

When updating container names in hook files during a container clone,
we substitute the new container name for the old any time the old name
shows up as a separate word.  This patch adds the four characters
'.,_-' as additional delimiters.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-start-ephemeral: Fix get_ips call
Stéphane Graber [Wed, 19 Jun 2013 18:12:37 +0000 (14:12 -0400)]
lxc-start-ephemeral: Fix get_ips call

The timeout option in get_ips has been deprecated, so work around it.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoconf.c: always strdup rootfs.mount
Serge Hallyn [Tue, 18 Jun 2013 19:52:24 +0000 (14:52 -0500)]
conf.c: always strdup rootfs.mount

The reason is that the generic code which handles reading
lxc.rootfs.mount always frees the old value if not NULL.
So without this setting lxc.rootfs.mount = /mnt causes
segfault.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agodon't set up console for lxc-execute
Serge Hallyn [Thu, 13 Jun 2013 15:06:15 +0000 (10:06 -0500)]
don't set up console for lxc-execute

Currently due to some safety checks for !rootfs.path, lxc-execute works
ok if you do not set lxc.rootfs at all in your lxc.conf. But if you
set lxc.rootfs = '/', then it sets up console, and when you do an
lxc-execute, the console appears hung.

However the lxc.rootfs NULL check was just incidental to not dereference
a NULL pointer.  In fact we should not be setting up a console if the
container isn't running a full-fledged distro with a getty/login
running on the container's /dev/console.

Have lxc_execute() mark in lxc_conf that this is a lxc-execute and not
an lxc-start, and don't set up the console.

The issue is documented at https://sourceforge.net/p/lxc/bugs/67/ .

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
11 years agoconsole API improvements
Dwight Engen [Wed, 12 Jun 2013 15:09:16 +0000 (08:09 -0700)]
console API improvements

Add a higher level console API that opens a tty/console and runs the
mainloop as well. Rename existing API to console_getfd(). Use these in
the python binding.

Allow attaching a console peer after container bootup, including if the
container was launched with -d. This is made possible by allocation of a
"proxy" pty as the peer when the console is attached to.

Improve handling of SIGWINCH, the pty size will be correctly set at the
beginning of a session and future changes when using the lxc_console() API
will be propagated to it as well.

Refactor some common code between lxc_console.c and console.c. The variable
wait4q (renamed to saw_escape) was static, making the mainloop callback not
safe across threads. This wasn't a problem when the callback was in the
non-threaded lxc-console, but now that it is internal to console.c, we have
to take care of it. This is now contained in a per-tty state structure.

Don't attempt to open /dev/null as the console peer since /dev/null cannot
be added to the mainloop (epoll_ctl() fails with EPERM). This isn't needed
to get the console setup (and the log to work) since the case of not having
a peer at console init time has to be handled to allow for attaching to it
later.

Move signalfd libc wrapper/replacement to utils.h.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-init: continue even if we fail to mount /dev/mqueue
Natanael Copa [Wed, 12 Jun 2013 09:18:04 +0000 (11:18 +0200)]
lxc-init: continue even if we fail to mount /dev/mqueue

The 'lxc-init' (a lightweight init process used by lxc-execute in place
of upstart etc) tries to mount /dev/mqueue during startup. If that fails
(for instance due to missing support for mqueue in kernel) then it
aborts execution and returns -1. This is unreasonable as very few
applications actually need /dev/mqueue.

This similar to what we do with /dev/shm.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxclock: move container locks into /run/lock
Serge Hallyn [Wed, 5 Jun 2013 22:37:03 +0000 (17:37 -0500)]
lxclock: move container locks into /run/lock

Currently the lxc API mutexes configuration file read/writes with a
lock called $lxcpath/locks/$lxcname.  This fails if the container
is on a rofs.

This patch moves those locks under /run/lock/lxc.

The $lxcpath/$lxcname/partial file is not moved - if you can't
create it, you probably can't create the container either.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolxc_stop: return success if api_shutdown succeeded
Serge Hallyn [Mon, 10 Jun 2013 16:52:44 +0000 (11:52 -0500)]
lxc_stop: return success if api_shutdown succeeded

I originally forgot to set ret = 0 if it succeeded, meaning that a
simple 'lxc-stop -n container1' returns failure even though the
stop succeeded.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoconf.c: if we don't specify a rootfs, we still need proc mounted
Serge Hallyn [Mon, 10 Jun 2013 14:34:06 +0000 (09:34 -0500)]
conf.c: if we don't specify a rootfs, we still need proc mounted

otherwise we won't be allowed to set an apparmor context (on pid 1)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolxc-execute: allow lxc-init to log only when we have a valid log level
Qiang Huang [Fri, 7 Jun 2013 07:27:32 +0000 (15:27 +0800)]
lxc-execute: allow lxc-init to log only when we have a valid log level

Right now if we use lxc-execute without log level set, we get error:
lxc: invalid log priority NOTSET.
Because we set log level manually in execute_start(), but didn't
check if we have a valid log level or not, so fix it.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-ps: display process when container is frozen
Weng Meiling [Thu, 6 Jun 2013 11:59:31 +0000 (19:59 +0800)]
lxc-ps: display process when container is frozen

When we use lxc-ps to show the process, it's  more appropriate to
show process when container is frozen.

Signed-off-by: Weng Meiling <wengmeiling.weng@huawei.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-monitord: remove hard code execvp path of lxc-monitord
Rui Xiang [Sat, 8 Jun 2013 10:04:47 +0000 (18:04 +0800)]
lxc-monitord: remove hard code execvp path of lxc-monitord

Sometimes, the path of lxc tools is not '/usr/bin', but
'/usr/local/bin' or other. Then execvp lxc-monitord will fail
in lxc_monitord_spawn.

Signed-off-by: Rui Xiang <rui.xiang@huawei.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agofix check for lock acquired
Dwight Engen [Fri, 7 Jun 2013 14:07:36 +0000 (10:07 -0400)]
fix check for lock acquired

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxclock and lxccontainer: switch from flock to fcntl
Serge Hallyn [Wed, 5 Jun 2013 16:56:30 +0000 (11:56 -0500)]
lxclock and lxccontainer: switch from flock to fcntl

flock is not supported on nfs.  fcntl is at least supported on newer
(v3 and above) nfs.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Tested-by: zoolook <nbensa+lxcusers@gmail.com>
11 years agolxc-ps: fix the display problem with arg --lxc
Weng Meiling [Tue, 4 Jun 2013 12:52:27 +0000 (20:52 +0800)]
lxc-ps: fix the display problem with arg --lxc

When we use arg --lxc to show processes in all containers, no
process displays, so fix it.

(Changelog: Serge: in-line fix of s/;;/;/ at line 69)

Signed-off-by: Weng Meiling <wengmeiling.weng@huawei.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoimplement loopback backing store
Serge Hallyn [Sun, 2 Jun 2013 20:39:35 +0000 (15:39 -0500)]
implement loopback backing store

Create a loopfile backed container by doing:

lxc-create -B loop -t template -n name

or

lxc-clone -B loop -o dir1 -n loop1

The rootfs in the configuration file will be

loop:/var/lib/lxc/loop1/rootdev

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc_create: support 'lxc-create -t <template> -h'
Serge Hallyn [Mon, 3 Jun 2013 16:19:01 +0000 (18:19 +0200)]
lxc_create: support 'lxc-create -t <template> -h'

With the lxc-create script, 'lxc-create -t template -h' used to call
'template -h' to get template-specific help.  The api based lxc-create
did not yet support that.

Add a 'helpfn' method to the lxc_arguments, which is called at the end
of printhelp, and passed the lxc_arguments.  Use that in lxc_create to
reintroduce the desired behavior.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-destroy: fix the wrong help info of lxc-destroy
Qiang Huang [Mon, 3 Jun 2013 01:48:14 +0000 (09:48 +0800)]
lxc-destroy: fix the wrong help info of lxc-destroy

Changelog: jun 3: (Serge) trivial typo fix inline.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-create: fix the typo in help info
Qiang Huang [Mon, 3 Jun 2013 01:48:13 +0000 (09:48 +0800)]
lxc-create: fix the typo in help info

Fix typo in help info of lxc-create, and get rid of duplicate
comments in bdev.h

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoarguments: should return negative number when error happens
Qiang Huang [Mon, 3 Jun 2013 01:48:12 +0000 (09:48 +0800)]
arguments: should return negative number when error happens

We should return -ENOMEM instead of ENOMEM when realloc fails.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxcapi_create: don't close stdin/out/err
Serge Hallyn [Mon, 3 Jun 2013 15:47:21 +0000 (10:47 -0500)]
lxcapi_create: don't close stdin/out/err

Otherwise we can't see template progress.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-alpine: download a static package manager if its missing
Natanael Copa [Tue, 28 May 2013 08:25:14 +0000 (10:25 +0200)]
lxc-alpine: download a static package manager if its missing

If the package manager, apk-tools is missing, then:
 - download a static binary and public keys
 - verify the keys against embedded checksum
 - verify the signature of the static binary against the downloaded keys
 - use the verified static binary

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoDefine LXC_DEFAULT_CONFIG
Serge Hallyn [Fri, 31 May 2013 14:09:14 +0000 (16:09 +0200)]
Define LXC_DEFAULT_CONFIG

And use it in place of the various ways we were deducing /etc/lxc/default.conf.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoconfigure/makefile: rename default_conf to distro_conf
Serge Hallyn [Fri, 31 May 2013 14:02:33 +0000 (16:02 +0200)]
configure/makefile: rename default_conf to distro_conf

configure/makefile: rename default_conf to distro_conf, since it is a per-distro
default.  Then we'll be able to use the symbol LXC_DEFAULT_CONF in the code to
refer to the installed file.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolxccontainer: update locking comment
Serge Hallyn [Fri, 31 May 2013 12:55:14 +0000 (07:55 -0500)]
lxccontainer: update locking comment

Update the LOCKING comment.

Take mem_lock in want_daemonize.

convert lxcapi_destroy to not use privlock/slock by hand.

Fix a coverity-found potential dereference of NULL c->lxc_conf.

api_cgroup_get_item() and api_cgroup_set_item(): use disklock,
not memlock, since the values are set through the cgroup fs on
the running container.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agowaitpid at abort to make sure we can rmdir cgroups
Serge Hallyn [Thu, 30 May 2013 16:22:16 +0000 (11:22 -0500)]
waitpid at abort to make sure we can rmdir cgroups

If we abort the container start, and don't wait for the init task to be
reaped after we kill it, then we can't remove the container cgroup
because it is not empty.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxccontainer: don't lock around getstate and freeze/unfreeze (v2)
Serge Hallyn [Wed, 29 May 2013 17:26:25 +0000 (12:26 -0500)]
lxccontainer: don't lock around getstate and freeze/unfreeze (v2)

Those go through commands.c and are already mutex'ed that way.

Also remove a unmatched container_disk_unlock in lxcapi_create.

Since is_stopped uses getstate which is no longer locked, rename
it to drop the _locked suffix.

And convert save_config to taking the disk lock.  This way the
save_ and load_config are mutexing each other, as they should.

Changelog: May 29:
   Per Dwight's comment, take the lock before opening the config
      FILE *.
   Only take disklock at load and save_config when we're using the
   container's config file, not when read/writing from/to another
   file.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
11 years agoadd console to lxc api
Dwight Engen [Tue, 28 May 2013 19:25:41 +0000 (15:25 -0400)]
add console to lxc api

Make lxc_cmd_console() return the fd from the socket connection to the
caller. This fd keeps the tty slot allocated until the caller closes
it. Returning the fd allows for a long lived process to close the fd
and reuse consoles.

Add API function for console allocation.

Create test program for console API.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-console: use fd instead of 0 in setup_tios
Qiang Huang [Mon, 27 May 2013 11:10:38 +0000 (19:10 +0800)]
lxc-console: use fd instead of 0 in setup_tios

We should use the fd specified by caller.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc.spec.in: remove lxc-shutdown (for commit 3e625e2d)
Dwight Engen [Tue, 28 May 2013 19:18:22 +0000 (15:18 -0400)]
lxc.spec.in: remove lxc-shutdown (for commit 3e625e2d)

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoapi_clone: call is_stopped_locked() to avoid deadlock.
Serge Hallyn [Tue, 28 May 2013 20:27:42 +0000 (15:27 -0500)]
api_clone: call is_stopped_locked() to avoid deadlock.

Technically as Dwight has mentioned we should probably drop the locking
from api_state() altogether, since those are protected through the
lxc command system.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc.conf.sgml.in: fill in missing configuration file statements
Serge Hallyn [Tue, 28 May 2013 19:07:43 +0000 (14:07 -0500)]
lxc.conf.sgml.in: fill in missing configuration file statements

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoMove container creation fully into the api
Serge Hallyn [Fri, 17 May 2013 21:23:17 +0000 (23:23 +0200)]
Move container creation fully into the api

1. implement bdev->create:

python and lua: send NULL for bdevtype and bdevspecs.
They'll want to be updated to pass those in in a way that makes
sense, but I can't think about that right now.

2. templates: pass --rootfs

If the container is backed by a device which must be mounted (i.e.
lvm) then pass the actual rootfs mount destination to the
templates.

Note that the lxc.rootfs can be a mounted block device.  The template
should actually be installing the rootfs under the path where the
lxc.rootfs is *mounted*.

Still, some people like to run templates by hand and assume purely
directory backed containers, so continue to support that use case
(i.e. if no --rootfs is listed).

Make sure the templates don't re-write lxc.rootfs if it is
already in the config.  (Most were already checking for that)

3. Replace lxc-create script with lxc_create.c program.

Changelog:
May 24: when creating a container, create $lxcpath/$name/partial,
and flock it.  When done, close that file and unlink it.  In
lxc_container_new() and lxcapi_start(), check for this file.  If
it is locked, create is ongoing.  If it exists but is not locked,
create() was killed - remove the container.

May 24: dont disk-lock during lxcapi_create.  The partial lock
is sufficient.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agodestroy: implement in the api
Serge Hallyn [Fri, 17 May 2013 05:20:10 +0000 (07:20 +0200)]
destroy: implement in the api

This requires implementing bdev->ops->destroy() for each of the backing
store types.  Then implementing lxcapi_clone(), writing lxc_destroy.c
using the api, and removing the lxc-destroy.in script.

(this also has a few other cleanups, like marking some functions
static)

Changelog:
fold into destroy: fix zfs destroy
destroy: use correct program name in help

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-stop: use api, remove lxc_shutdown, extend lxc-stop functionality
Serge Hallyn [Thu, 16 May 2013 21:03:47 +0000 (23:03 +0200)]
lxc-stop: use api, remove lxc_shutdown, extend lxc-stop functionality

implement c->reboot(c) in the api.

Also if the container is not running, return -2.  Currently
lxc-stop will return 0, so you cannot tell the difference
between successfull stopping and noop.

Per stgraber's email:

 - Remove lxc-shutdown
 - Change lxc-stop so that:
   * Default behaviour is to call shutdown(), wait 15s for STOPPED, if
not STOPPED, print a message to the user and call stop() [ NOTE:
actually 60 seconds per followup thread]
   * We have a -r option to reboot the container (with proper check that
the container indeed rebooted within the next 15s)
   * We have a -s option to shutdown the container without the automatic
fallback to stop()
   * Add a -k option allowing a user to just kill a container
(equivalent to old lxc-stop, no shutdown() call and no delay).

and update manpages.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolocking: update per Dwight's comment
Serge Hallyn [Fri, 24 May 2013 21:03:22 +0000 (16:03 -0500)]
locking: update per Dwight's comment

Create three pairs of functions:
int process_lock(void);
void process_unlock(void);
int container_mem_lock(struct lxc_container *c)
void container_mem_unlock(struct lxc_container *c)
int container_disk_lock(struct lxc_container *c);
void container_disk_unlock(struct lxc_container *c);

and use those in lxccontainer.c

process_lock() is to protect the process state among multiple threads.
container_mem_lock() is to protect a struct container among multiple
threads.  container_disk_lock is to protect a container on disk.

Also remove the lock in lxcapi_init_pid() as Dwight suggested.

Fix a typo (s/container/contain) spotted by Dwight.

More locking fixes are needed, but let's first the the fundamentals
right.  How close does this get us?

Changelog: v2:
fix lxclock compile

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
11 years agolxclock: Replace named sempahore with flock
Serge Hallyn [Wed, 22 May 2013 21:24:00 +0000 (16:24 -0500)]
lxclock: Replace named sempahore with flock

The problem: if a task is killed while holding a posix semaphore,
there appears to be no way to have the semaphore be reliably
autmoatically released.  The only trick which seemed promising
is to store the pid of the lock holder in some file and have
later lock seekers check whether that task has died.

Instead of going down that route, this patch switches from a
named posix semaphore to flock.  The advantage is that when
the task is killed, its fds are closed and locks are automatically
released.

The disadvantage of flock is that we can't rely on it to exclude
threads.  Therefore c->slock must now always be wrapped inside
c->privlock.

This patch survived basic testing with the lxcapi_create patchset,
where now killing lxc-create while it was holding the lock did
not lock up future api commands.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agofix memory leaks in cgroup functions
Dwight Engen [Thu, 23 May 2013 19:44:39 +0000 (15:44 -0400)]
fix memory leaks in cgroup functions

There were several memory leaks in the cgroup functions, notably in the
success cases.

The cgpath test program was refactored and additional tests added to it.
It was used in various modes under valgrind to test that the leaks were
fixed.

Simplify lxc_cgroup_path_get() and cgroup_path_get by having them return a
char * instead of an int and an output char * argument. The only return
values ever used were -1 and 0, which are now handled with NULL and non-NULL
returns respectively.

Use consistent variable names of cgabspath when refering to an absolute path
to a cgroup subsystem or file, and cgrelpath when refering to a container
"group/name" within the cgroup heirarchy.

Remove unused subsystem argument to lxc_cmd_get_cgroup_path().

Remove unused #define MAXPRIOLEN

Make template arg to lxcapi_create() const

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoconsolidate missing C library functions into utils.h
Dwight Engen [Thu, 23 May 2013 19:39:03 +0000 (15:39 -0400)]
consolidate missing C library functions into utils.h

This fixes the build of lxccontainer.c on systems that have __NR_setns
but not HAVE_SETNS.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agopython: Fix lxc-ls's usage of get_ips()
Stéphane Graber [Thu, 23 May 2013 02:28:43 +0000 (22:28 -0400)]
python: Fix lxc-ls's usage of get_ips()

The recent port of get_ips() from pure python to the C API came with
a couple of API changes for that function call (as were highlighted in
the commit message).

I somehow didn't notice that lxc-ls was still calling with the old API
and so was crashing whenever it was asked to show the ipv4 or ipv6 address.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agolxc-fedora template. Cleanup for rootfs.
Michael H. Warfield [Tue, 21 May 2013 18:17:25 +0000 (14:17 -0400)]
lxc-fedora template. Cleanup for rootfs.

This is just some minor changes in the way the Fedora template is
synthesizing the target rootfs_path.  Currently, the template uses a
path with the container in it twice like this:

/var/lib/lxc/rasputin/rasputin/rootfs

This happens because the container name is already contained in the
"path" and the template appends it a second time.  This changes the
logic to be congruent with other templates such as lxc-arch.  The new
behavior will be to create the rootfs like this:

/var/lib/lxc/rasputin/rootfs

Attached below the jump.

Regards,
Mike
--
Michael H. Warfield (AI4NB) | (770) 985-6132 |  mhw@WittsEnd.com
   /\/\|=mhw=|\/\/          | (678) 463-0932 |  http://www.wittsend.com/mhw/
   NIC whois: MHW9          | An optimist believes we live in the best of all
 PGP Key: 0x674627FF        | possible worlds.  A pessimist is sure of it!
--

Signed-off-by: Michael H. Warfield <mhw@WittsEnd.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agooracle template: mount /dev/shm as tmpfs
Dwight Engen [Tue, 21 May 2013 15:34:45 +0000 (11:34 -0400)]
oracle template: mount /dev/shm as tmpfs

sem_open(3) checks that /dev/shm is SHMFS_SUPER_MAGIC. Normally /dev/shm
is mounted in the initramfs created by dracut, but that won't be run for
a container so make sure that rc.sysinit mounts /dev/shm.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agofix build with --enable-tests
Dwight Engen [Tue, 21 May 2013 17:30:09 +0000 (13:30 -0400)]
fix build with --enable-tests

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoattach: and cgroup.c: be overly cautious
Serge Hallyn [Wed, 22 May 2013 01:31:04 +0000 (20:31 -0500)]
attach: and cgroup.c: be overly cautious

Realistically (as Dwight points out) it doesn't seem possible that
getline won't return at least one line in this functions, however
just to make absolutely sure we don't get a segv on free(NULL),
check line != NULL before freeing it on exit.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agofix getline(3) memory leaks
Dwight Engen [Tue, 21 May 2013 19:36:32 +0000 (15:36 -0400)]
fix getline(3) memory leaks

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agofix minor gcc 4.7.2 error
Dwight Engen [Tue, 21 May 2013 17:15:53 +0000 (13:15 -0400)]
fix minor gcc 4.7.2 error

lxccontainer.c:874:4: error: ‘for’ loop initial declarations are only
allowed in C99 mode

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agoextend command processor to handle generic data
Dwight Engen [Fri, 17 May 2013 22:29:12 +0000 (18:29 -0400)]
extend command processor to handle generic data

Motivation for this change is to have the ability to get the run-time
configuration items from a container, which may differ from its current
on disk configuration, or might not be available any other way (for
example lxc.network.0.veth.pair). In adding this ability it seemed there
was room for refactoring improvements.

Genericize the command infrastructure so that both command requests and
responses can have arbitrary data. Consolidate all commands into command.c
and name them consistently. This allows all the callback routines to be
made static, reducing exposure.

Return the actual allocated tty for the console command. Don't print the
init pid in lxc_info if the container isn't actually running. Command
processing was made more thread safe by removing the static buffer from
receive_answer(). Refactored command response code to a common routine.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxcapi: Add new get_ips() call
Stéphane Graber [Fri, 26 Apr 2013 14:01:58 +0000 (16:01 +0200)]
lxcapi: Add new get_ips() call

This adds a new get_ips call which takes a family (inet, inet6 or NULL),
a network interface (or NULL for all) and a scope (0 for global) and returns
a char** of all the IPs in the container.

This also adds a matching python3 binding (function result is a tuple) and
deprecates the previous pure-python get_ips() implementation.

WARNING: The python get_ips() call is quite different from the previous
implementation. The timeout argument has been removed, the family names are
slightly different (inet/inet6 vs ipv4/ipv6) and an extra scope parameter
has been added.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
11 years agoImplement simple utility functions for reading and writing to fds
Christian Seiler [Mon, 20 May 2013 15:54:23 +0000 (17:54 +0200)]
Implement simple utility functions for reading and writing to fds

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoMove declarations of some constants to where they are needed.
Christian Seiler [Mon, 20 May 2013 15:54:22 +0000 (17:54 +0200)]
Move declarations of some constants to where they are needed.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoutils.c: Add lxc_wait_for_pid_status routine that returns exit code
Christian Seiler [Mon, 20 May 2013 15:54:21 +0000 (17:54 +0200)]
utils.c: Add lxc_wait_for_pid_status routine that returns exit code

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agowait_for_pid: Fix EINTR check
Christian Seiler [Mon, 20 May 2013 15:54:20 +0000 (17:54 +0200)]
wait_for_pid: Fix EINTR check

Signed-off-by: Christian Seiler <christian@iwakd.de>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-fedora template - systemd console gettys
Michael H. Warfield [Mon, 20 May 2013 16:04:38 +0000 (12:04 -0400)]
lxc-fedora template - systemd console gettys

Hey all...

Patch to the lxc-fedora template to setup gettys on the ttys that are
enabled in the configuration.  The area of the code already had some
modifications to that service that didn't seem to do anything and would
get wiped out by an update.  I commented that out but subsumed the
change it was attempting into my command in case it does something on
another rev somewhere.

This is very similar to the logic in the OpenSuse template but doesn't
seem to appear in other templates, such as arch, which have to deal with
systemd.  This isn't unique to Fedora.  The templates for Fedora,
ArchLinux, and OpenSuse are the only three that seem to have any
reference to systemd at all.

Attached below the jump.

Regards,
Mike
--
Michael H. Warfield (AI4NB) | (770) 985-6132 |  mhw@WittsEnd.com
   /\/\|=mhw=|\/\/          | (678) 463-0932 |  http://www.wittsend.com/mhw/
   NIC whois: MHW9          | An optimist believes we live in the best of all
 PGP Key: 0x674627FF        | possible worlds.  A pessimist is sure of it!
--

Signed-off-by: Michael H. Warfield <mhw@WittsEnd.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoreturn lxc generated name for veth pair
Dwight Engen [Fri, 17 May 2013 22:28:12 +0000 (18:28 -0400)]
return lxc generated name for veth pair

Doing a get_config_item for lxc.network.0.veth.pair only returns the
pair name if explicitly given, but it can be useful to know the name
even if it is the one that lxc autogenerated.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoquiet gcc 4.4.7 warning about saveptr use before initialization
Dwight Engen [Fri, 17 May 2013 21:40:12 +0000 (17:40 -0400)]
quiet gcc 4.4.7 warning about saveptr use before initialization

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc-create: zfs: consistently use zfsroot, not zfs_root
Serge Hallyn [Fri, 17 May 2013 16:25:15 +0000 (11:25 -0500)]
lxc-create: zfs: consistently use zfsroot, not zfs_root

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agodocument clone hooks
Serge Hallyn [Thu, 16 May 2013 13:22:41 +0000 (08:22 -0500)]
document clone hooks

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agolxc: add clone hook.
Serge Hallyn [Tue, 14 May 2013 21:10:37 +0000 (16:10 -0500)]
lxc: add clone hook.

Add a clone hook called from api_clone.  Pass arguments to it from
lxc_clone.c.

The clone update hook is called while the container's bdev is mounted.
Information about the container is passed in through environment
variables LXC_ROOTFS_PATH, LXC_NAME, The LXC_ROOTFS_MOUNT, and
LXC_CONFIG_FILE.

LXC_ROOTFS_MOUNT=/usr/lib/x86_64-linux-gnu/lxc
LXC_CONFIG_FILE=/var/lib/lxc/demo3/config
LXC_ROOTFS_PATH=/var/lib/lxc/demo3/rootfs
LXC_NAME=demo3

So from the hook, updates to the container should be made under
$LXC_ROOTFS_MOUNT/ .

The hook also receives command line arguments as follows:
First argument is container name, second is always 'lxc', third
is the hook name (always clone), then come the arguments which
were passed to lxc-clone.  I.e. when I did:

sudo lxc-clone demo2 demo3 -- hey there dude

the arguments passed in were "demo3 lxc clone hey there dude"

I personally would like to drop the first two arguments.  The
name is available as $LXC_NAME, and the section argument ('lxc')
is meaningless.  However, doing so risks invalidating existing
hooks.

Soon analogous create and destroy hooks will be added as well.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
11 years agocgroup: prevent DOS when a hierachy is mounted multiple times
Serge Hallyn [Wed, 15 May 2013 20:21:24 +0000 (15:21 -0500)]
cgroup: prevent DOS when a hierachy is mounted multiple times

When starting a container, we walk through all cgroup mounts looking
for a unique directory name we can use for this container.  If the
name we are trying is in use, we try another name.  If it is not in
use in the first mount we check, we need to check other hierarchies
as it may exist there.  But we weren't checking whether we have already
checked a subsystem - so that if freezer was mounted twice, we would
create it in the first mount, see it exists in the second, so start
over trying in the second mount.

To fix this, keep track of which subsystems we have already checked,
and do not re-check.

(See http://pad.lv/1176287 for a bug report)

Note we still need to add, at the next: label, the removal of the
directories we've already created.  I'm keeping that for later as
it's far lower priority than this fix, and I don't want to risk
introducing a regression for that.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agoset non device cgroup items before the cgroup is entered
Dwight Engen [Wed, 15 May 2013 16:27:34 +0000 (12:27 -0400)]
set non device cgroup items before the cgroup is entered

This allows some special cgroup items such as memory.kmem.limit_in_bytes
to be successfully set, since they must be set before any task is put
into the cgroup.

The devices cgroup is setup later giving the container a chance to mount
file systems before the device it might want to mount from becomes
unavailable.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
11 years agodoc/lxc.conf minor clarifications
Dwight Engen [Wed, 15 May 2013 17:23:12 +0000 (13:23 -0400)]
doc/lxc.conf minor clarifications

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>