Commit Graph

91 Commits

Author SHA1 Message Date
Serge Hallyn
964fe051e9 Clear environment for container
Clear env before starting a container.  Do it right before setting
the container=lxc variable.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-12-22 11:34:28 +01:00
Stéphane Graber
f79d43bbe7 Remove all trailing whitespaces.
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-26 12:08:13 -05:00
Stéphane Graber
c3752c0b59 Use clearer error message on failure to create pidfile
As suggested by Serge Hallyn on lxc-devel.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-15 10:51:09 -05:00
Natanael Copa
3114c98242 lxc-start: add option -p, --pidfile=FILE
Add option to create a pidfile for lxc-start. This is helpful for
init scripts and process monitors when running as daemon.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2012-11-15 10:50:56 -05:00
Serge Hallyn
b4df0a1eda lxc_start: exit early if insufficient privs in daemon mode
Starting a container with insufficient privilege (correctly) fails
during lxc_init.  However, if starting a daemonized container, we
daemonize before we get to that check.  Therefore while the
container will fail to start, and the logfile will show this, the
'lxc-start -n x -d' command will return success.  For ease of
scripting, do a check for the required privilege before we exit.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2012-10-25 10:07:30 +02:00
Serge Hallyn
b119f36293 add option to close inherited fds
The option is implied by '-d', because the admin won't see the warning
message.

Signed-off-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2012-02-26 10:44:41 +01:00
Daniel Lezcano
829dd9183c lxc-start can output the console to a file
Add the ability to specify a file to output the console.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2011-02-01 14:49:40 +01:00
Daniel Lezcano
3244e75040 export env variable in lxc_start
Let's export the 'container' variable and let init receive it
as a kernel command line option.

In the upstart init scripts, we can distinguish if we are in a
container context or not.

===============================================================================

# /dev/console - getty
#
# This service maintains a getty on /dev/console from the point the
# system is started until it is shut down again.
# It only runs in lxc containers.

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

env container
pre-start script
	[ "x$container" != "xlxc" ] && { stop; exit 0; }
	exit 0;
end script

respawn

exec /sbin/getty -8 38400 /dev/console

===============================================================================

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2011-01-28 00:14:51 +01:00
Daniel Lezcano
0ed9cc8b00 initialize capabilities for lxc-start and lxc-execute
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-07-20 13:45:44 +02:00
Nathan Lynch
fa9ab20562 correct asprintf error checking
asprintf(3) returns -1 (not 0) on error.

Signed-off-by: Nathan Lynch <ntl@pobox.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-05-19 22:15:28 +02:00
Daniel Lezcano
91480a0f0a restart the container at reboot
When the reboot is detected, reboot the container.
That needs to set all file descriptor opened by lxc-start
to be flagged with the close-on-exec flag, otherwise when
re-execing ourself, we inherit our own fd.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-04-08 09:44:23 +02:00
Cedric Le Goater
80090207de lxc: forbid open fds upon startup
This patch modifies the startup of a container to forbid opened
fds, unless these are stdios.

Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
2010-03-22 11:08:34 +01:00
Daniel Lezcano
63376d7db3 allocate a console to be proxied
The actual behaviour of the console is messy as:
 * it relies on a heuristic (tty or not, rootfs or not, etc ...)
 * the container init stole the tty and we lose the control

The following patch:
 * allocates a tty
 * maps this tty to the container console
 * proxy the io from the console to the file specified in the configuration
 lxc.console=<file>

That allows to specify a file, a fifo, a $(tty), and can be extended with an
uri like file://mypath, net://1.2.3.4:1234, etc ...
That solves the problem with the heuristic and the container does no longer stole
our current tty.

Note by default, the console output will go to a blackhole if no configuration is
specified making the container showing nothing.

In order to access the console from the tty, use

 lxc-start -n foo -s lxc.console=$(tty)

I propose the make the container to daemonize by default now.

I tried the following:

 in a shell:
  touch /var/lib/lxc/foo/console
  tail --retry -f /var/lib/lxc/foo/console
 in another shell:
  lxc-start -n foo -s lxc.console=/var/lib/lxc/foo/console

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2010-02-24 10:57:43 +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
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
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
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
Daniel Lezcano
7418c9ced1 rollback configuration is a file
The container will be a directory where the user can store everything,
so we create one directory and store a configuration file inside.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-20 15:01:30 +01:00
Daniel Lezcano
158f998257 Do not chdir when daemonize
With the previous modifications, a temporary directory is created
to mount the rootfs in order to have the system container to remount
itself the '/' directory.

But in case of daemonize, we change the directory, so when the rootfs
is specified with a relative path, we can not access it.

Don't chdir, as that will be done automatically later in the chroot
setup.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-20 15:01:30 +01:00
Daniel Lezcano
96c210bbbe fix container find the previously created configuration
The command specifies a configuration file => use it
The command does not specify a configuration but the container
was created before, use the configuration.
The command does not specify a configuration and the container
was not created before, use default.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-17 22:57:46 +01:00
Cedric Le Goater
00b3c2e284 cleanup <lxc/lxc.h>
<lxc/lxc.h>  should only include what is needed. This patch removes
all useless headers from lxc.h and fixed other .c files.

Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-17 10:56:23 +01:00
Daniel Lezcaon
4886240165 Allows a container to run without previous creation
When a container was created, its configuration is used.
When a container was not created, the configuration specified in
the command line is used, if not configuration file is used,
default values are used.

