[lxc-devel] [PATCH] remove LXC_CLONE_COPYHOOKS and make lxcapi_clone to copy hooks unconditionally

Serge Hallyn serge.hallyn at ubuntu.com
Thu Dec 19 05:40:45 UTC 2013


Quoting Serge Hallyn (serge.hallyn at ubuntu.com):
> Quoting S.Çağlar Onur (caglar at 10ur.org):
> > Signed-off-by: S.Çağlar Onur <caglar at 10ur.org>
> 
> You're missing the part where copyhooks only copies hooks under the
> container's path.  Could be as simple as the following untested patch:
> 
> diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
> index 1af8d62..9ee29fd 100644
> --- a/src/lxc/lxccontainer.c
> +++ b/src/lxc/lxccontainer.c
> @@ -2187,7 +2187,13 @@ static int copyhooks(struct lxc_container *oldc, struct lxc_container *c)
>  	int i;
>  	int ret;
>  	struct lxc_list *it;
> +	char *cpath;
>  
> +	i = strlen(oldc->config_path) + strlen(oldc->name) + 3;
> +	cpath = alloca(i);
> +	ret = snprintf(cpath, i, "%s/%s/", oldc->config_path, oldc->name);
> +	if (ret < 0 || ret >= i)
> +		return -1;
>  	for (i=0; i<NUM_LXC_HOOKS; i++) {
>  		lxc_list_for_each(it, &c->lxc_conf->hooks[i]) {
>  			char *hookname = it->elem;
> @@ -2195,6 +2201,10 @@ static int copyhooks(struct lxc_container *oldc, struct lxc_container *c)
>  			char tmppath[MAXPATHLEN];
>  			if (!fname) // relative path - we don't support, but maybe we should
>  				return 0;
> +			if (strncpy(hookname, cpath) != 0) {

haha, if you take this code, better store the length into a new 'len'
and fix strcpy to strncmp(hookname, cpath, len)

think i'm done for the day

> +				// this hook is public - ignore
> +				continue;
> +			}
>  			// copy the script, and change the entry in confile
>  			ret = snprintf(tmppath, MAXPATHLEN, "%s/%s/%s",
>  					c->config_path, c->name, fname+1);
> _______________________________________________
> 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