Commit Graph

529 Commits

Author SHA1 Message Date
Michel Normand
96819f4d77 lxc-create to run even if not in PATH
Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-21 14:34:08 +01:00
Michel Normand
3bc15639eb avoid too long line in lxc-busybox.in
Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-21 14:34:08 +01:00
Michel Normand
4357db9a06 add --define to restart V2
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-21 14:34:08 +01:00
Michel Normand
b75afd9089 lxc: typo in scripts/lxc-debian.in
warning with git am, white before tab correction

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-20 11:09:56 +01:00
Greg Kurz
b24319395b lxc: remove useless check
The handler argument to lxc_fini() is never null.

Signed-off-by: Greg Kurz <gkurz@fr.ibm.com>
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-20 11:09:56 +01:00
Greg Kurz
b79fcd8638 lxc: fix double-close in lxc_[re]spawn() abort path
sv[0] has already been closed when reaching out_abort label.

Signed-off-by: Greg Kurz <gkurz@fr.ibm.com>
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-20 11:09:56 +01:00
Michel Normand
8b7329af3f lxc: add capabilities for C/R
Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-20 11:09:56 +01:00
Clement Calmels
c3e13372aa Remove useless lines
Signed-off-by: Clement Calmels <clement.calmels@fr.ibm.com>
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-20 11:09:56 +01:00
Greg Kurz
9d7f9e522b lxc: some goto clarification
It makes sense to use goto when there's some rollback work to be done.
And it's nice for code clarity to add an explicit suffix to goto labels.

Signed-off-by: Greg Kurz <gkurz@fr.ibm.com>
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-20 11:09:56 +01:00
Michel Normand
79e6830922 lxc: typo white space src/lxc/network.c
Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-20 11:09:56 +01:00
Taisuke Yamada
84a24de235 Added -e to lxc-console to change command character (defaults to '^a')
I noticed lxc-console uses '^a' as command-mode prefix to
escape out of console session, so created a patch to make it
configurable. With this, you can do

  lxc-console -n foo -e ^t

and exit the session with 'Ctrl+t q'.

For emacs-binding addicts (like me), it's always nice to
let shell handle '^a' as 'beginning-of-line' command...

Signed-off-by: Taisuke Yamada <tai@rakugaki.org>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-18 23:08:12 +01:00
Clement Calmels
5fa5aa7c6a remove warning in parse.c:80
Signed-off-by: Clement Calmels <clement.calmels@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-18 23:08:12 +01:00
Clement Calmels
2382ecffdb use getline instead of fgets
The getline function allocate the needed memory. Fix buffer can lead
to 'hard to find' bug. I don't test the pivot_root part but the other
parts are ok.

Signed-off-by: Clement Calmels <clement.calmels@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-18 23:08:12 +01:00
Clement Calmels
8eec72f75d free struct dirent **namelist
Correct the way the struct dirent **namelist structure is freed.

Signed-off-by: Clement Calmels <clement.calmels@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-18 23:08:12 +01:00
Daniel Lezcano
226a18d671 fix compilation warning
lxc_config_define_load should an int

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-14 07:43:18 +01:00
Cedric Le Goater
33ba4ad795 lxc: add --define to start
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-14 07:43:18 +01:00
Cedric Le Goater
a31b2048d9 add --define to restart
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-14 07:43:18 +01:00
Cedric Le Goater
201172806c add --define to execute
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-14 07:43:18 +01:00
Cedric Le Goater
62e4603548 add interface to assign configuration variable from the command line
lxc_config_define_add() and lxc_config_define_load() define
the interface to load a list of KEY=VAL buffers in the configuration

Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-14 07:43:17 +01:00
Daniel Lezcano
222dcd5443 remove unused variable
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-13 18:51:16 +01:00
Cedric Le Goater
af5b01558c export lxc_config_readline()
lxc_config_readline() will be used to parse configuration variable
assigned from the command line with --define

Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-13 18:51:16 +01:00
Clement Calmels
d066f3b8e2 Simplify mainloop
Just use a list instead of array for dynamically allocated stuff. It's
more appropriated.

