[lxc-devel] [lxc/master] minor tweaks

brauner on Github lxc-bot at linuxcontainers.org
Mon Mar 4 19:35:55 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190304/de11cbd2/attachment.bin>
-------------- next part --------------
From 15f3007f8970f858fd88ff1b1fb3a985c99fcc20 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Mon, 4 Mar 2019 20:26:33 +0100
Subject: [PATCH 1/3] confile_utils: lxc_config_net_is_hwaddr()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c       |  2 +-
 src/lxc/confile_utils.c | 44 ++++++++++++++++++++---------------------
 src/lxc/confile_utils.h |  2 +-
 3 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 120e9cddf8..2c420cf8b5 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -3014,7 +3014,7 @@ bool network_new_hwaddrs(struct lxc_conf *conf)
 		else
 			lend++;
 
-		if (!lxc_config_net_hwaddr(lstart)) {
+		if (!lxc_config_net_is_hwaddr(lstart)) {
 			lstart = lend;
 			continue;
 		}
diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c
index 04926854d1..fd6c28a0b9 100644
--- a/src/lxc/confile_utils.c
+++ b/src/lxc/confile_utils.c
@@ -548,6 +548,27 @@ int network_ifname(char *valuep, const char *value, size_t size)
 	return 0;
 }
 
+bool lxc_config_net_is_hwaddr(const char *line)
+{
+	unsigned index;
+	char tmp[7];
+
+	if (strncmp(line, "lxc.net", 7) != 0)
+		return false;
+
+	if (strncmp(line, "lxc.net.hwaddr", 14) == 0)
+		return true;
+
+	if (strncmp(line, "lxc.network.hwaddr", 18) == 0)
+		return true;
+
+	if (sscanf(line, "lxc.net.%u.%6s", &index, tmp) == 2 ||
+	    sscanf(line, "lxc.network.%u.%6s", &index, tmp) == 2)
+		return strncmp(tmp, "hwaddr", 6) == 0;
+
+	return false;
+}
+
 void rand_complete_hwaddr(char *hwaddr)
 {
 	const char hex[] = "0123456789abcdef";
@@ -580,27 +601,6 @@ void rand_complete_hwaddr(char *hwaddr)
 	}
 }
 
-bool lxc_config_net_hwaddr(const char *line)
-{
-	unsigned index;
-	char tmp[7];
-
-	if (strncmp(line, "lxc.net", 7) != 0)
-		return false;
-
-	if (strncmp(line, "lxc.net.hwaddr", 14) == 0)
-		return true;
-
-	if (strncmp(line, "lxc.network.hwaddr", 18) == 0)
-		return true;
-
-	if (sscanf(line, "lxc.net.%u.%6s", &index, tmp) == 2 ||
-	    sscanf(line, "lxc.network.%u.%6s", &index, tmp) == 2)
-		return strncmp(tmp, "hwaddr", 6) == 0;
-
-	return false;
-}
-
 /*
  * If we find a lxc.net.[i].hwaddr or lxc.network.hwaddr in the original config
  * file, we expand it in the unexpanded_config, so that after a save_config we
@@ -617,7 +617,7 @@ void update_hwaddr(const char *line)
 	if (line[0] == '#')
 		return;
 
-	if (!lxc_config_net_hwaddr(line))
+	if (!lxc_config_net_is_hwaddr(line))
 		return;
 
 	/* Let config_net_hwaddr raise the error. */
diff --git a/src/lxc/confile_utils.h b/src/lxc/confile_utils.h
index e381cbe648..2c3948b8fb 100644
--- a/src/lxc/confile_utils.h
+++ b/src/lxc/confile_utils.h
@@ -66,7 +66,7 @@ extern int set_config_path_item(char **conf_item, const char *value);
 extern int config_ip_prefix(struct in_addr *addr);
 extern int network_ifname(char *valuep, const char *value, size_t size);
 extern void rand_complete_hwaddr(char *hwaddr);
