Hello

Attached is a patch that allows one to include other configuration files
from the main container config. The main motivation is to make the
automation of container configuration changes easier. Shell globs are
allowed, so you can do

lxc.include = /var/lib/lxc/mycontainer/conf.d/*.conf

I used the config value "lxc.include" to avoid having to change the
parse_line function, but since this is not really an LXC setting, maybe
something different would be desired (maybe "#include"?)

Any comments are appreciated.

Thanks in advance,
Andre
diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 550102c..7b7ae94 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -27,6 +27,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <pty.h>
+#include <glob.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/param.h>
@@ -69,6 +70,7 @@ static int config_network_ipv6(const char *, char *, struct lxc_conf *);
 static int config_network_ipv6_gateway(const char *, char *, struct lxc_conf *);
 static int config_cap_drop(const char *, char *, struct lxc_conf *);
 static int config_console(const char *, char *, struct lxc_conf *);
+static int config_include(const char *, char *, struct lxc_conf *);
 
 typedef int (*config_cb)(const char *, char *, struct lxc_conf *);
 
@@ -104,6 +106,7 @@ static struct config config[] = {
 	{ "lxc.network.ipv6",         config_network_ipv6         },
 	{ "lxc.cap.drop",             config_cap_drop             },
 	{ "lxc.console",              config_console              },
+	{ "lxc.include",              config_include              },
 };
 
 static const size_t config_size = sizeof(config)/sizeof(struct config);
@@ -943,6 +946,31 @@ int lxc_config_read(const char *file, struct lxc_conf *conf)
 	return lxc_file_for_each_line(file, parse_line, conf);
 }
 
+static int config_include(const char *key, char *value, struct lxc_conf *lxc_conf)
+{
+	int i, ret;
+	glob_t gl;
+
+	ret = glob(value, GLOB_ERR | GLOB_BRACE | GLOB_TILDE, NULL, &gl);
+	if (ret != 0) {
+		globfree(&gl);
+		ERROR("failed to read included configuration file "
+                        "'%s': %s", value, strerror(errno));
+		return -1;
+	}
+	for (i = 0; i < gl.gl_pathc; i++) {
+		char *file = gl.gl_pathv[i];
+		ret = lxc_config_read(file, lxc_conf);
+		if (ret != 0) {
+			globfree(&gl);
+			ERROR("failed to read included configuration file "
+                                "'%s': %s", file, strerror(errno));
+			return -1;
+		}
+	}
+	return 0;
+}
+
 int lxc_config_define_add(struct lxc_list *defines, char* arg)
 {
 	struct lxc_list *dent;
------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to