Signed-off-by: Clement Calmels <clement.calmels@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-13 18:51:16 +01:00
Clement Calmels
5df6b18f0e Don't mess descr->ev
A simple test program to show up the issue:

-8<---
#include <stdio.h>
#include <unistd.h>

#include "mainloop.h"

struct lxc_epoll_descr loop;

int cb1(int fd, void *data, struct lxc_epoll_descr *descr)
{
	fprintf(stderr, "cb1\n");
        return 1;
}

int cb2(int fd, void *data, struct lxc_epoll_descr *descr)
{
	fprintf(stderr, "cb2\n");
        return 1;
}

int main(int argc, char *argv[])
{
        int ret;
        int fds[2];

        ret = pipe(fds);
        if (ret) {
                perror("pipe:");
                return -1;
        }

        ret = lxc_mainloop_open(&loop);
        if (ret) {
                fprintf(stderr, "lxc_mainloop_open: %d\n", ret);
                return -1;
        }

        ret = lxc_mainloop_add_handler(&loop, fds[1], cb1, NULL);
        if (ret) {
                fprintf(stderr, "lxc_mainloop_add_handler(fds[1]): %d\n", ret);
                return -1;
        }

        ret = lxc_mainloop_add_handler(&loop, fds[0], cb2, NULL);
        if (ret) {
                fprintf(stderr, "lxc_mainloop_add_handler(fds[0]): %d\n", ret);
                return -1;
        }

        write(fds[1], &ret, sizeof(ret));

        ret = lxc_mainloop(&loop);
        if (ret) {
	        fprintf(stderr, "lxc_mainloop: %d\n", ret);
				return -1;
        }

        ret = lxc_mainloop_close(&loop);
        if (ret) {
                fprintf(stderr, "lxc_mainloop_close: %d\n", ret);
                return -1;
        }

        return 0;
}

Compile and run:
$ gcc test.c -o test -I ./src/lxc/ ./src/lxc/liblxc_so-mainloop.o && ./test
cb2
2010-01-13 18:51:16 +01:00
Clement Calmels
3ce45e6458 If epoll_ctl fails, the descr->ev array isinconsistent
Let's take an example:

fd = open(..) /* fd = 3 for example */

lxc_mainloop_add_handler(descr, fd, cb1, data1) fails.

the program take care of the error, it closes the fd

Later, reopen a fd (get 3 for again)

lxc_mainloop_add_handler(desc, fd, cb2, data2) is ok.

When something happen on fd, cb1 with data1 will be called instead of
cb2 with data2, because descr->ev contains 2 entries for fd == 3.

Signed-off-by: Clement Calmels <clement.calmels@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-13 18:51:16 +01:00
Clement Calmels
312b3ca262 fix lxc_mainloop_del_handler
Fix bad index.

Signed-off-by: Clement Calmels <clement.calmels@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-13 18:51:16 +01:00
Cedric Le Goater
7707565969 use different log categories in commands
lxc_<cmd>.c and <cmd>.c files use the same log category : lxc_<cmd>.
The symbol is multiply defined and linking statically lxc commands is
not possible.

The patch introduces new log categories with a '_ui' suffix to
differentiate the command line interface from the library routine.

Reported-by: Ciprian Dorin, Craciun <ciprian.craciun@gmail.com>
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-13 18:51:15 +01:00
Cedric Le Goater
7a7ff0c6fb fix lxc_file_cb prototype
Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-13 18:51:15 +01:00
Daniel Lezcano
f079d569fc fix bad docbook syntax in lxc-create.sgml.in
Removed extra </command>.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-08 15:19:20 +01:00
Michael Holzt
9acc339a38 fix misleading error message in lxc_create
When the configuration path does not exist, lxc_create misleadingly
tells that it was not set.

