[lxc-devel] [PATCH 1/1] systemd: specify container_ttys in environment

Daniel P. Berrange berrange at redhat.com
Wed Jan 28 14:35:28 UTC 2015


On Tue, Jan 27, 2015 at 08:48:25PM +0000, Serge Hallyn wrote:
> The lxc.tty configuration item specifies a number of ttys to create.
> Historically, for each of those, we create a /dev/pts/N entry and
> symlink it to /dev/ttyN for older inits to use.  For systemd, we should
> instead specify each tty name in a $container_ttys environment variable
> passed to init.
> 
> See http://www.freedesktop.org/wiki/Software/systemd/ContainerInterface/ and
> https://github.com/lxc/lxc/issues/419.
> 
> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
> ---
>  src/lxc/conf.c  | 43 ++++++++++++++++++++++++++++++++++++++++---
>  src/lxc/conf.h  |  1 +
>  src/lxc/start.c |  8 +++++---
>  3 files changed, 46 insertions(+), 6 deletions(-)
> 

> +static int setup_tty(struct lxc_conf *conf)
> +{
> +	const struct lxc_rootfs *rootfs = &conf->rootfs;
> +	const struct lxc_tty_info *tty_info = &conf->tty_info;
> +	char *ttydir = conf->ttydir;
>  	char path[MAXPATHLEN], lxcpath[MAXPATHLEN];
>  	int i, ret;
>  
> @@ -999,6 +1024,8 @@ static int setup_tty(const struct lxc_rootfs *rootfs,
>  				SYSERROR("failed to create symlink for tty %d", i+1);
>  				return -1;
>  			}
> +			/* Now save the relative path in @path for append_ptyname */
> +			sprintf(path, "%s/tty%d", ttydir, i + 1);
>  		} else {
>  			/* If we populated /dev, then we need to create /dev/ttyN */
>  			if (access(path, F_OK)) {
> @@ -1015,6 +1042,12 @@ static int setup_tty(const struct lxc_rootfs *rootfs,
>  						pty_info->name, path);
>  				continue;
>  			}
> +			/* Now save the relative path in @path for append_ptyname */
> +			sprintf(path, "tty%d", i + 1);
> +		}
> +		if (!append_ptyname(&conf->pty_names, path)) {
> +			ERROR("Error setting up container_ttys string");
> +			return -1;
>  		}
>  	}

I'm unclear if this is relevant for LXC tools or not, but if one of those
ptys is symlinked to /dev/console, then it should be excluded from the
set in "container_ttys" env variable.

In libvirt /dev/pts/0 is always symlinked to /dev/console, so we only
include pts/1, pts/2, etc in "container_ttys".  Not doing this will
result in systemd trying to launch login process on both /dev/console
and /dev/pts/0 with obvious hilarity / fail :-)

Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|


More information about the lxc-devel mailing list