[lxc-devel] [PATCH] create fd, stdin, stdout, stderr symlinks in /dev

Dwight Engen dwight.engen at oracle.com
Thu Feb 13 21:36:22 UTC 2014


Hey Mike, I didn't add /dev/core since it wasn't in "Compulsory", but
if you think we should have it too feel free to add it :)

On Thu, 13 Feb 2014 16:26:59 -0500
"Michael H. Warfield" <mhw at WittsEnd.com> wrote:

> Nice job.  Ya beat me too it.
> 
> Acked-by: Michael H. Warfield <mhw at WittsEnd.com>
> 
> On Thu, 2014-02-13 at 16:13 -0500, Dwight Engen wrote:
> > The kernel's Documentation/devices.txt says that these symlinks
> > should exist in /dev (they are listed in the "Compulsory" section).
> > I'm not currently adding nfsd and X0R since they are required for
> > iBCS, but they can be easily added to the array later if need be.
> > 
> > Signed-off-by: Dwight Engen <dwight.engen at oracle.com>
> > ---
> >  src/lxc/conf.c | 37 +++++++++++++++++++++++++++++++++++++
> >  1 file changed, 37 insertions(+)
> > 
> > diff --git a/src/lxc/conf.c b/src/lxc/conf.c
> > index 6fa3db9..0de189f 100644
> > --- a/src/lxc/conf.c
> > +++ b/src/lxc/conf.c
> > @@ -812,6 +812,38 @@ static int setup_utsname(struct utsname
> > *utsname) return 0;
> >  }
> >  
> > +struct dev_symlinks {
> > +	const char *oldpath;
> > +	const char *name;
> > +};
> > +
> > +static const struct dev_symlinks dev_symlinks[] = {
> > +	{"/proc/self/fd",	"fd"},
> > +	{"/proc/self/fd/0",	"stdin"},
> > +	{"/proc/self/fd/1",	"stdout"},
> > +	{"/proc/self/fd/2",	"stderr"},
> > +};
> > +
> > +static int setup_dev_symlinks(const struct lxc_rootfs *rootfs)
> > +{
> > +	char path[MAXPATHLEN];
> > +	int ret,i;
> > +
> > +
> > +	for (i = 0; i < sizeof(dev_symlinks) /
> > sizeof(dev_symlinks[0]); i++) {
> > +		const struct dev_symlinks *d = &dev_symlinks[i];
> > +		ret = snprintf(path, sizeof(path), "%s/dev/%s",
> > rootfs->mount, d->name);
> > +		if (ret < 0 || ret >= MAXPATHLEN)
> > +			return -1;
> > +		ret = symlink(d->oldpath, path);
> > +		if (ret && errno != EEXIST) {
> > +			SYSERROR("Error creating %s", path);
> > +			return -1;
> > +		}
> > +	}
> > +	return 0;
> > +}
> > +
> >  static int setup_tty(const struct lxc_rootfs *rootfs,
> >  		     const struct lxc_tty_info *tty_info, char
> > *ttydir) {
> > @@ -3616,6 +3648,11 @@ int lxc_setup(struct lxc_handler *handler)
> >  		return -1;
> >  	}
> >  
> > +	if (!lxc_conf->is_execute &&
> > setup_dev_symlinks(&lxc_conf->rootfs)) {
> > +		ERROR("failed to setup /dev symlinks for '%s'",
> > name);
> > +		return -1;
> > +	}
> > +
> >  	/* mount /proc if needed for LSM transition */
> >  	if (lsm_proc_mount(lxc_conf) < 0) {
> >  		ERROR("failed to LSM mount proc for '%s'", name);
> > -- 
> > 1.8.5.3
> > 
> > 
> 



More information about the lxc-devel mailing list