[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:34:43 UTC 2013


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) {
+				// 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);


More information about the lxc-devel mailing list