[lxc-devel] [PATCH 2/3] execute: bind init.lxc.static into container

Serge Hallyn serge.hallyn at ubuntu.com
Tue May 13 11:46:00 UTC 2014


Quoting Serge Hallyn (serge.hallyn at ubuntu.com):
> Quoting Dwight Engen (dwight.engen at oracle.com):
> > On Mon, 12 May 2014 18:04:00 +0000
> > Serge Hallyn <serge.hallyn at ubuntu.com> wrote:
> > 
> > > Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
> > > ---
> > >  src/lxc/conf.c | 58
> > > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file
> > > changed, 58 insertions(+)
> > > 
> > > diff --git a/src/lxc/conf.c b/src/lxc/conf.c
> > > index 7427a94..0580f46 100644
> > > --- a/src/lxc/conf.c
> > > +++ b/src/lxc/conf.c
> > > @@ -3811,6 +3811,61 @@ static void remount_all_slave(void)
> > >  		free(line);
> > >  }
> > >  
> > > +void lxc_execute_bind_init(struct lxc_conf *conf)
> > > +{
> > > +	int ret;
> > > +	char path[PATH_MAX], destpath[PATH_MAX];
> > > +
> > > +	ret = snprintf(path, PATH_MAX, SBINDIR "/init.lxc.static");
> > > +	if (ret < 0 || ret >= PATH_MAX) {
> > > +		WARN("Path name too long searching for
> > > lxc.init.static");
> > > +		return;
> > > +	}
> > > +
> > > +	if (!file_exists(path)) {
> > > +		INFO("%s does not exist on host", path);
> > > +		return;
> > > +	}
> > > +
> > > +	ret = snprintf(destpath, PATH_MAX, "%s%s",
> > > conf->rootfs.mount, path);
> > > +	if (ret < 0 || ret >= PATH_MAX) {
> > > +		WARN("Path name too long for container's
> > > lxc.init.static");
> > > +		return;
> > > +	}
> > > +
> > > +	if (!file_exists(destpath)) {
> > > +		FILE *pathfile;
> > > +		char *pathdirname = strdup(path);
> > > +
> > > +		if (!pathdirname) {
> > > +			SYSERROR("Out of memory binding
> > > lxc.init.static into container");
> > > +			return;
> > > +		}
> > > +		pathdirname = dirname(pathdirname);
> > > +		ret = mkdir_p(pathdirname, 0755);
> > > +		free(pathdirname);
> > > +		if (ret < 0) {
> > > +			/*
> > > +			 * this can fail just due to read-only bind
> > > mounts.  Trust
> > > +			 * that the user knows what they want, log
> > > and proceed
> > > +			 */
> > > +			WARN("Failed to create %s in container",
> > > SBINDIR);
> > > +			return;
> > > +		}
> > > +		pathfile = fopen(destpath, "wb");
> 
> Thanks for taking a look,
> 
> > Hi Serge, are you sure you want to truncate destpath in case it exists?
> > Maybe you want "ab"?
> 
> This only happens in the !file_exists(destpath) case though, so it
> really shouldn't be possible absent a weird race.

I guess it might be worth changing.  I copy/pasted this code from the
file=create case in conf.c, so I think we should fix it in both places
with one separate patch.


More information about the lxc-devel mailing list