[lxc-devel] [lxc/master] tree-wide: fixes

brauner on Github lxc-bot at linuxcontainers.org
Tue Dec 8 14:41:30 UTC 2020


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/20201208/4afec98b/attachment-0001.bin>
-------------- next part --------------
From 62af653cc125c90997b48179fbcff7e0fe6317b6 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:34:06 +0100
Subject: [PATCH 01/25] confile: cleanup set_config_personality()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index e7ab359291..e7f9df3c49 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1242,8 +1242,9 @@ static int set_config_hooks_version(const char *key, const char *value,
 static int set_config_personality(const char *key, const char *value,
 				  struct lxc_conf *lxc_conf, void *data)
 {
-	signed long personality = lxc_config_parse_arch(value);
+	signed long personality;
 
+	personality = lxc_config_parse_arch(value);
 	if (personality >= 0)
 		lxc_conf->personality = personality;
 	else

From 49aabd9d60e3879254ac6601a2fadb268259cc7e Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:36:17 +0100
Subject: [PATCH 02/25] confile: cleanup set_config_pty_max()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index e7f9df3c49..412d1045bc 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1266,7 +1266,7 @@ static int set_config_pty_max(const char *key, const char *value,
 
 	ret = lxc_safe_uint(value, &max);
 	if (ret < 0)
-		return -1;
+		return ret_errno(EINVAL);
 
 	lxc_conf->pty_max = max;
 

From 572f6a14705f2e1a187cc50f40e825a774cf5de1 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:38:16 +0100
Subject: [PATCH 03/25] confile: cleanup set_config_start()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 412d1045bc..38416e840c 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1281,6 +1281,7 @@ static int set_config_pty_max(const char *key, const char *value,
 static int set_config_start(const char *key, const char *value,
 			    struct lxc_conf *lxc_conf, void *data)
 {
+	int ret;
 	bool is_empty;
 
 	is_empty = lxc_config_value_empty(value);
@@ -1291,11 +1292,12 @@ static int set_config_start(const char *key, const char *value,
 			return 0;
 		}
 
-		if (lxc_safe_uint(value, &lxc_conf->start_auto) < 0)
-			return -1;
+		ret = lxc_safe_uint(value, &lxc_conf->start_auto);
+		if (ret)
+			return ret;
 
 		if (lxc_conf->start_auto > 1)
-			return -1;
+			return ret_errno(EINVAL);
 
 		return 0;
 	} else if (*(key + 10) == 'd') { /* lxc.start.delay */
@@ -1314,7 +1316,7 @@ static int set_config_start(const char *key, const char *value,
 		return lxc_safe_int(value, &lxc_conf->start_order);
 	}
 
-	return -1;
+	return ret_errno(EINVAL);
 }
 
 static int set_config_monitor(const char *key, const char *value,

From e16659731606d7f2ef9debe62dd872cbc403eb75 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:38:57 +0100
Subject: [PATCH 04/25] confile: cleanup set_config_monitor()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 38416e840c..6bf8143606 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1330,7 +1330,7 @@ static int set_config_monitor(const char *key, const char *value,
 	if (strcmp(key + 12, "unshare") == 0)
 		return lxc_safe_uint(value, &lxc_conf->monitor_unshare);
 
-	return -1;
+	return ret_errno(EINVAL);
 }
 
 static int set_config_monitor_signal_pdeath(const char *key, const char *value,

From cb5f3df2588ecf3c34716c6cac49dbfcaf6a83ff Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:39:49 +0100
Subject: [PATCH 05/25] confile: cleanup set_config_monitor_signal_pdeath()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 6bf8143606..4d1acc1fb1 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1346,13 +1346,13 @@ static int set_config_monitor_signal_pdeath(const char *key, const char *value,
 
 		sig_n = sig_parse(value);
 		if (sig_n < 0)
-			return -1;
+			return ret_errno(EINVAL);
 
 		lxc_conf->monitor_signal_pdeath = sig_n;
 		return 0;
 	}
 
-	return -EINVAL;
+	return ret_errno(EINVAL);
 }
 
 static int set_config_group(const char *key, const char *value,

From 154369953583fa1b321f588f142bdee724d4106e Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:43:50 +0100
Subject: [PATCH 06/25] confile: cleanup set_config_group()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 4d1acc1fb1..6900111dd0 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1358,40 +1358,34 @@ static int set_config_monitor_signal_pdeath(const char *key, const char *value,
 static int set_config_group(const char *key, const char *value,
 			    struct lxc_conf *lxc_conf, void *data)
 {
-	char *groups, *token;
-	struct lxc_list *grouplist;
-	int ret = 0;
+	__do_free char *groups = NULL;
+	char *token;
 
 	if (lxc_config_value_empty(value))
 		return lxc_clear_groups(lxc_conf);
 
 	groups = strdup(value);
 	if (!groups)
-		return -1;
+		return ret_errno(ENOMEM);
 
 	/* In case several groups are specified in a single line split these
 	 * groups in a single element for the list.
 	 */
 	lxc_iterate_parts(token, groups, " \t") {
+		__do_free struct lxc_list *grouplist = NULL;
+
 		grouplist = malloc(sizeof(*grouplist));
-		if (!grouplist) {
-			ret = -1;
-			break;
-		}
+		if (!grouplist)
+			return ret_errno(ENOMEM);
 
 		grouplist->elem = strdup(token);
-		if (!grouplist->elem) {
-			free(grouplist);
-			ret = -1;
-			break;
-		}
+		if (!grouplist->elem)
+			return ret_errno(ENOMEM);
 
-		lxc_list_add_tail(&lxc_conf->groups, grouplist);
+		lxc_list_add_tail(&lxc_conf->groups, move_ptr(grouplist));
 	}
 
-	free(groups);
-
-	return ret;
+	return 0;
 }
 
 static int set_config_environment(const char *key, const char *value,

From a6bf1128ebe08bd56a7e1f4481294485e22213fd Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:46:30 +0100
Subject: [PATCH 07/25] confile: cleanup set_config_environment()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 6900111dd0..56a0931fc9 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1391,14 +1391,14 @@ static int set_config_group(const char *key, const char *value,
 static int set_config_environment(const char *key, const char *value,
 				  struct lxc_conf *lxc_conf, void *data)
 {
-	struct lxc_list *list_item = NULL;
+	__do_free struct lxc_list *list_item = NULL;
 
 	if (lxc_config_value_empty(value))
 		return lxc_clear_environment(lxc_conf);
 
 	list_item = malloc(sizeof(*list_item));
 	if (!list_item)
-		goto on_error;
+		return ret_errno(ENOMEM);
 
 	if (!strchr(value, '=')) {
 		const char *env_val;
@@ -1407,7 +1407,7 @@ static int set_config_environment(const char *key, const char *value,
 
 		env_val = getenv(env_key);
 		if (!env_val)
-			goto on_error;
+			return ret_errno(ENOENT);
 
 		env_var[0] = env_key;
 		env_var[1] = env_val;
@@ -1417,16 +1417,11 @@ static int set_config_environment(const char *key, const char *value,
 	}
 
 	if (!list_item->elem)
-		goto on_error;
+		return ret_errno(ENOMEM);
 
-	lxc_list_add_tail(&lxc_conf->environment, list_item);
+	lxc_list_add_tail(&lxc_conf->environment, move_ptr(list_item));
 
 	return 0;
-
-on_error:
-	free(list_item);
-
-	return -1;
 }
 
 static int set_config_tty_max(const char *key, const char *value,

From 755d65326956b5950e9e32057fdef3f288e52b70 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:46:54 +0100
Subject: [PATCH 08/25] confile: cleanup set_config_tty_max()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 56a0931fc9..713c66386a 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1437,7 +1437,7 @@ static int set_config_tty_max(const char *key, const char *value,
 
 	ret = lxc_safe_uint(value, &nbtty);
 	if (ret < 0)
-		return -1;
+		return ret;
 
 	lxc_conf->ttys.max = nbtty;
 

From 042f87117f4336273ebce6d6f233d858a66e1a1d Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:47:46 +0100
Subject: [PATCH 09/25] confile: cleanup set_config_apparmor_allow_incomplete()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 713c66386a..7dfd984230 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1462,16 +1462,19 @@ static int set_config_apparmor_allow_incomplete(const char *key,
 						struct lxc_conf *lxc_conf,
 						void *data)
 {
+	int ret;
+
 	if (lxc_config_value_empty(value)) {
 		lxc_conf->lsm_aa_allow_incomplete = 0;
 		return 0;
 	}
 
-	if (lxc_safe_uint(value, &lxc_conf->lsm_aa_allow_incomplete) < 0)
-		return -1;
+	ret = lxc_safe_uint(value, &lxc_conf->lsm_aa_allow_incomplete);
+	if (ret)
+		return ret;
 
 	if (lxc_conf->lsm_aa_allow_incomplete > 1)
-		return -1;
+		return ret_errno(EINVAL);
 
 	return 0;
 }

From 55a7689135b3e8f47891d85e983422a40146d0ab Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:48:33 +0100
Subject: [PATCH 10/25] confile: cleanup set_config_apparmor_allow_nesting()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 7dfd984230..373d0d6f03 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1484,14 +1484,17 @@ static int set_config_apparmor_allow_nesting(const char *key,
 					     struct lxc_conf *lxc_conf,
 					     void *data)
 {
+	int ret;
+
 	if (lxc_config_value_empty(value))
 		return clr_config_apparmor_allow_nesting(key, lxc_conf, NULL);
 
-	if (lxc_safe_uint(value, &lxc_conf->lsm_aa_allow_nesting) < 0)
-		return -1;
+	ret = lxc_safe_uint(value, &lxc_conf->lsm_aa_allow_nesting);
+	if (ret)
+		return ret;
 
 	if (lxc_conf->lsm_aa_allow_nesting > 1)
-		return -1;
+		return ret_errno(EINVAL);
 
 	return 0;
 }

From 7f44fda1da647d40771facaa771916151eb7bd84 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:50:25 +0100
Subject: [PATCH 11/25] confile: cleanup set_config_apparmor_raw()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 373d0d6f03..89029c22ce 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1504,26 +1504,22 @@ static int set_config_apparmor_raw(const char *key,
 				   struct lxc_conf *lxc_conf,
 				   void *data)
 {
-	char *elem;
-	struct lxc_list *list;
+	__do_free char *elem = NULL;
+	__do_free struct lxc_list *list = NULL;
 
 	if (lxc_config_value_empty(value))
 		return lxc_clear_apparmor_raw(lxc_conf);
 
 	list = malloc(sizeof(*list));
-	if (!list) {
-		errno = ENOMEM;
-		return -1;
-	}
+	if (!list)
+		return ret_errno(ENOMEM);
 
 	elem = strdup(value);
-	if (!elem) {
-		free(list);
-		return -1;
-	}
-	list->elem = elem;
+	if (!elem)
+		return ret_errno(ENOMEM);
 
-	lxc_list_add_tail(&lxc_conf->lsm_aa_raw, list);
+	list->elem = move_ptr(elem);
+	lxc_list_add_tail(&lxc_conf->lsm_aa_raw, move_ptr(list));
 
 	return 0;
 }

From 34f3b30a78a74e543ba9029570fd07d0ba780200 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:51:22 +0100
Subject: [PATCH 12/25] confile: cleanup set_config_log_file()

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

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 89029c22ce..4854acee41 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1548,12 +1548,12 @@ static int set_config_log_file(const char *key, const char *value,
 	int ret;
 
 	if (lxc_config_value_empty(value)) {
-		free(c->logfile);
-		c->logfile = NULL;
+		free_disarm(c->logfile);
 		return 0;
 	}
 
-	/* Store these values in the lxc_conf, and then try to set for actual
+	/*
+	 * Store these values in the lxc_conf, and then try to set for actual
 	 * current logging.
 	 */
 	ret = set_config_path_item(&c->logfile, value);

From 806244c69d2faf83172efe70c7f9a5326e6a2582 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:52:05 +0100
Subject: [PATCH 13/25] confile: cleanup set_config_log_level()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 4854acee41..57ea4dc084 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1574,13 +1574,17 @@ static int set_config_log_level(const char *key, const char *value,
 	}
 
 	if (value[0] >= '0' && value[0] <= '9') {
-		if (lxc_safe_int(value, &newlevel) < 0)
-			return -1;
+		int ret;
+
+		ret = lxc_safe_int(value, &newlevel);
+		if (ret)
+			return ret_errno(EINVAL);
 	} else {
 		newlevel = lxc_log_priority_to_int(value);
 	}
 
-	/* Store these values in the lxc_conf, and then try to set for actual
+	/*
+	 * Store these values in the lxc_conf, and then try to set for actual
 	 * current logging.
 	 */
 	lxc_conf->loglevel = newlevel;

From 0c48b874fda6f23bee0a438ca67b4dc0a1e98dcb Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:52:42 +0100
Subject: [PATCH 14/25] confile: cleanup set_config_log_level()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 57ea4dc084..7f42b9b1f5 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1595,16 +1595,19 @@ static int set_config_log_level(const char *key, const char *value,
 static int set_config_autodev(const char *key, const char *value,
 			      struct lxc_conf *lxc_conf, void *data)
 {
+	int ret;
+
 	if (lxc_config_value_empty(value)) {
 		lxc_conf->autodev = 0;
 		return 0;
 	}
 
-	if (lxc_safe_uint(value, &lxc_conf->autodev) < 0)
-		return -1;
+	ret = lxc_safe_uint(value, &lxc_conf->autodev);
+	if (ret)
+		return ret_errno(EINVAL);
 
 	if (lxc_conf->autodev > 1)
-		return -1;
+		return ret_errno(EINVAL);
 
 	return 0;
 }

From d12fabf8d61072d248a430edac8f6c06f6f6dcfa Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:53:11 +0100
Subject: [PATCH 15/25] confile: cleanup set_config_signal_halt()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 7f42b9b1f5..5597c3928b 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1638,7 +1638,7 @@ static int set_config_signal_halt(const char *key, const char *value,
 
 	sig_n = sig_parse(value);
 	if (sig_n < 0)
-		return -1;
+		return ret_errno(EINVAL);
 
 	lxc_conf->haltsignal = sig_n;
 

From 7d6b1a204af66bd3b4130b11aa5777484a1d7ca2 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:53:32 +0100
Subject: [PATCH 16/25] confile: cleanup set_config_signal_reboot()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 5597c3928b..00e37a89e0 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1657,7 +1657,7 @@ static int set_config_signal_reboot(const char *key, const char *value,
 
 	sig_n = sig_parse(value);
 	if (sig_n < 0)
-		return -1;
+		return ret_errno(EINVAL);
 
 	lxc_conf->rebootsignal = sig_n;
 

From c4d9b159421e251ee5afa065eb78a2a8cef6b063 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 14:53:52 +0100
Subject: [PATCH 17/25] confile: cleanup set_config_signal_stop()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 00e37a89e0..b3e1c2adef 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1676,7 +1676,7 @@ static int set_config_signal_stop(const char *key, const char *value,
 
 	sig_n = sig_parse(value);
 	if (sig_n < 0)
-		return -1;
+		return ret_errno(EINVAL);
 
 	lxc_conf->stopsignal = sig_n;
 

From ee91fa0616a47490b0eb0a71a46aebbdf9c7abe3 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 15:03:15 +0100
Subject: [PATCH 18/25] confile: cleanup __set_config_cgroup_controller()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/conf.h    | 11 +++++++++++
 src/lxc/confile.c | 31 +++++++++++--------------------
 2 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index 907cbdfa52..92b7ac86bb 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -19,6 +19,7 @@
 #include "config.h"
 #include "list.h"
 #include "lxcseccomp.h"
+#include "memory_utils.h"
 #include "ringbuf.h"
 #include "start.h"
 #include "terminal.h"
@@ -69,6 +70,16 @@ struct lxc_cgroup {
 	};
 };
 
+static void free_lxc_cgroup(struct lxc_cgroup *ptr)
+{
+	if (ptr) {
+		free(ptr->subsystem);
+		free(ptr->value);
+		free_disarm(ptr);
+	}
+}
+define_cleanup_function(struct lxc_cgroup *, free_lxc_cgroup);
+
 #if !HAVE_SYS_RESOURCE_H
 #define RLIM_INFINITY ((unsigned long)-1)
 struct rlimit {
diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index b3e1c2adef..f6fb3bd276 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1686,10 +1686,10 @@ static int set_config_signal_stop(const char *key, const char *value,
 static int __set_config_cgroup_controller(const char *key, const char *value,
 					  struct lxc_conf *lxc_conf, int version)
 {
+	__do_free struct lxc_list *cglist = NULL;
+	call_cleaner(free_lxc_cgroup) struct lxc_cgroup *cgelem = NULL;
 	const char *subkey, *token;
 	size_t token_len;
-	struct lxc_list *cglist = NULL;
-	struct lxc_cgroup *cgelem = NULL;
 
 	if (lxc_config_value_empty(value))
 		return lxc_clear_cgroups(lxc_conf, key, version);
@@ -1701,53 +1701,44 @@ static int __set_config_cgroup_controller(const char *key, const char *value,
 		token = "lxc.cgroup.";
 		token_len = 11;
 	} else {
-		return -EINVAL;
+		return ret_errno(EINVAL);
 	}
 
 	if (strncmp(key, token, token_len) != 0)
-		return -EINVAL;
+		return ret_errno(EINVAL);
 
 	subkey = key + token_len;
 	if (*subkey == '\0')
-		return -EINVAL;
+		return ret_errno(EINVAL);
 
 	cglist = malloc(sizeof(*cglist));
 	if (!cglist)
-		goto out;
+		return ret_errno(ENOMEM);
 
 	cgelem = malloc(sizeof(*cgelem));
 	if (!cgelem)
-		goto out;
+		return ret_errno(ENOMEM);
 	memset(cgelem, 0, sizeof(*cgelem));
 
 	cgelem->subsystem = strdup(subkey);
 	if (!cgelem->subsystem)
-		goto out;
+		return ret_errno(ENOMEM);
 
 	cgelem->value = strdup(value);
 	if (!cgelem->value)
-		goto out;
+		return ret_errno(ENOMEM);
 
 	cgelem->version = version;
 
-	lxc_list_add_elem(cglist, cgelem);
+	lxc_list_add_elem(cglist, move_ptr(cgelem));
 
 	if (version == CGROUP2_SUPER_MAGIC)
 		lxc_list_add_tail(&lxc_conf->cgroup2, cglist);
 	else
 		lxc_list_add_tail(&lxc_conf->cgroup, cglist);
+	move_ptr(cglist);
 
 	return 0;
-
-out:
-	free(cglist);
-	if (cgelem) {
-		free(cgelem->subsystem);
-		free(cgelem->value);
-		free(cgelem);
-	}
-
-	return -1;
 }
 
 static int set_config_cgroup_controller(const char *key, const char *value,

From c521771abbb95b08b61e7db6cdada779ea3d1e04 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 15:04:31 +0100
Subject: [PATCH 19/25] confile: cleanup set_config_cgroup_relative()

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

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index f6fb3bd276..544c491346 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1822,8 +1822,8 @@ static int set_config_cgroup_relative(const char *key, const char *value,
 		return clr_config_cgroup_relative(key, lxc_conf, NULL);
 
 	ret = lxc_safe_uint(value, &converted);
-	if (ret < 0)
-		return -ret;
+	if (ret)
+		return ret;
 
 	if (converted == 1) {
 		lxc_conf->cgroup_meta.relative = true;
@@ -1835,7 +1835,7 @@ static int set_config_cgroup_relative(const char *key, const char *value,
 		return 0;
 	}
 
-	return -EINVAL;
+	return ret_errno(EINVAL);
 }
 
 static bool parse_limit_value(const char **value, rlim_t *res)

From 8fa831e0dce6a1ed323e8fc3de2cce74d5fb4bcb Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 15:09:37 +0100
Subject: [PATCH 20/25] confile: cleanup set_config_prlimit()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/conf.h    |  9 +++++++++
 src/lxc/confile.c | 34 ++++++++++++----------------------
 2 files changed, 21 insertions(+), 22 deletions(-)

diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index 92b7ac86bb..b06b547434 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -98,6 +98,15 @@ struct lxc_limit {
 	struct rlimit limit;
 };
 
+static void free_lxc_limit(struct lxc_limit *ptr)
+{
+	if (ptr) {
+		free(ptr->resource);
+		free_disarm(ptr);
+	}
+}
+define_cleanup_function(struct lxc_limit *, free_lxc_limit);
+
 enum idtype {
 	ID_TYPE_UID,
 	ID_TYPE_GID
diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 544c491346..0ffd15e263 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1861,23 +1861,23 @@ static bool parse_limit_value(const char **value, rlim_t *res)
 static int set_config_prlimit(const char *key, const char *value,
 			    struct lxc_conf *lxc_conf, void *data)
 {
+	__do_free struct lxc_list *limlist = NULL;
+	call_cleaner(free_lxc_limit) struct lxc_limit *limelem = NULL;
 	struct lxc_list *iter;
 	struct rlimit limit;
 	rlim_t limit_value;
-	struct lxc_list *limlist = NULL;
-	struct lxc_limit *limelem = NULL;
 
 	if (lxc_config_value_empty(value))
 		return lxc_clear_limits(lxc_conf, key);
 
 	if (strncmp(key, "lxc.prlimit.", STRLITERALLEN("lxc.prlimit.")) != 0)
-		return -1;
+		return ret_errno(EINVAL);
 
 	key += STRLITERALLEN("lxc.prlimit.");
 
 	/* soft limit comes first in the value */
 	if (!parse_limit_value(&value, &limit_value))
-		return -1;
+		return ret_errno(EINVAL);
 
 	limit.rlim_cur = limit_value;
 
@@ -1888,7 +1888,7 @@ static int set_config_prlimit(const char *key, const char *value,
 	if (*value == ':')
 		++value;
 	else if (*value) /* any other character is an error here */
-		return -1;
+		return ret_errno(EINVAL);
 
 	while (isspace(*value))
 		++value;
@@ -1896,7 +1896,7 @@ static int set_config_prlimit(const char *key, const char *value,
 	/* optional hard limit */
 	if (*value) {
 		if (!parse_limit_value(&value, &limit_value))
-			return -1;
+			return ret_errno(EINVAL);
 
 		limit.rlim_max = limit_value;
 
@@ -1905,7 +1905,7 @@ static int set_config_prlimit(const char *key, const char *value,
 			++value;
 
 		if (*value)
-			return -1;
+			return ret_errno(EINVAL);
 	} else {
 		/* a single value sets both hard and soft limit */
 		limit.rlim_max = limit.rlim_cur;
@@ -1923,32 +1923,22 @@ static int set_config_prlimit(const char *key, const char *value,
 	/* allocate list element */
 	limlist = malloc(sizeof(*limlist));
 	if (!limlist)
-		goto on_error;
+		return ret_errno(ENOMEM);
 
 	limelem = malloc(sizeof(*limelem));
 	if (!limelem)
-		goto on_error;
+		return ret_errno(ENOMEM);
 	memset(limelem, 0, sizeof(*limelem));
 
 	limelem->resource = strdup(key);
 	if (!limelem->resource)
-		goto on_error;
+		return ret_errno(ENOMEM);
 
 	limelem->limit = limit;
-	lxc_list_add_elem(limlist, limelem);;
-	lxc_list_add_tail(&lxc_conf->limits, limlist);
+	lxc_list_add_elem(limlist, move_ptr(limelem));;
+	lxc_list_add_tail(&lxc_conf->limits, move_ptr(limlist));
 
 	return 0;
-
-on_error:
-	free(limlist);
-
-	if (limelem) {
-		free(limelem->resource);
-		free(limelem);
-	}
-
-	return -1;
 }
 
 static int set_config_sysctl(const char *key, const char *value,

From f10c80d258c89e8724d6376e1dc3998d8490eaee Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 15:13:41 +0100
Subject: [PATCH 21/25] confile: cleanup set_config_sysctl()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/conf.h    | 10 ++++++++++
 src/lxc/confile.c | 34 ++++++++++++----------------------
 2 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index b06b547434..1087a75329 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -122,6 +122,16 @@ struct lxc_sysctl {
 	char *value;
 };
 
+static void free_lxc_sysctl(struct lxc_sysctl *ptr)
+{
+	if (ptr) {
+		free(ptr->key);
+		free(ptr->value);
+		free_disarm(ptr);
+	}
+}
+define_cleanup_function(struct lxc_sysctl *, free_lxc_sysctl);
+
 /*
  * Defines a structure to configure proc filesystem at runtime.
  * @filename : the proc filesystem will be configured without the "lxc.proc" prefix
diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 0ffd15e263..63435f56b1 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -1944,10 +1944,9 @@ static int set_config_prlimit(const char *key, const char *value,
 static int set_config_sysctl(const char *key, const char *value,
 			    struct lxc_conf *lxc_conf, void *data)
 {
+	__do_free struct lxc_list *sysctl_list = NULL;
+	call_cleaner(free_lxc_sysctl) struct lxc_sysctl *sysctl_elem = NULL;
 	struct lxc_list *iter;
-	char *replace_value = NULL;
-	struct lxc_list *sysctl_list = NULL;
-	struct lxc_sysctl *sysctl_elem = NULL;
 
 	if (lxc_config_value_empty(value))
 		return clr_config_sysctl(key, lxc_conf, NULL);
@@ -1959,6 +1958,8 @@ static int set_config_sysctl(const char *key, const char *value,
 
 	/* find existing list element */
 	lxc_list_for_each(iter, &lxc_conf->sysctls) {
+		__do_free char *replace_value = NULL;
+
 		sysctl_elem = iter->elem;
 
 		if (strcmp(key, sysctl_elem->key) != 0)
@@ -1966,10 +1967,10 @@ static int set_config_sysctl(const char *key, const char *value,
 
 		replace_value = strdup(value);
 		if (!replace_value)
-			return -1;
+			return ret_errno(EINVAL);
 
 		free(sysctl_elem->value);
-		sysctl_elem->value = replace_value;
+		sysctl_elem->value = move_ptr(replace_value);
 
 		return 0;
 	}
@@ -1977,36 +1978,25 @@ static int set_config_sysctl(const char *key, const char *value,
 	/* allocate list element */
 	sysctl_list = malloc(sizeof(*sysctl_list));
 	if (!sysctl_list)
-		goto on_error;
+		return ret_errno(ENOMEM);
 
 	sysctl_elem = malloc(sizeof(*sysctl_elem));
 	if (!sysctl_elem)
-		goto on_error;
+		return ret_errno(ENOMEM);
 	memset(sysctl_elem, 0, sizeof(*sysctl_elem));
 
 	sysctl_elem->key = strdup(key);
 	if (!sysctl_elem->key)
-		goto on_error;
+		return ret_errno(ENOMEM);
 
 	sysctl_elem->value = strdup(value);
 	if (!sysctl_elem->value)
-		goto on_error;
+		return ret_errno(ENOMEM);
 
-	lxc_list_add_elem(sysctl_list, sysctl_elem);
-	lxc_list_add_tail(&lxc_conf->sysctls, sysctl_list);
+	lxc_list_add_elem(sysctl_list, move_ptr(sysctl_elem));
+	lxc_list_add_tail(&lxc_conf->sysctls, move_ptr(sysctl_list));
 
 	return 0;
-
-on_error:
-	free(sysctl_list);
-
-	if (sysctl_elem) {
-		free(sysctl_elem->key);
-		free(sysctl_elem->value);
-		free(sysctl_elem);
-	}
-
-	return -1;
 }
 
 static int set_config_proc(const char *key, const char *value,

From 83332c2473747d9b767be6dd31cac698da733b8d Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 15:19:33 +0100
Subject: [PATCH 22/25] confile: cleanup set_config_proc()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/conf.h    | 10 ++++++++++
 src/lxc/confile.c | 34 ++++++++++++----------------------
 2 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index 1087a75329..116479df94 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -142,6 +142,16 @@ struct lxc_proc {
 	char *value;
 };
 
+static void free_lxc_proc(struct lxc_proc *ptr)
+{
+	if (ptr) {
+		free(ptr->filename);
+		free(ptr->value);
+		free_disarm(ptr);
+	}
+}
+define_cleanup_function(struct lxc_proc *, free_lxc_proc);
+
 /*
  * id_map is an id map entry.  Form in confile is:
  * lxc.idmap = u 0    9800 100
diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 63435f56b1..a737bd778f 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -2002,9 +2002,9 @@ static int set_config_sysctl(const char *key, const char *value,
 static int set_config_proc(const char *key, const char *value,
 			    struct lxc_conf *lxc_conf, void *data)
 {
+	__do_free struct lxc_list *proclist = NULL;
+	call_cleaner(free_lxc_proc) struct lxc_proc *procelem = NULL;
 	const char *subkey;
-	struct lxc_list *proclist = NULL;
-	struct lxc_proc *procelem = NULL;
 
 	if (lxc_config_value_empty(value))
 		return clr_config_proc(key, lxc_conf, NULL);
@@ -2014,39 +2014,29 @@ static int set_config_proc(const char *key, const char *value,
 
 	subkey = key + STRLITERALLEN("lxc.proc.");
 	if (*subkey == '\0')
-		return -EINVAL;
+		return ret_errno(EINVAL);
 
 	proclist = malloc(sizeof(*proclist));
 	if (!proclist)
-		goto on_error;
+		return ret_errno(ENOMEM);
 
 	procelem = malloc(sizeof(*procelem));
 	if (!procelem)
-		goto on_error;
+		return ret_errno(ENOMEM);
 	memset(procelem, 0, sizeof(*procelem));
 
 	procelem->filename = strdup(subkey);
-	procelem->value = strdup(value);
-
-	if (!procelem->filename || !procelem->value)
-		goto on_error;
+	if (!procelem->filename)
+		return ret_errno(ENOMEM);
 
-	proclist->elem = procelem;
+	procelem->value = strdup(value);
+	if (!procelem->value)
+		return ret_errno(ENOMEM);
 
-	lxc_list_add_tail(&lxc_conf->procs, proclist);
+	proclist->elem = move_ptr(procelem);
+	lxc_list_add_tail(&lxc_conf->procs, move_ptr(proclist));
 
 	return 0;
-
-on_error:
-	free(proclist);
-
-	if (procelem) {
-		free(procelem->filename);
-		free(procelem->value);
-		free(procelem);
-	}
-
-	return -1;
 }
 
 static int set_config_idmaps(const char *key, const char *value,

From d1554a300e7bf05d80b90a547756c7b970b095ca Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 15:23:51 +0100
Subject: [PATCH 23/25] confile: cleanup set_config_idmaps()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index a737bd778f..d74fb55d05 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -2042,29 +2042,27 @@ static int set_config_proc(const char *key, const char *value,
 static int set_config_idmaps(const char *key, const char *value,
 			     struct lxc_conf *lxc_conf, void *data)
 {
+	__do_free struct lxc_list *idmaplist = NULL;
+	__do_free struct id_map *idmap = NULL;
 	unsigned long hostid, nsid, range;
 	char type;
 	int ret;
-	struct lxc_list *idmaplist = NULL;
-	struct id_map *idmap = NULL;
 
 	if (lxc_config_value_empty(value))
 		return lxc_clear_idmaps(lxc_conf);
 
 	idmaplist = malloc(sizeof(*idmaplist));
 	if (!idmaplist)
-		goto on_error;
+		return ret_errno(ENOMEM);
 
 	idmap = malloc(sizeof(*idmap));
 	if (!idmap)
-		goto on_error;
+		return ret_errno(ENOMEM);
 	memset(idmap, 0, sizeof(*idmap));
 
 	ret = parse_idmaps(value, &type, &nsid, &hostid, &range);
-	if (ret < 0) {
-		ERROR("Failed to parse id mappings");
-		goto on_error;
-	}
+	if (ret < 0)
+		return log_error_errno(-EINVAL, EINVAL, "Failed to parse id mappings");
 
 	INFO("Read uid map: type %c nsid %lu hostid %lu range %lu", type, nsid, hostid, range);
 	if (type == 'u')
@@ -2072,13 +2070,13 @@ static int set_config_idmaps(const char *key, const char *value,
 	else if (type == 'g')
 		idmap->idtype = ID_TYPE_GID;
 	else
-		goto on_error;
+		return ret_errno(EINVAL);
 
 	idmap->hostid = hostid;
 	idmap->nsid = nsid;
 	idmap->range = range;
-	idmaplist->elem = idmap;
-	lxc_list_add_tail(&lxc_conf->id_map, idmaplist);
+	idmaplist->elem = move_ptr(idmap);
+	lxc_list_add_tail(&lxc_conf->id_map, move_ptr(idmaplist));
 
 	if (!lxc_conf->root_nsuid_map && idmap->idtype == ID_TYPE_UID)
 		if (idmap->nsid == 0)
@@ -2088,15 +2086,7 @@ static int set_config_idmaps(const char *key, const char *value,
 		if (idmap->nsid == 0)
 			lxc_conf->root_nsgid_map = idmap;
 
-	idmap = NULL;
-
 	return 0;
-
-on_error:
-	free(idmaplist);
-	free(idmap);
-
-	return -1;
 }
 
 static int set_config_mount_fstab(const char *key, const char *value,

From 760263a8a93d4d8aad9d0211d9cafbde062c342e Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 15:24:25 +0100
Subject: [PATCH 24/25] confile: cleanup set_config_mount_fstab()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index d74fb55d05..29eb350071 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -2094,7 +2094,7 @@ static int set_config_mount_fstab(const char *key, const char *value,
 {
 	if (lxc_config_value_empty(value)) {
 		clr_config_mount_fstab(key, lxc_conf, NULL);
-		return -1;
+		return ret_errno(EINVAL);
 	}
 
 	return set_config_path_item(&lxc_conf->fstab, value);

From ea05f3e2db8f38853f4badd98a61d0848e18ff9d Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 8 Dec 2020 15:39:35 +0100
Subject: [PATCH 25/25] confile: cleanup set_config_mount_auto()

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/confile.c | 117 +++++++++++++++++++++-------------------------
 1 file changed, 54 insertions(+), 63 deletions(-)

diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 29eb350071..8dbc8ee05f 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -2103,43 +2103,44 @@ static int set_config_mount_fstab(const char *key, const char *value,
 static int set_config_mount_auto(const char *key, const char *value,
 				 struct lxc_conf *lxc_conf, void *data)
 {
-	char *autos, *token;
+	__do_free char *autos = NULL;
+	char *token;
 	int i;
-	int ret = -1;
 	static struct {
 		const char *token;
 		int mask;
 		int flag;
 	} allowed_auto_mounts[] = {
-	    { "proc",                    LXC_AUTO_PROC_MASK,   LXC_AUTO_PROC_MIXED                                 },
-	    { "proc:mixed",              LXC_AUTO_PROC_MASK,   LXC_AUTO_PROC_MIXED                                 },
-	    { "proc:rw",                 LXC_AUTO_PROC_MASK,   LXC_AUTO_PROC_RW                                    },
-	    { "sys",                     LXC_AUTO_SYS_MASK,    LXC_AUTO_SYS_MIXED                                  },
-	    { "sys:ro",                  LXC_AUTO_SYS_MASK,    LXC_AUTO_SYS_RO                                     },
-	    { "sys:mixed",               LXC_AUTO_SYS_MASK,    LXC_AUTO_SYS_MIXED                                  },
-	    { "sys:rw",                  LXC_AUTO_SYS_MASK,    LXC_AUTO_SYS_RW                                     },
-	    { "cgroup",                  LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_NOSPEC                              },
-	    { "cgroup:mixed",            LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_MIXED                               },
-	    { "cgroup:ro",               LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_RO                                  },
-	    { "cgroup:rw",               LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_RW                                  },
-	    { "cgroup:force",            LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_NOSPEC | LXC_AUTO_CGROUP_FORCE      },
-	    { "cgroup:mixed:force",      LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_MIXED | LXC_AUTO_CGROUP_FORCE       },
-	    { "cgroup:ro:force",         LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_RO | LXC_AUTO_CGROUP_FORCE          },
-	    { "cgroup:rw:force",         LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_RW | LXC_AUTO_CGROUP_FORCE          },
-	    { "cgroup-full",             LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_NOSPEC                         },
-	    { "cgroup-full:mixed",       LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_MIXED                          },
-	    { "cgroup-full:ro",          LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RO                             },
-	    { "cgroup-full:rw",          LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RW                             },
-	    { "cgroup-full:force",       LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_NOSPEC | LXC_AUTO_CGROUP_FORCE },
-	    { "cgroup-full:mixed:force", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_MIXED | LXC_AUTO_CGROUP_FORCE  },
-	    { "cgroup-full:ro:force",    LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RO | LXC_AUTO_CGROUP_FORCE     },
-	    { "cgroup-full:rw:force",    LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RW | LXC_AUTO_CGROUP_FORCE     },
-	    { "shmounts:",               LXC_AUTO_SHMOUNTS_MASK, LXC_AUTO_SHMOUNTS                                 },
-	    /* For adding anything that is just a single on/off, but has no
-	    *  options: keep mask and flag identical and just define the enum
-	    *  value as an unused bit so far
-	     */
-	    { NULL,                      0,                    0                                              }
+		{ "proc",			LXC_AUTO_PROC_MASK,	LXC_AUTO_PROC_MIXED					},
+		{ "proc:mixed",			LXC_AUTO_PROC_MASK,	LXC_AUTO_PROC_MIXED					},
+		{ "proc:rw",			LXC_AUTO_PROC_MASK,	LXC_AUTO_PROC_RW					},
+		{ "sys",			LXC_AUTO_SYS_MASK,	LXC_AUTO_SYS_MIXED					},
+		{ "sys:ro",			LXC_AUTO_SYS_MASK,	LXC_AUTO_SYS_RO						},
+		{ "sys:mixed",			LXC_AUTO_SYS_MASK,	LXC_AUTO_SYS_MIXED					},
+		{ "sys:rw",			LXC_AUTO_SYS_MASK,	LXC_AUTO_SYS_RW						},
+		{ "cgroup",			LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_NOSPEC					},
+		{ "cgroup:mixed",		LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_MIXED					},
+		{ "cgroup:ro",			LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_RO					},
+		{ "cgroup:rw",			LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_RW					},
+		{ "cgroup:force",		LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_NOSPEC | LXC_AUTO_CGROUP_FORCE		},
+		{ "cgroup:mixed:force",		LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_MIXED | LXC_AUTO_CGROUP_FORCE		},
+		{ "cgroup:ro:force",		LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_RO | LXC_AUTO_CGROUP_FORCE		},
+		{ "cgroup:rw:force",		LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_RW | LXC_AUTO_CGROUP_FORCE		},
+		{ "cgroup-full",		LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_FULL_NOSPEC				},
+		{ "cgroup-full:mixed",		LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_FULL_MIXED				},
+		{ "cgroup-full:ro",		LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_FULL_RO					},
+		{ "cgroup-full:rw",		LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_FULL_RW					},
+		{ "cgroup-full:force",		LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_FULL_NOSPEC | LXC_AUTO_CGROUP_FORCE	},
+		{ "cgroup-full:mixed:force",	LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_FULL_MIXED | LXC_AUTO_CGROUP_FORCE	},
+		{ "cgroup-full:ro:force",	LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_FULL_RO | LXC_AUTO_CGROUP_FORCE		},
+		{ "cgroup-full:rw:force",	LXC_AUTO_CGROUP_MASK,	LXC_AUTO_CGROUP_FULL_RW | LXC_AUTO_CGROUP_FORCE		},
+		{ "shmounts:",			LXC_AUTO_SHMOUNTS_MASK,	LXC_AUTO_SHMOUNTS					},
+		/*
+		 * For adding anything that is just a single on/off, but has no
+		 * options: keep mask and flag identical and just define the
+		 * enum value as an unused bit so far
+		 */
+		{ NULL,				0,			0							}
 	};
 
 	if (lxc_config_value_empty(value)) {
@@ -2149,7 +2150,7 @@ static int set_config_mount_auto(const char *key, const char *value,
 
 	autos = strdup(value);
 	if (!autos)
-		return -1;
+		return ret_errno(ENOMEM);
 
 	lxc_iterate_parts(token, autos, " \t") {
 		bool is_shmounts = false;
@@ -2165,50 +2166,40 @@ static int set_config_mount_auto(const char *key, const char *value,
 			}
 		}
 
-		if (!allowed_auto_mounts[i].token) {
-			ERROR("Invalid filesystem to automount \"%s\"", token);
-			goto on_error;
-		}
+		if (!allowed_auto_mounts[i].token)
+			return log_error_errno(-EINVAL, EINVAL, "Invalid filesystem to automount \"%s\"", token);
 
 		lxc_conf->auto_mounts &= ~allowed_auto_mounts[i].mask;
 		lxc_conf->auto_mounts |= allowed_auto_mounts[i].flag;
 
 		if (is_shmounts) {
-			char *container_path;
-			char *host_path;
+			__do_free char *container_path = NULL, *host_path = NULL;
+			char *val;
 
-			host_path = token + STRLITERALLEN("shmounts:");
-			if (*host_path == '\0') {
-				SYSERROR("Failed to copy shmounts host path");
-				goto on_error;
-			}
+			val = token + STRLITERALLEN("shmounts:");
+			if (*val == '\0')
+				return log_error_errno(-EINVAL, EINVAL, "Failed to copy shmounts host path");
+
+			host_path = strdup(val);
+			if (!host_path)
+				return log_error_errno(-EINVAL, EINVAL, "Failed to copy shmounts host path");
 
-			container_path = strchr(host_path, ':');
-			if (!container_path || *(container_path + 1) == '\0')
-				container_path = "/dev/.lxc-mounts";
+			val = strchr(host_path, ':');
+			if (!val || *(val + 1) == '\0')
+				val = "/dev/.lxc-mounts";
 			else
-				*container_path++ = '\0';
+				*val++ = '\0';
 
-			lxc_conf->shmount.path_host = strdup(host_path);
-			if (!lxc_conf->shmount.path_host) {
-				SYSERROR("Failed to copy shmounts host path");
-				goto on_error;
-			}
+			container_path = strdup(val);
+			if(!container_path)
+				return log_error_errno(-EINVAL, EINVAL, "Failed to copy shmounts container path");
 
-			lxc_conf->shmount.path_cont = strdup(container_path);
-			if(!lxc_conf->shmount.path_cont) {
-				SYSERROR("Failed to copy shmounts container path");
-				goto on_error;
-			}
+			lxc_conf->shmount.path_host = move_ptr(host_path);
+			lxc_conf->shmount.path_cont = move_ptr(container_path);
 		}
 	}
 
-	ret = 0;
-
-on_error:
-	free(autos);
-
-	return ret;
+	return 0;
 }
 
 static int set_config_mount(const char *key, const char *value,


More information about the lxc-devel mailing list