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

Dwight Engen dwight.engen at oracle.com
Tue May 13 22:39:24 UTC 2014


On Tue, 13 May 2014 11:46:00 +0000
Serge Hallyn <serge.hallyn at ubuntu.com> wrote:

> 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.

Hey, when I try to build this I get:

conf.c: In function 'lxc_execute_bind_init':
conf.c:3824:2: error: implicit declaration of function 'file_exists' [-Werror=implicit-function-declaration]
  if (!file_exists(path)) {

it looks like file_exists() isn't declared in any header and is static to lxccontainer.c?

> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel



More information about the lxc-devel mailing list