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

Stéphane Graber stgraber at ubuntu.com
Wed Jan 28 16:29:11 UTC 2015


On Wed, Jan 28, 2015 at 04:23:43PM +0000, Serge Hallyn wrote:
> Quoting Daniel P. Berrange (berrange at redhat.com):
> > 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 :-)
> 
> :)  Yup, the setup_tty() function which adds to the pty_names list is
> only called for the ptys other than /dev/console, so this bit is ok.
> 
> (Something else seems to be wrong with it, but not sure yet what)
> 
> thanks,
> -serge

Just a quick note that this patch doesn't actually work because systemd
checks that those are pts/* and ours aren't (they belong to the host's
devpts, not the container's).

-- 
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: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20150128/26c801b7/attachment.sig>


More information about the lxc-devel mailing list