That allows to create 'volatile' container, like tmp files.
It is useful for example to spawn different container with the
same generic configuration file. That let the user to have its own
repository of configuration files.

And, more important, that fix temporary created container with
lxc-execute to be not deleted when the host crash or the command
is killed.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-11-13 11:48:29 +01:00
Daniel Lezcano
af79587587 fix closed fd when they are inherited
This patch fix a problem with the commit d983b93c3a
When the lxc daemonize, it closes fd 0, 1 and 2. But these ones are coming from
inherited fd and they are already in the inherited list of fd. When lxc creates
some file descriptors, they have the number of the previous inherited file
descriptor, so they are closed when we close all the inherited file descriptors.

In order to fix that, the lxc_close_inherited_fd function has been implemented
to close an inherited fd and remove it from the list.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-07-20 17:57:31 +02:00
Daniel Lezcano
b8f57738b4 log the container console when it is daemonized and the log is enabled
When we daemonize the container and we specify the log file,
the container will use the log file to write the console output.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-06-07 21:48:46 +02:00
Daniel Lezcano
c36583c303 Make possible to daemonize lxc-start
If needed the container can be launched in background
with a specific option -d.

That will make mute the container, the logs can help
to check what went wrong.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-06-07 21:48:46 +02:00
Daniel Lezcano
f8e09a0b76 save/restore the tty
Save the tty configuration before calling lxc_start and
restore it right after it has been changed.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-06-07 21:48:46 +02:00
Michel Normand
e043236e2a lxc-start to report exit code of started application
The exit code of the application as reported by lxc-start is:
0-126       exit code of the application itself
128+n       signal n received by the application
255         lxc error

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-05-18 22:27:34 +02:00
Michel Normand
9618063c87 add long options step2
add the long options to lxc-start
with a small change in lxc_start proto to avoid compilation warning

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-05-18 22:11:45 +02:00
Michel Normand
441e496395 add quiet option
This added quiet option allow to disable
the reporting via stderr of the lxc error messages.

Note that the usage function is still printing in case of error,
but will be removed by later patches

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-05-18 22:11:45 +02:00
Michel Normand
4c200d12e0 report error in lxc_get_lock
report error in lxc_get_lock and remove the call to lxc_strerror
that become useless for these errors.

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-05-17 13:43:51 +02:00
Michel Normand
51cab6315f add support of a lxc log file to cli
this is adding -o and -l options to all cli of lxc

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-05-14 15:52:03 +02:00
Michel Normand
3ab87b66af remove fprintf to stderr and replace by ERROR call when needed
do it in all cli, except:
* the usage functions that will be removed by another patch
* the lxc_init that need more work
* the lxc_priority that is not used anymore

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-05-14 15:52:03 +02:00
Cedric Le Goater
36eb9bdef1 lxc: use new logging system
This patch defines a new log category in each file using logging and
replaced the former logging routines with the new ones.

Signed-off-by: Cedric Le Goater <legoater@free.fr>
Acked-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-04-21 21:51:13 +02:00
dlezcano
64870cda2a Fixed bad variable type
From: Daniel Lezcano <daniel.lezcano@free.fr>

Fixed the type of the opt variable. On the powerpc architecture, that leads
to an infinite loop in the getopt inspection because getopt returns 255
instead of -1 as expected. The opt variable should be an int and not a char.

Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-01-26 19:43:46 +00:00
dlezcano
b0a33c1eb6 From: Daniel Lezcano <daniel.lezcano@free.fr>
Console support for the system container.

Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2009-01-25 21:52:38 +00:00
dlezcano
1f3da8f86c Handle the lock error and show message to user
From: Daniel Lezcano <dlezcano@fr.ibm.com>

Handle the lock error and show message to user.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2008-11-17 17:55:49 +00:00
dlezcano
b2b6c597df Default command is "/sbin/init" for lxc-start
From: Daniel Lezcano <dlezcano@fr.ibm.com>

When no command is specified is specified for lxc-start, the "/sbin/init"
is automatically used.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2008-11-14 15:35:40 +00:00
dlezcano
05f05512ed Replace lxc_execute by an intermediate lxc_init
From: Daniel Lezcano <dlezcano@fr.ibm.com>

The main difference between lxc_start and lxc_execute is the latter creates
an intermediate process to wait for all the childs. That allows to support
daemons or orphan process group for the pid namespace.

Having such difference makes the code to be duplicate between the two
functions. So instead of doing this, I create an intermediate <init> program
which is in charge to launch the specified command. This command is the
lxc-init program taking different options:
 --mount-procfs : mount the proc filesystem before exec'ing the command
 --mount-sysfs : mount the sys filesystem before exec'ing the command

A double dash indicates the end of the options of lxc-init and the beginning
of the command to be launched.

To summarize:
 * lxc_execute function is no more.
 * lxc-execute command uses the lxc_start function and launch the specified
command via lxc-init

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
2008-11-13 15:21:55 +00:00
dlezcano
b113348ebd Change header inclusion path 2008-09-04 10:09:53 +00:00
dlezcano
5e97c3fcce Initial revision 2008-08-06 14:32:29 +00:00