Signed-off-by: Michael Holzt <lxc@my.fqdn.org>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-08 15:19:20 +01:00
Michael Holzt
2b3d393b42 Update .gitignore
lxc.pc and scripts/lxc-busybox are missing from .gitignore

Signed-off-by: Michael Holzt <lxc@my.fqdn.org>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-08 15:19:20 +01:00
Michael Holzt
c553a9c22e Rename doc/examples/lxc-complex-config.in to lxc-complex.conf.in
Rename doc/examples/lxc-complex-config.in to lxc-complex.conf.in as all other
examples in this directory have a .conf ending as well.

Signed-off-by: Michael Holzt <lxc@my.fqdn.org>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-08 15:19:20 +01:00
Daniel Lezcano
932b94f5de Remove dead code
Remove dead code.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-08 15:19:19 +01:00
Michael Holtz
bf601689a9 use pivot_root instead of chroot
lxc currently does a chroot into the target rootfs. chroot is insecure and
can easily be broken, as demonstrated here:

| root@synergy:~# touch /this_is_the_realrootfs_ouch
| # touch /container/webhost/this_is_the_container
| # lxc-start -n webhost /bin/sh
| # ls this*
| this_is_the_container
| # ./breakchroot
| # ls this*
| this_is_the_realrootfs_ouch

code to break chroot taken from
http://www.bpfh.net/simes/computing/chroot-break.html

Now this can be fixed. As our container has his own mount namespace, we can
easily pivot_root into the rootfs and then unmount all old mounts. The patch
attached add a new config keyword which contains the path to a temporary
mount for the old rootfs (inside the container). This stops the chroot break
method shown before. 

Example:

| root@synergy:~# grep pivotdir /var/lib/lxc/webhost/config
| lxc.pivotdir = /oldrootfs
| root@synergy:~# ls -lad /container/webhost/oldrootfs
| drwxr-xr-x 2 root root 4096 2010-01-02 03:59 /container/webhost/oldrootfs
| root@synergy:~# lxc-start -n webhost /bin/sh
| # mount -t proc proc /proc
| # cat /proc/mounts
| rootfs / rootfs rw 0 0
| /dev/root / ext3 rw,relatime,errors=remount-ro,data=writeback 0 0
| devpts /dev/console devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0
| proc /proc proc rw,relatime 0 0
| # ls this*   
| this_is_the_container
| # ./breakchroot
| # ls this*
| this_is_the_container

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Signed-off-by: Michael Holtz <lxc@my.fqdn.org>
2010-01-08 14:34:13 +01:00
Michel Normand
7b379ab3a5 lxc: avoid memory corruption on ppc and s390 V4
conf object is on stack and is used in forked process.

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-08 14:34:13 +01:00
Michel Normand
4eec6850fc lxc_cgroup_set not reporting error
this is a side effect of previous patch I made
on this same function in commit
a6ddef6149

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-08 14:34:13 +01:00
Michel Normand
0bb4f8cf3b lxc: update man and help of lxc-create
few added lines to document the new lxc-create -t option

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-08 14:34:13 +01:00
Paul Fee
23a92fad75 fix manpage typo
Fix and clarify some parts of the lxc.conf man page.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-01-05 13:11:27 +01:00
Daniel Lezcano
e892973e39 add macvlan vepa and bridge mode
The future kernel 2.6.33 will incorporate the macvlan bridge
mode where all the macvlan will be able to communicate if they are
using the same physical interface. This is an interesting feature
to have containers to communicate together. If we are outside of the
container, we have to setup a macvlan on the same physical interface than
the containers and use it to communicate with them.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-28 22:10:11 +01:00
Daniel Lezcano
eb960fea58 busybox template
This script builds a busybox rootfs and provides the associated
configuration to run the busybox.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-27 22:36:09 +01:00
Daniel Lezcano
418c73ad12 adapt lxc-sshd to be a template
Cleanup the script, simplify it and pass the arguments to this
script to be callable by lxc-create template logic.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-27 22:36:09 +01:00
Daniel Lezcano
1b6d8e7197 add template option for lxc-create
The lxc-create command is now able to call a sub script to install
a mini template.
Right now, debian is supported.

