Description: Support individual hook types in clear_config_item
 Without this patch, only clear_config_item("lxc.hook") works.
Forwarded: yes
Author: Serge Hallyn <serge.hallyn@ubuntu.com>
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1050719

Index: lxc/src/lxc/conf.c
===================================================================
--- lxc.orig/src/lxc/conf.c	2012-09-14 11:34:25.616537000 -0500
+++ lxc/src/lxc/conf.c	2012-09-14 12:07:18.149733532 -0500
@@ -2488,18 +2488,31 @@
 	return 0;
 }
 
-int lxc_clear_hooks(struct lxc_conf *c)
+int lxc_clear_hooks(struct lxc_conf *c, char *key)
 {
 	struct lxc_list *it;
+	bool all = false, done = false;
+	char *k = key + 9;
 	int i;
 
+	if (strcmp(key, "lxc.hook") == 0)
+		all = true;
+
 	for (i=0; i<NUM_LXC_HOOKS; i++) {
-		lxc_list_for_each(it, &c->hooks[i]) {
-			lxc_list_del(it);
-			free(it->elem);
-			free(it);
+		if (all || strcmp(k, lxchook_names[i]) == 0) {
+			lxc_list_for_each(it, &c->hooks[i]) {
+				lxc_list_del(it);
+				free(it->elem);
+				free(it);
+			}
+			done = true;
 		}
 	}
+
+	if (!done) {
+		ERROR("Invalid hook key: %s", key);
+		return -1;
+	}
 	return 0;
 }
 
@@ -2516,7 +2529,7 @@
 		free(conf->aa_profile);
 	lxc_clear_config_caps(conf);
 	lxc_clear_cgroups(conf, "lxc.cgroup");
-	lxc_clear_hooks(conf);
+	lxc_clear_hooks(conf, "lxc.hook");
 	lxc_clear_mount_entries(conf);
 	free(conf);
 }
Index: lxc/src/lxc/conf.h
===================================================================
--- lxc.orig/src/lxc/conf.h	2012-09-14 11:34:25.616537000 -0500
+++ lxc/src/lxc/conf.h	2012-09-14 11:37:06.507461581 -0500
@@ -252,7 +252,7 @@
 extern int lxc_clear_config_caps(struct lxc_conf *c);
 extern int lxc_clear_cgroups(struct lxc_conf *c, char *key);
 extern int lxc_clear_mount_entries(struct lxc_conf *c);
-extern int lxc_clear_hooks(struct lxc_conf *c);
+extern int lxc_clear_hooks(struct lxc_conf *c, char *key);
 
 /*
  * Configure the container from inside
Index: lxc/src/lxc/confile.c
===================================================================
--- lxc.orig/src/lxc/confile.c	2012-09-14 11:34:25.616537000 -0500
+++ lxc/src/lxc/confile.c	2012-09-14 11:36:55.171461993 -0500
@@ -1557,8 +1557,8 @@
 		return lxc_clear_cgroups(c, key);
 	else if (strcmp(key, "lxc.mount.entries") == 0)
 		return lxc_clear_mount_entries(c);
-	else if (strcmp(key, "lxc.hook") == 0)
-		return lxc_clear_hooks(c);
+	else if (strncmp(key, "lxc.hook", 8) == 0)
+		return lxc_clear_hooks(c, key);
 
 	return -1;
 }