-extern bool lxc_config_net_hwaddr(const char *line);
+extern bool lxc_config_net_is_hwaddr(const char *line);
 extern void update_hwaddr(const char *line);
 extern bool new_hwaddr(char *hwaddr);
 extern int lxc_get_conf_str(char *retv, int inlen, const char *value);

From e81e5d68467c64f7be7022032bbf38b5dd2d7ca4 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Mon, 4 Mar 2019 20:30:41 +0100
Subject: [PATCH 2/3] confile_utils: make update_hwaddr() static

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c       | 34 ++++++++++++++++++++++++++++++++++
 src/lxc/confile_utils.c | 35 -----------------------------------
 src/lxc/confile_utils.h |  1 -
 3 files changed, 34 insertions(+), 36 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 2c420cf8b5..a61add7544 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -2081,6 +2081,40 @@ static int set_config_console_size(const char *key, const char *value,
 	return 0;
 }
 
+/*
+ * If we find a lxc.net.[i].hwaddr or lxc.network.hwaddr in the original config
+ * file, we expand it in the unexpanded_config, so that after a save_config we
+ * store the hwaddr for re-use.
+ * This is only called when reading the config file, not when executing a
+ * lxc.include.
+ * 'x' and 'X' are substituted in-place.
+ */
+static void update_hwaddr(const char *line)
+{
+	char *p;
+
+	line += lxc_char_left_gc(line, strlen(line));
+	if (line[0] == '#')
+		return;
+
+	if (!lxc_config_net_is_hwaddr(line))
+		return;
+
+	/* Let config_net_hwaddr raise the error. */
+	p = strchr(line, '=');
+	if (!p)
+		return;
+	p++;
+
+	while (isblank(*p))
+		p++;
+
+	if (!*p)
+		return;
+
+	rand_complete_hwaddr(p);
+}
+
 int append_unexp_config_line(const char *line, struct lxc_conf *conf)
 {
 	size_t linelen;
diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c
index fd6c28a0b9..72db49a080 100644
--- a/src/lxc/confile_utils.c
+++ b/src/lxc/confile_utils.c
@@ -601,40 +601,6 @@ void rand_complete_hwaddr(char *hwaddr)
 	}
 }
 
-/*
- * If we find a lxc.net.[i].hwaddr or lxc.network.hwaddr in the original config
- * file, we expand it in the unexpanded_config, so that after a save_config we
- * store the hwaddr for re-use.
- * This is only called when reading the config file, not when executing a
- * lxc.include.
- * 'x' and 'X' are substituted in-place.
- */
-void update_hwaddr(const char *line)
-{
-	char *p;
-
-	line += lxc_char_left_gc(line, strlen(line));
-	if (line[0] == '#')
-		return;
-
-	if (!lxc_config_net_is_hwaddr(line))
-		return;
-
-	/* Let config_net_hwaddr raise the error. */
-	p = strchr(line, '=');
-	if (!p)
-		return;
-	p++;
-
-	while (isblank(*p))
-		p++;
-
-	if (!*p)
-		return;
-
-	rand_complete_hwaddr(p);
-}
-
 bool new_hwaddr(char *hwaddr)
 {
 	int ret;
@@ -703,7 +669,6 @@ int lxc_get_conf_int(struct lxc_conf *c, char *retv, int inlen, int v)
 
 	return fulllen;
 }