The rootfs is stored automatically in <lxcpath>/<name>/rootfs
So the rootfs is a subdirectory of the container configuration directory.

When lxc-destroy is called, the rootfs is deleted with the container
configuration.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-27 22:36:09 +01:00
Daniel Lezcano
fb7460fe60 cleanup lxc-debian script
The lxc-debian is epurated and consolidated with a better
error handling.

This script is no longer interactive but it installs in a specified
place the debian rootfs.

This script is not supposed to be called directly so it will fall in
libexec path very soon. This script is called by lxc-create
as a template with the right option and the right place.

The debian network configuration is by dhcp.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-27 22:36:09 +01:00
Daniel Lezcano
1d6b1976a0 fix mount entry typo
Added missing carriage-return when adding a new entry.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-18 14:19:59 +01:00
Jamal Hadi Salim
f6cc1de1a9 Introduce per netdev priv structure
Some devices like veth or vlans have a bit of extra details that
are specific to them. Example veth.pair and vlan.vlanid.
Separate them from the common so we can update cleanly in the future.
    
Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Acked-by: Daniel Lezcano <daniel.lezcano@free.fr>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-15 10:14:27 +01:00
Jamal Hadi Salim
26c390288b Add VLAN support in config
This adds ability to migrate vlan interfaces into namespaces
by specifying them in a config
    
Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Acked-by: Daniel Lezcano <daniel.lezcano@free.fr>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-15 10:14:27 +01:00
Jamal Hadi Salim
9ddaf3bf1c Add utility u16 get/put
Add utility functions to parse a u16 and put a u16 on a
netlink message
    
Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Acked-by: Daniel Lezcano <daniel.lezcano@free.fr>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-12-15 10:14:26 +01:00
Daniel Lezcano
108ed092c3 fix a compilation warning
lxc_get_cgroup_path is used in the file but the header
defining the function is missing.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-26 16:46:25 +01:00
Andrian Nord
f2ae79a045 "Default" configuration may destroy host system
If you're running (by mistake or typo) (via lxc-start) container that does not
exists it will run with lxc.rootfs=/, meaning that /sbin/init will
restart initialization procedure, efficiently messing host's system,
that may lead to unpredictable results or even destroy (make inaccessible) host
system (by reseting network configuration or something like that).

(Actually, it _did_ destroy system of everyone who tested this).

Actually, I finally lost any meaning of having such a feature for
full-system containers. You may not use hosts's FS - it's described at
above. You may not use some temporary directory - that's nonsense.

This patch forbinds starting container via lxc-start without rcfile and
custom start program, but probably it fixes only small part of problem.
I really don't see much sense in such a feature without ability of
overriding 'default' setting with command line switches. Anyway, default
behaviour should be as save as possible.

Signed-off-by: Andrian Nord <NightNord@gmail.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-26 16:46:25 +01:00
Daniel Lezcano
fae349da89 pass lxc_conf to the lxc_start function instead of the rcfile
The rcfile is parsed in the lxc_start function. This is not the place
to do that. Let's the caller to do that.

In the meantime, we have the lxc_conf structure filled right before
calling the lxc_start function so we can do some sanity check on the
configuration to not break the system when we launch the container.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-26 16:46:24 +01:00
Jamal Hadi Salim
aedd9d3fb3 Remove unnecessary reset of msg.msg_controlle
Remove unnecessary reset of msg.msg_controllen
    
Signed-off-by: Jamal Hadi Salim <hadi@cyberus.ca>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-26 16:46:24 +01:00