[lxc-devel] [PATCH] don't set up console for lxc-execute
Stéphane Graber
stgraber at ubuntu.com
Thu Jun 13 15:22:15 UTC 2013
On Thu, Jun 13, 2013 at 10:09:59AM -0500, Serge Hallyn wrote:
> 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 at ubuntu.com>
Looks good to me.
Acked-by: Stéphane Graber <stgraber at ubuntu.com>
> ---
> src/lxc/conf.c | 4 ++--
> src/lxc/conf.h | 1 +
> src/lxc/console.c | 10 ++++++++++
> src/lxc/execute.c | 1 +
> 4 files changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/src/lxc/conf.c b/src/lxc/conf.c
> index a4ed218..d3dc9a5 100644
> --- a/src/lxc/conf.c
> +++ b/src/lxc/conf.c
> @@ -2836,7 +2836,7 @@ int lxc_setup(const char *name, struct lxc_conf *lxc_conf)
> }
> }
>
> - if (setup_console(&lxc_conf->rootfs, &lxc_conf->console, lxc_conf->ttydir)) {
> + if (!lxc_conf->is_execute && setup_console(&lxc_conf->rootfs, &lxc_conf->console, lxc_conf->ttydir)) {
> ERROR("failed to setup the console for '%s'", name);
> return -1;
> }
> @@ -2846,7 +2846,7 @@ int lxc_setup(const char *name, struct lxc_conf *lxc_conf)
> ERROR("failed to setup kmsg for '%s'", name);
> }
>
> - if (setup_tty(&lxc_conf->rootfs, &lxc_conf->tty_info, lxc_conf->ttydir)) {
> + if (!lxc_conf->is_execute && setup_tty(&lxc_conf->rootfs, &lxc_conf->tty_info, lxc_conf->ttydir)) {
> ERROR("failed to setup the ttys for '%s'", name);
> return -1;
> }
> diff --git a/src/lxc/conf.h b/src/lxc/conf.h
> index 2fd3ab1..9b1677e 100644
> --- a/src/lxc/conf.h
> +++ b/src/lxc/conf.h
> @@ -251,6 +251,7 @@ struct saved_nic {
> };
>
> struct lxc_conf {
> + int is_execute;
> char *fstab;
> int tty;
> int pts;
> diff --git a/src/lxc/console.c b/src/lxc/console.c
> index f801e0b..125890f 100644
> --- a/src/lxc/console.c
> +++ b/src/lxc/console.c
> @@ -276,6 +276,11 @@ int lxc_console_mainloop_add(struct lxc_epoll_descr *descr,
> struct lxc_conf *conf = handler->conf;
> struct lxc_console *console = &conf->console;
>
> + if (conf->is_execute) {
> + INFO("no console for lxc-execute.");
> + return 0;
> + }
> +
> if (!conf->rootfs.path) {
> INFO("no rootfs, no console.");
> return 0;
> @@ -564,6 +569,11 @@ int lxc_console_create(struct lxc_conf *conf)
> {
> struct lxc_console *console = &conf->console;
>
> + if (conf->is_execute) {
> + INFO("no console for lxc-execute.");
> + return 0;
> + }
> +
> if (!conf->rootfs.path)
> return 0;
>
> diff --git a/src/lxc/execute.c b/src/lxc/execute.c
> index 9bf33ca..3cf3540 100644
> --- a/src/lxc/execute.c
> +++ b/src/lxc/execute.c
> @@ -158,5 +158,6 @@ int lxc_execute(const char *name, char *const argv[], int quiet,
> if (lxc_check_inherited(conf, -1))
> return -1;
>
> + conf->is_execute = 1;
> return __lxc_start(name, conf, &execute_start_ops, &args, lxcpath);
> }
> --
> 1.8.1.2
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Windows:
>
> Build for Windows Store.
>
> http://p.sf.net/sfu/windows-dev2dev
> _______________________________________________
> Lxc-devel mailing list
> Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20130613/551fc3af/attachment.pgp>
More information about the lxc-devel
mailing list