-
 int lxc_get_conf_size_t(struct lxc_conf *c, char *retv, int inlen, size_t v)
 {
 	int len;
diff --git a/src/lxc/confile_utils.h b/src/lxc/confile_utils.h
index 2c3948b8fb..b097edc0fb 100644
--- a/src/lxc/confile_utils.h
+++ b/src/lxc/confile_utils.h
@@ -67,7 +67,6 @@ extern int config_ip_prefix(struct in_addr *addr);
 extern int network_ifname(char *valuep, const char *value, size_t size);
 extern void rand_complete_hwaddr(char *hwaddr);
 extern bool lxc_config_net_is_hwaddr(const char *line);
-extern void update_hwaddr(const char *line);
 extern bool new_hwaddr(char *hwaddr);
 extern int lxc_get_conf_str(char *retv, int inlen, const char *value);
 extern int lxc_get_conf_bool(struct lxc_conf *c, char *retv, int inlen, bool v);

From 00d86b1736c9d7c440f57622bc2dc9081a2cebbf Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Mon, 4 Mar 2019 20:31:52 +0100
Subject: [PATCH 3/3] confile: make parse_limit_value() static

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c       | 20 ++++++++++++++++++++
 src/lxc/confile_utils.c | 21 +--------------------
 src/lxc/confile_utils.h |  1 -
 3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index a61add7544..8f94635d1b 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1450,6 +1450,26 @@ static int set_config_cgroup_relative(const char *key, const char *value,
 	return -EINVAL;
 }
 
+static bool parse_limit_value(const char **value, rlim_t *res)
+{
+	char *endptr = NULL;
+
+	if (strncmp(*value, "unlimited", STRLITERALLEN("unlimited")) == 0) {
+		*res = RLIM_INFINITY;
+		*value += STRLITERALLEN("unlimited");
+		return true;
+	}
+
+	errno = 0;
+	*res = strtoull(*value, &endptr, 10);
+	if (errno || !endptr)
+		return false;
+
+	*value = endptr;
+
+	return true;
+}
+
 static int set_config_prlimit(const char *key, const char *value,
 			    struct lxc_conf *lxc_conf, void *data)
 {
diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c
index 72db49a080..50777c4481 100644
--- a/src/lxc/confile_utils.c
+++ b/src/lxc/confile_utils.c
@@ -669,6 +669,7 @@ int lxc_get_conf_int(struct lxc_conf *c, char *retv, int inlen, int v)
 
 	return fulllen;
 }
+
 int lxc_get_conf_size_t(struct lxc_conf *c, char *retv, int inlen, size_t v)
 {
 	int len;
@@ -699,26 +700,6 @@ int lxc_get_conf_uint64(struct lxc_conf *c, char *retv, int inlen, uint64_t v)
 	return fulllen;
 }
 
-bool parse_limit_value(const char **value, rlim_t *res)
-{
-	char *endptr = NULL;
-
-	if (strncmp(*value, "unlimited", STRLITERALLEN("unlimited")) == 0) {
-		*res = RLIM_INFINITY;
-		*value += STRLITERALLEN("unlimited");
-		return true;
-	}
-
-	errno = 0;
-	*res = strtoull(*value, &endptr, 10);
-	if (errno || !endptr)
-		return false;
-
-	*value = endptr;
-
-	return true;
-}
-
 static int lxc_container_name_to_pid(const char *lxcname_or_pid,
 				     const char *lxcpath)
 {
diff --git a/src/lxc/confile_utils.h b/src/lxc/confile_utils.h
index b097edc0fb..5a3bcc914c 100644
--- a/src/lxc/confile_utils.h
+++ b/src/lxc/confile_utils.h
@@ -73,7 +73,6 @@ extern int lxc_get_conf_bool(struct lxc_conf *c, char *retv, int inlen, bool v);
 extern int lxc_get_conf_int(struct lxc_conf *c, char *retv, int inlen, int v);
 extern int lxc_get_conf_size_t(struct lxc_conf *c, char *retv, int inlen, size_t v);
 extern int lxc_get_conf_uint64(struct lxc_conf *c, char *retv, int inlen, uint64_t v);
-extern bool parse_limit_value(const char **value, rlim_t *res);
 extern int lxc_inherit_namespace(const char *lxcname_or_pid,
 				 const char *lxcpath, const char *namespace);
 extern int sig_parse(const char *signame);


More information about the lxc-devel mailing list