[lxc-devel] [lxc/master] cgfsng: coding style + fixes

brauner on Github lxc-bot at linuxcontainers.org
Sat Feb 17 18:51:12 UTC 2018


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/20180217/803ff173/attachment.bin>
-------------- next part --------------
From 438c4581b068db39e88db570294a852ecc31092f Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 16:32:16 +0100
Subject: [PATCH 01/56] cgfsng: order includes

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index c13f7fa2f..17dfd5e8c 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -44,10 +44,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <sys/types.h>
-
-#include <linux/types.h>
 #include <linux/kdev_t.h>
+#include <linux/types.h>
+#include <sys/types.h>
 
 #include "caps.h"
 #include "cgroup.h"

From 9e28830178eaba12336f0d32a9b2389377c3e9be Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 16:37:35 +0100
Subject: [PATCH 02/56] cgfsng: fully document struct hierarchy

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 17dfd5e8c..37f009e06 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -61,15 +61,34 @@ lxc_log_define(lxc_cgfsng, lxc);
 
 static struct cgroup_ops cgfsng_ops;
 
-/*
- * A descriptor for a mounted hierarchy
- * @controllers: either NULL, or a null-terminated list of all
- *   the co-mounted controllers
- * @mountpoint: the mountpoint we will use.  It will be either
- *   /sys/fs/cgroup/controller or /sys/fs/cgroup/controllerlist
- * @base_cgroup: the cgroup under which the container cgroup path
-     is created.  This will be either the caller's cgroup (if not
-     root), or init's cgroup (if root).
+/* A descriptor for a mounted hierarchy
+ * @controllers:
+ * - legacy hierarchy:
+ *   Either NULL, or a null-terminated list of all the co-mounted controllers.
+ * - unified hierarchy:
+ *   Either NULL, or a null-terminated list of all enabled controllers.
+ * @mountpoint:
+ * - The mountpoint we will use.
+ * - legacy hierarchy:
+ *   It will be either /sys/fs/cgroup/controller or
+ *   /sys/fs/cgroup/controllerlist.
+ * - unified hierarchy:
+ *   It will either be /sys/fs/cgroup or /sys/fs/cgroup/<mountpoint-name>
+ *   depending on whether this is a hybrid cgroup layout (mix of legacy and
+ *   unified hierarchies) or a pure unified cgroup layout.
+ * @base_cgroup:
+ * - The cgroup under which the container cgroup path
+ *   is created. This will be either the caller's cgroup (if not root), or
+ *   init's cgroup (if root).
+ * @fullcgpath:
+ * - The full path to the containers cgroup.
+ * @version:
+ * - legacy hierarchy:
+ *   If the hierarchy is a legacy hierarchy this will be set to
+ *   CGROUP_SUPER_MAGIC.
+ * - unified hierarchy:
+ *   If the hierarchy is a legacy hierarchy this will be set to
+ *   CGROUP2_SUPER_MAGIC.
  */
 struct hierarchy {
 	char **controllers;

From 16a2cde9e036f8245392b0e257b830d083dfb728 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 16:45:01 +0100
Subject: [PATCH 03/56] cgfsng: fully document struct cgfsng_handler_data

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/cgroups/cgfsng.c | 71 ++++++++++++++++++++++++++++++++++--------------
 1 file changed, 50 insertions(+), 21 deletions(-)

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 37f009e06..bff810827 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -62,31 +62,36 @@ lxc_log_define(lxc_cgfsng, lxc);
 static struct cgroup_ops cgfsng_ops;
 
 /* A descriptor for a mounted hierarchy
- * @controllers:
- * - legacy hierarchy:
+ *
+ * @controllers
+ * - legacy hierarchy
  *   Either NULL, or a null-terminated list of all the co-mounted controllers.
- * - unified hierarchy:
+ * - unified hierarchy
  *   Either NULL, or a null-terminated list of all enabled controllers.
- * @mountpoint:
+ *
+ * @mountpoint
  * - The mountpoint we will use.
- * - legacy hierarchy:
+ * - legacy hierarchy
  *   It will be either /sys/fs/cgroup/controller or
  *   /sys/fs/cgroup/controllerlist.
- * - unified hierarchy:
+ * - unified hierarchy
  *   It will either be /sys/fs/cgroup or /sys/fs/cgroup/<mountpoint-name>
  *   depending on whether this is a hybrid cgroup layout (mix of legacy and
  *   unified hierarchies) or a pure unified cgroup layout.
- * @base_cgroup:
+ *
+ * @base_cgroup
  * - The cgroup under which the container cgroup path
  *   is created. This will be either the caller's cgroup (if not root), or
  *   init's cgroup (if root).
- * @fullcgpath:
+ *
+ * @fullcgpath
  * - The full path to the containers cgroup.
- * @version:
- * - legacy hierarchy:
+ *
+ * @version
+ * - legacy hierarchy
  *   If the hierarchy is a legacy hierarchy this will be set to
  *   CGROUP_SUPER_MAGIC.
- * - unified hierarchy:
+ * - unified hierarchy
  *   If the hierarchy is a legacy hierarchy this will be set to
  *   CGROUP2_SUPER_MAGIC.
  */
@@ -98,16 +103,40 @@ struct hierarchy {
 	int version;
 };
 
-/*
- * The cgroup data which is attached to the lxc_handler.
- * @cgroup_pattern   : A copy of the lxc.cgroup.pattern
- * @container_cgroup : If not null, the cgroup which was created for the
- *                     container. For each hierarchy, it is created under the
- *                     @hierarchy->base_cgroup directory. Relative to the
- *                     base_cgroup it is the same for all hierarchies.
- * @name             : The name of the container.
- * @cgroup_meta      : A copy of the container's cgroup information. This
- *                     overrides @cgroup_pattern.
+/* The cgroup data which is attached to the lxc_handler.
+ *
+ * @cgroup_pattern
+ * - A copy of lxc.cgroup.pattern.
+ *
+ * @container_cgroup
+ * - If not null, the cgroup which was created for the container. For each
+ *   hierarchy, it is created under the @hierarchy->base_cgroup directory.
+ *   Relative to the base_cgroup it is the same for all hierarchies.
+ *
+ * @name
+ * - The name of the container.
+ *
+ * @cgroup_meta
+ * - A copy of the container's cgroup information. This overrides
+ *   @cgroup_pattern.
+ *
+ * @cgroup_layout:
+ * - What cgroup layout the container is running with
+ *   - CGROUP_LAYOUT_UNKNOWN
+ *     The cgroup layout could not be determined. This should be treated as an
+ *     error condition.
+ *   - CGROUP_LAYOUT_LEGACY
+ *     The container is running with all controllers mounted into legacy cgroup
+ *     hierarchies.
+ *   - CGROUP_LAYOUT_HYBRID
+ *     The container is running with at least one controller mounted into a
+ *     legacy cgroup hierarchy and a mountpoint for the unified hierarchy.  The
+ *     unified hierarchy can be empty (no controllers enabled) or non-empty
+ *     (controllers enabled).
+ *   - CGROUP_LAYOUT_UNIFIED
+ *     The container is running on a pure unified cgroup hierarchy. The unified
+ *     hierarchy can be empty (no controllers enabled) or non-empty (controllers
+ *     enabled).
  */
 struct cgfsng_handler_data {
 	char *cgroup_pattern;

From 09f3bb13cc449480f0e56d55d11c31384d361600 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 16:48:08 +0100
Subject: [PATCH 04/56] cgfsng: fully document remaining variables

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/cgroups/cgfsng.c | 51 +++++++++++++++++++++++++++++++++---------------
 1 file changed, 35 insertions(+), 16 deletions(-)

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index bff810827..51aa0cb3e 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -120,8 +120,8 @@ struct hierarchy {
  * - A copy of the container's cgroup information. This overrides
  *   @cgroup_pattern.
  *
- * @cgroup_layout:
- * - What cgroup layout the container is running with
+ * @cgroup_layout
+ * - What cgroup layout the container is running with.
  *   - CGROUP_LAYOUT_UNKNOWN
  *     The cgroup layout could not be determined. This should be treated as an
  *     error condition.
@@ -147,30 +147,49 @@ struct cgfsng_handler_data {
 	cgroup_layout_t cgroup_layout;
 };
 
-/*
- * @hierarchies - a NULL-terminated array of struct hierarchy, one per
- *                legacy hierarchy. No duplicates. First sufficient, writeable
- *                mounted hierarchy wins
+/* @hierarchies
+ * - A NULL-terminated array of struct hierarchy, one per legacy hierarchy. No
+ *   duplicates. First sufficient, writeable mounted hierarchy wins.
  */
 struct hierarchy **hierarchies;
+/* Pointer to the unified hierarchy in the null terminated list @hierarchies.
+ * This is merely a convenience for hybrid cgroup layouts to easily retrieve the
+ * unified hierarchy without iterating throught @hierarchies.
+ */
 struct hierarchy *unified;
-cgroup_layout_t cgroup_layout;
-
 /*
- * @cgroup_use - a copy of the lxc.cgroup.use
+ * @cgroup_layout
+ * - What cgroup layout the container is running with.
+ *   - CGROUP_LAYOUT_UNKNOWN
+ *     The cgroup layout could not be determined. This should be treated as an
+ *     error condition.
+ *   - CGROUP_LAYOUT_LEGACY
+ *     The container is running with all controllers mounted into legacy cgroup
+ *     hierarchies.
+ *   - CGROUP_LAYOUT_HYBRID
+ *     The container is running with at least one controller mounted into a
+ *     legacy cgroup hierarchy and a mountpoint for the unified hierarchy.  The
+ *     unified hierarchy can be empty (no controllers enabled) or non-empty
+ *     (controllers enabled).
+ *   - CGROUP_LAYOUT_UNIFIED
+ *     The container is running on a pure unified cgroup hierarchy. The unified
+ *     hierarchy can be empty (no controllers enabled) or non-empty (controllers
+ *     enabled).
  */
+cgroup_layout_t cgroup_layout;
+/* What controllers is the container supposed to use. */
 char *cgroup_use;
 
-/*
- * @lxc_cgfsng_debug - whether to print debug info to stdout for the cgfsng
- * driver
+/* @lxc_cgfsng_debug
+ * - Whether to print debug info to stdout for the cgfsng driver.
  */
 static bool lxc_cgfsng_debug;
 
-#define CGFSNG_DEBUG(format, ...) do {		\
-	if (lxc_cgfsng_debug)			\
-		printf("cgfsng: " format, ##__VA_ARGS__);	\
-} while(0)
+#define CGFSNG_DEBUG(format, ...)                                              \
+	do {                                                                   \
+		if (lxc_cgfsng_debug)                                          \
+			printf("cgfsng: " format, ##__VA_ARGS__);              \
+	} while (0)
 
 static void free_string_list(char **clist)
 {

From 2d5fe5bad08561ad561a8fed1927d463cdc90207 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 16:51:03 +0100
Subject: [PATCH 05/56] cgfsng: free_string_list()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 51aa0cb3e..fa73cb2ec 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -193,13 +193,15 @@ static bool lxc_cgfsng_debug;
 
 static void free_string_list(char **clist)
 {
-	if (clist) {
-		int i;
+	int i;
 
-		for (i = 0; clist[i]; i++)
-			free(clist[i]);
-		free(clist);
-	}
+	if (!clist)
+		return;
+
+	for (i = 0; clist[i]; i++)
+		free(clist[i]);
+
+	free(clist);
 }
 
 /* Allocate a pointer, do not fail */

From 7745483dbd34958c857d912d6c275cc47dbf013c Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 17:03:38 +0100
Subject: [PATCH 06/56] cgfsng: cg_legacy_must_prefix_named()

s/must_prefix_named/cg_legacy_must_prefix_named/

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index fa73cb2ec..62acbeca6 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -204,25 +204,27 @@ static void free_string_list(char **clist)
 	free(clist);
 }
 
-/* Allocate a pointer, do not fail */
+/* Allocate a pointer, do not fail. */
 static void *must_alloc(size_t sz)
 {
 	return must_realloc(NULL, sz);
 }
 
-/*
- * This is a special case - return a copy of @entry
- * prepending 'name='.  I.e. turn systemd into name=systemd.
- * Do not fail.
+/* Return a copy of @entry prepending "name=", i.e.  turn "systemd" into
+ * "name=systemd". Do not fail.
  */
-static char *must_prefix_named(char *entry)
+static char *cg_legacy_must_prefix_named(char *entry)
 {
-	char *ret;
-	size_t len = strlen(entry);
+	size_t len;
+	char *prefixed;
 
-	ret = must_alloc(len + 6);
-	snprintf(ret, len + 6, "name=%s", entry);
-	return ret;
+	len = strlen(entry);
+	prefixed = must_alloc(len + 6);
+
+	memcpy(prefixed, "name=", sizeof("name="));
+	memcpy(prefixed + sizeof("name="), entry, len);
+	prefixed[len + 5] = '\0';
+	return prefixed;
 }
 
 /*
@@ -292,7 +294,7 @@ static void must_append_controller(char **klist, char **nlist, char ***clist, ch
 	else if (string_in_list(klist, entry))
 		copy = must_copy_string(entry);
 	else
-		copy = must_prefix_named(entry);
+		copy = cg_legacy_must_prefix_named(entry);
 
 	(*clist)[newentry] = copy;
 }

From ac010944301152587b7beeb1027e949ddb1d7391 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 17:06:56 +0100
Subject: [PATCH 07/56] cgfsng: move cg_legacy_must_prefix_named()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 62acbeca6..cf3484cda 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -210,23 +210,6 @@ static void *must_alloc(size_t sz)
 	return must_realloc(NULL, sz);
 }
 
-/* Return a copy of @entry prepending "name=", i.e.  turn "systemd" into
- * "name=systemd". Do not fail.
- */
-static char *cg_legacy_must_prefix_named(char *entry)
-{
-	size_t len;
-	char *prefixed;
-
-	len = strlen(entry);
-	prefixed = must_alloc(len + 6);
-
-	memcpy(prefixed, "name=", sizeof("name="));
-	memcpy(prefixed + sizeof("name="), entry, len);
-	prefixed[len + 5] = '\0';
-	return prefixed;
-}
-
 /*
  * Given a pointer to a null-terminated array of pointers, realloc to
  * add one entry, and point the new entry to NULL.  Do not fail.  Return
@@ -263,6 +246,23 @@ static bool string_in_list(char **list, const char *entry)
 	return false;
 }
 
+/* Return a copy of @entry prepending "name=", i.e.  turn "systemd" into
+ * "name=systemd". Do not fail.
+ */
+static char *cg_legacy_must_prefix_named(char *entry)
+{
+	size_t len;
+	char *prefixed;
+
+	len = strlen(entry);
+	prefixed = must_alloc(len + 6);
+
+	memcpy(prefixed, "name=", sizeof("name="));
+	memcpy(prefixed + sizeof("name="), entry, len);
+	prefixed[len + 5] = '\0';
+	return prefixed;
+}
+
 /*
  * append an entry to the clist.  Do not fail.
  * *clist must be NULL the first time we are called.

From 3fd0de4d307aa9146c272a556c3b4cd10d5f1936 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 17:08:06 +0100
Subject: [PATCH 08/56] cgfsng: add me to authors

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index cf3484cda..dbd4ff2c6 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -5,6 +5,7 @@
  *
  * Authors:
  * Serge Hallyn <serge.hallyn at ubuntu.com>
+ * Christian Brauner <christian.brauner at ubuntu.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public

From 8b8db2f6af8e2c1fea02553800d7cee861c465c3 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 17:08:58 +0100
Subject: [PATCH 09/56] cgfsng: append_null_to_list()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index dbd4ff2c6..dd47ad714 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -211,18 +211,18 @@ static void *must_alloc(size_t sz)
 	return must_realloc(NULL, sz);
 }
 
-/*
- * Given a pointer to a null-terminated array of pointers, realloc to
- * add one entry, and point the new entry to NULL.  Do not fail.  Return
- * the index to the second-to-last entry - that is, the one which is
- * now available for use (keeping the list null-terminated).
+/* Given a pointer to a null-terminated array of pointers, realloc to add one
+ * entry, and point the new entry to NULL. Do not fail. Return the index to the
+ * second-to-last entry - that is, the one which is now available for use
+ * (keeping the list null-terminated).
  */
 static int append_null_to_list(void ***list)
 {
 	int newentry = 0;
 
 	if (*list)
-		for (; (*list)[newentry]; newentry++);
+		for (; (*list)[newentry]; newentry++)
+			;
 
 	*list = must_realloc(*list, (newentry + 2) * sizeof(void **));
 	(*list)[newentry + 1] = NULL;

From 8073018da72792e9504c8450a8bf2b2b2f395365 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 17:09:26 +0100
Subject: [PATCH 10/56] cgfsng: string_in_list()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index dd47ad714..9569d36b2 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -229,9 +229,8 @@ static int append_null_to_list(void ***list)
 	return newentry;
 }
 
-/*
- * Given a null-terminated array of strings, check whether @entry
- * is one of the strings
+/* Given a null-terminated array of strings, check whether @entry is one of the
+ * strings.
  */
 static bool string_in_list(char **list, const char *entry)
 {

From 42a993b4704a1981a7184b519c856d78b0a3081a Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 17:11:05 +0100
Subject: [PATCH 11/56] cgfsng: must_append_controller()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 9569d36b2..1c44d95ec 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -263,20 +263,19 @@ static char *cg_legacy_must_prefix_named(char *entry)
 	return prefixed;
 }
 
-/*
- * append an entry to the clist.  Do not fail.
- * *clist must be NULL the first time we are called.
+/* Append an entry to the clist. Do not fail. @clist must be NULL the first time
+ * we are called.
  *
- * We also handle named subsystems here.  Any controller which is not a
- * kernel subsystem, we prefix 'name='.  Any which is both a kernel and
- * named subsystem, we refuse to use because we're not sure which we
- * have here.  (TODO - we could work around this in some cases by just
- * remounting to be unambiguous, or by comparing mountpoint contents
- * with current cgroup)
+ * We also handle named subsystems here. Any controller which is not a kernel
+ * subsystem, we prefix "name=". Any which is both a kernel and named subsystem,
+ * we refuse to use because we're not sure which we have here.
+ * (TODO: We could work around this in some cases by just remounting to be
+ * unambiguous, or by comparing mountpoint contents with current cgroup.)
  *
  * The last entry will always be NULL.
  */
-static void must_append_controller(char **klist, char **nlist, char ***clist, char *entry)
+static void must_append_controller(char **klist, char **nlist, char ***clist,
+				   char *entry)
 {
 	int newentry;
 	char *copy;

From 5ae0207c84f5e295768815f4f31cb2694318dc14 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 17:12:30 +0100
Subject: [PATCH 12/56] cgfsng: get_hierarchy()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 1c44d95ec..bf0d59b3b 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -310,9 +310,8 @@ static void free_handler_data(struct cgfsng_handler_data *d)
 	free(d);
 }
 
-/*
- * Given a handler's cgroup data, return the struct hierarchy for the
- * controller @c, or NULL if there is none.
+/* Given a handler's cgroup data, return the struct hierarchy for the controller
+ * @c, or NULL if there is none.
  */
 struct hierarchy *get_hierarchy(const char *c)
 {

From d5d468f6f000128c4180a5f847ca44eaac0b7174 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 17:16:52 +0100
Subject: [PATCH 13/56] cgfsng: lxc_cpumask()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index bf0d59b3b..feeb6541c 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -401,27 +401,33 @@ static bool is_set(unsigned bit, uint32_t *bitarr)
  *
  *	0,2-3
  *
- *  into bit array
+ * into bit array
  *
  *	1 0 1 1
  */
 static uint32_t *lxc_cpumask(char *buf, size_t nbits)
 {
 	char *token;
+	size_t arrlen;
+	uint32_t *bitarr;
 	char *saveptr = NULL;
-	size_t arrlen = BITS_TO_LONGS(nbits);
-	uint32_t *bitarr = calloc(arrlen, sizeof(uint32_t));
+
+	arrlen = BITS_TO_LONGS(nbits);
+	bitarr = calloc(arrlen, sizeof(uint32_t));
 	if (!bitarr)
 		return NULL;
 
 	for (; (token = strtok_r(buf, ",", &saveptr)); buf = NULL) {
 		errno = 0;
-		unsigned start = strtoul(token, NULL, 0);
-		unsigned end = start;
+		unsigned end, start;
+		char *range;
 
-		char *range = strchr(token, '-');
+		start = strtoul(token, NULL, 0);
+		end = start;
+		range = strchr(token, '-');
 		if (range)
 			end = strtoul(range + 1, NULL, 0);
+
 		if (!(start <= end)) {
 			free(bitarr);
 			return NULL;

From 414c6719d50fec5aeeac286e78687768675bc79e Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 18:54:10 +0100
Subject: [PATCH 14/56] cgfsng: lxc_cpumask_to_cpulist()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index feeb6541c..9ca42e50b 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -448,24 +448,31 @@ static uint32_t *lxc_cpumask(char *buf, size_t nbits)
 /* Turn cpumask into simple, comma-separated cpulist. */
 static char *lxc_cpumask_to_cpulist(uint32_t *bitarr, size_t nbits)
 {
-	size_t i;
 	int ret;
-	char numstr[LXC_NUMSTRLEN64] = {0};
+	size_t i;
 	char **cpulist = NULL;
+	char numstr[LXC_NUMSTRLEN64] = {0};
 
 	for (i = 0; i <= nbits; i++) {
-		if (is_set(i, bitarr)) {
-			ret = snprintf(numstr, LXC_NUMSTRLEN64, "%zu", i);
-			if (ret < 0 || (size_t)ret >= LXC_NUMSTRLEN64) {
-				lxc_free_array((void **)cpulist, free);
-				return NULL;
-			}
-			if (lxc_append_string(&cpulist, numstr) < 0) {
-				lxc_free_array((void **)cpulist, free);
-				return NULL;
-			}
+		if (!is_set(i, bitarr))
+			continue;
+
+		ret = snprintf(numstr, LXC_NUMSTRLEN64, "%zu", i);
+		if (ret < 0 || (size_t)ret >= LXC_NUMSTRLEN64) {
+			lxc_free_array((void **)cpulist, free);
+			return NULL;
+		}
+
+		ret = lxc_append_string(&cpulist, numstr);
+		if (ret < 0) {
+			lxc_free_array((void **)cpulist, free);
+			return NULL;
 		}
 	}
+
+	if (!cpulist)
+		return NULL;
+
 	return lxc_string_join(",", (const char **)cpulist, false);
 }
 

From 333987b9e590617cd05ae3aeb893546ba3e55911 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 18:55:15 +0100
Subject: [PATCH 15/56] cgfsng: get_max_cpus()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 9ca42e50b..689661f7c 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -496,13 +496,9 @@ static ssize_t get_max_cpus(char *cpulist)
 		c2 = c1;
 	else if (c1 < c2)
 		c1 = c2;
-	else if (!c1 && c2) /* The reverse case is obvs. not needed. */
+	else if (!c1 && c2)
 		c1 = c2;
 
-	/* If the above logic is correct, c1 should always hold a valid string
-	 * here.
-	 */
-
 	errno = 0;
 	cpus = strtoul(c1, NULL, 0);
 	if (errno != 0)

From 59ac3b88d88989808ef00c258ef16520c6fa76e4 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:00:33 +0100
Subject: [PATCH 16/56] cgfsng: cg_legacy_filter_and_set_cpus()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 689661f7c..198bc7941 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -510,18 +510,17 @@ static ssize_t get_max_cpus(char *cpulist)
 #define __ISOL_CPUS "/sys/devices/system/cpu/isolated"
 static bool cg_legacy_filter_and_set_cpus(char *path, bool am_initialized)
 {
-	char *lastslash, *fpath, oldv;
 	int ret;
 	ssize_t i;
-
-	ssize_t maxposs = 0, maxisol = 0;
-	char *cpulist = NULL, *posscpus = NULL, *isolcpus = NULL;
-	uint32_t *possmask = NULL, *isolmask = NULL;
+	char *lastslash, *fpath, oldv;
+	ssize_t maxisol = 0, maxposs = 0;
+	char *cpulist = NULL, *isolcpus = NULL, *posscpus = NULL;
+	uint32_t *isolmask = NULL, *possmask = NULL;
 	bool bret = false, flipped_bit = false;
 
 	lastslash = strrchr(path, '/');
-	if (!lastslash) { /* bug...  this shouldn't be possible */
-		ERROR("Invalid path: %s.", path);
+	if (!lastslash) {
+		ERROR("Failed to detect \"/\" in \"%s\"", path);
 		return bret;
 	}
 	oldv = *lastslash;
@@ -529,7 +528,7 @@ static bool cg_legacy_filter_and_set_cpus(char *path, bool am_initialized)
 	fpath = must_make_path(path, "cpuset.cpus", NULL);
 	posscpus = read_file(fpath);
 	if (!posscpus) {
-		SYSERROR("Could not read file: %s.\n", fpath);
+		SYSERROR("Failed to read file \"%s\"", fpath);
 		goto on_error;
 	}
 
@@ -540,14 +539,14 @@ static bool cg_legacy_filter_and_set_cpus(char *path, bool am_initialized)
 
 	if (!file_exists(__ISOL_CPUS)) {
 		/* This system doesn't expose isolated cpus. */
-		DEBUG("Path: "__ISOL_CPUS" to read isolated cpus from does not exist.\n");
+		DEBUG("The path \""__ISOL_CPUS"\" to read isolated cpus from does not exist");
 		cpulist = posscpus;
 		/* No isolated cpus but we weren't already initialized by
 		 * someone. We should simply copy the parents cpuset.cpus
 		 * values.
 		 */
 		if (!am_initialized) {
-			DEBUG("Copying cpuset of parent cgroup.");
+			DEBUG("Copying cpu settings of parent cgroup");
 			goto copy_parent;
 		}
 		/* No isolated cpus but we were already initialized by someone.
@@ -558,18 +557,18 @@ static bool cg_legacy_filter_and_set_cpus(char *path, bool am_initialized)
 
 	isolcpus = read_file(__ISOL_CPUS);
 	if (!isolcpus) {
-		SYSERROR("Could not read file "__ISOL_CPUS);
+		SYSERROR("Failed to read file \""__ISOL_CPUS"\"");
 		goto on_error;
 	}
 	if (!isdigit(isolcpus[0])) {
-		DEBUG("No isolated cpus detected.");
+		TRACE("No isolated cpus detected");
 		cpulist = posscpus;
 		/* No isolated cpus but we weren't already initialized by
 		 * someone. We should simply copy the parents cpuset.cpus
 		 * values.
 		 */
 		if (!am_initialized) {
-			DEBUG("Copying cpuset of parent cgroup.");
+			DEBUG("Copying cpu settings of parent cgroup");
 			goto copy_parent;
 		}
 		/* No isolated cpus but we were already initialized by someone.
@@ -589,32 +588,33 @@ static bool cg_legacy_filter_and_set_cpus(char *path, bool am_initialized)
 
 	possmask = lxc_cpumask(posscpus, maxposs);
 	if (!possmask) {
-		ERROR("Could not create cpumask for all possible cpus.\n");
+		ERROR("Failed to create cpumask for possible cpus");
 		goto on_error;
 	}
 
 	isolmask = lxc_cpumask(isolcpus, maxposs);
 	if (!isolmask) {
-		ERROR("Could not create cpumask for all isolated cpus.\n");
+		ERROR("Failed to create cpumask for isolated cpus");
 		goto on_error;
 	}
 
 	for (i = 0; i <= maxposs; i++) {
-		if (is_set(i, isolmask) && is_set(i, possmask)) {
-			flipped_bit = true;
-			clear_bit(i, possmask);
-		}
+		if (!is_set(i, isolmask) || !is_set(i, possmask))
+			continue;
+
+		flipped_bit = true;
+		clear_bit(i, possmask);
 	}
 
 	if (!flipped_bit) {
-		DEBUG("No isolated cpus present in cpuset.");
+		DEBUG("No isolated cpus present in cpuset");
 		goto on_success;
 	}
-	DEBUG("Removed isolated cpus from cpuset.");
+	DEBUG("Removed isolated cpus from cpuset");
 
 	cpulist = lxc_cpumask_to_cpulist(possmask, maxposs);
 	if (!cpulist) {
-		ERROR("Could not create cpu list.\n");
+		ERROR("Failed to create cpu list");
 		goto on_error;
 	}
 
@@ -624,7 +624,7 @@ static bool cg_legacy_filter_and_set_cpus(char *path, bool am_initialized)
 	fpath = must_make_path(path, "cpuset.cpus", NULL);
 	ret = lxc_write_to_file(fpath, cpulist, strlen(cpulist), false);
 	if (ret < 0) {
-		SYSERROR("Could not write cpu list to: %s.\n", fpath);
+		SYSERROR("Failed to write cpu list to \"%s\"", fpath);
 		goto on_error;
 	}
 

From b095a8ebbbcc2d86c4c98ff8f92d41280118d60d Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:04:05 +0100
Subject: [PATCH 17/56] cgfsng: copy_parent_file()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 198bc7941..07ececa53 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -648,13 +648,14 @@ static bool cg_legacy_filter_and_set_cpus(char *path, bool am_initialized)
 /* Copy contents of parent(@path)/@file to @path/@file */
 static bool copy_parent_file(char *path, char *file)
 {
-	char *lastslash, *value = NULL, *fpath, oldv;
-	int len = 0;
 	int ret;
+	char *fpath, *lastslash, oldv;
+	int len = 0;
+	char *value = NULL;
 
 	lastslash = strrchr(path, '/');
-	if (!lastslash) { /* bug...  this shouldn't be possible */
-		ERROR("cgfsng:copy_parent_file: bad path %s", path);
+	if (!lastslash) {
+		ERROR("Failed to detect \"/\" in \"%s\"", path);
 		return false;
 	}
 	oldv = *lastslash;
@@ -662,22 +663,25 @@ static bool copy_parent_file(char *path, char *file)
 	fpath = must_make_path(path, file, NULL);
 	len = lxc_read_from_file(fpath, NULL, 0);
 	if (len <= 0)
-		goto bad;
+		goto on_error;
+
 	value = must_alloc(len + 1);
-	if (lxc_read_from_file(fpath, value, len) != len)
-		goto bad;
+	ret = lxc_read_from_file(fpath, value, len);
+	if (ret != len)
+		goto on_error;
 	free(fpath);
+
 	*lastslash = oldv;
 	fpath = must_make_path(path, file, NULL);
 	ret = lxc_write_to_file(fpath, value, len, false);
 	if (ret < 0)
-		SYSERROR("Unable to write %s to %s", value, fpath);
+		SYSERROR("Failed to write \"%s\" to file \"%s\"", value, fpath);
 	free(fpath);
 	free(value);
 	return ret >= 0;
 
-bad:
-	SYSERROR("Error reading '%s'", fpath);
+on_error:
+	SYSERROR("Failed to read file \"%s\"", fpath);
 	free(fpath);
 	free(value);
 	return false;

From 7793add32ce009ea13b8d3258e3f0e49a0a37cd1 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:07:56 +0100
Subject: [PATCH 18/56] cgfsng: cg_legacy_handle_cpuset_hierarchy()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 07ececa53..bdb6f666b 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -687,15 +687,16 @@ static bool copy_parent_file(char *path, char *file)
 	return false;
 }
 
-/*
- * Initialize the cpuset hierarchy in first directory of @gname and
- * set cgroup.clone_children so that children inherit settings.
- * Since the h->base_path is populated by init or ourselves, we know
- * it is already initialized.
+/* Initialize the cpuset hierarchy in first directory of @gname and set
+ * cgroup.clone_children so that children inherit settings. Since the
+ * h->base_path is populated by init or ourselves, we know it is already
+ * initialized.
  */
 static bool cg_legacy_handle_cpuset_hierarchy(struct hierarchy *h, char *cgname)
 {
-	char *cgpath, *clonechildrenpath, v, *slash;
+	int ret;
+	char v;
+	char *cgpath, *clonechildrenpath, *slash;
 
 	if (!string_in_list(h->controllers, "cpuset"))
 		return true;
@@ -709,21 +710,28 @@ static bool cg_legacy_handle_cpuset_hierarchy(struct hierarchy *h, char *cgname)
 	cgpath = must_make_path(h->mountpoint, h->base_cgroup, cgname, NULL);
 	if (slash)
 		*slash = '/';
-	if (mkdir(cgpath, 0755) < 0 && errno != EEXIST) {
-		SYSERROR("Failed to create '%s'", cgpath);
-		free(cgpath);
-		return false;
+
+	ret = mkdir(cgpath, 0755);
+	if (ret < 0) {
+		if (errno != EEXIST) {
+			SYSERROR("Failed to create directory \"%s\"", cgpath);
+			free(cgpath);
+			return false;
+		}
 	}
 
-	clonechildrenpath = must_make_path(cgpath, "cgroup.clone_children", NULL);
+	clonechildrenpath =
+	    must_make_path(cgpath, "cgroup.clone_children", NULL);
 	/* unified hierarchy doesn't have clone_children */
 	if (!file_exists(clonechildrenpath)) {
 		free(clonechildrenpath);
 		free(cgpath);
 		return true;
 	}
-	if (lxc_read_from_file(clonechildrenpath, &v, 1) < 0) {
-		SYSERROR("Failed to read '%s'", clonechildrenpath);
+
+	ret = lxc_read_from_file(clonechildrenpath, &v, 1);
+	if (ret < 0) {
+		SYSERROR("Failed to read file \"%s\"", clonechildrenpath);
 		free(clonechildrenpath);
 		free(cgpath);
 		return false;
@@ -731,14 +739,15 @@ static bool cg_legacy_handle_cpuset_hierarchy(struct hierarchy *h, char *cgname)
 
 	/* Make sure any isolated cpus are removed from cpuset.cpus. */
 	if (!cg_legacy_filter_and_set_cpus(cgpath, v == '1')) {
-		SYSERROR("Failed to remove isolated cpus.");
+		SYSERROR("Failed to remove isolated cpus");
 		free(clonechildrenpath);
 		free(cgpath);
 		return false;
 	}
 
-	if (v == '1') {  /* already set for us by someone else */
-		DEBUG("\"cgroup.clone_children\" was already set to \"1\".");
+	/* Already set for us by someone else. */
+	if (v == '1') {
+		DEBUG("\"cgroup.clone_children\" was already set to \"1\"");
 		free(clonechildrenpath);
 		free(cgpath);
 		return true;
@@ -746,16 +755,17 @@ static bool cg_legacy_handle_cpuset_hierarchy(struct hierarchy *h, char *cgname)
 
 	/* copy parent's settings */
 	if (!copy_parent_file(cgpath, "cpuset.mems")) {
-		SYSERROR("Failed to copy \"cpuset.mems\" settings.");
+		SYSERROR("Failed to copy \"cpuset.mems\" settings");
 		free(cgpath);
 		free(clonechildrenpath);
 		return false;
 	}
 	free(cgpath);
 
-	if (lxc_write_to_file(clonechildrenpath, "1", 1, false) < 0) {
+	ret = lxc_write_to_file(clonechildrenpath, "1", 1, false);
+	if (ret < 0) {
 		/* Set clone_children so children inherit our settings */
-		SYSERROR("Failed to write 1 to %s", clonechildrenpath);
+		SYSERROR("Failed to write 1 to \"%s\"", clonechildrenpath);
 		free(clonechildrenpath);
 		return false;
 	}

From 5c0089ae6182402ad3ac9dbf3529077f0218de9b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:08:38 +0100
Subject: [PATCH 19/56] cgfsng: controller_lists_intersect()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index bdb6f666b..b67f41a81 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -773,9 +773,8 @@ static bool cg_legacy_handle_cpuset_hierarchy(struct hierarchy *h, char *cgname)
 	return true;
 }
 
-/*
- * Given two null-terminated lists of strings, return true if any string
- * is in both.
+/* Given two null-terminated lists of strings, return true if any string is in
+ * both.
  */
 static bool controller_lists_intersect(char **l1, char **l2)
 {
@@ -788,6 +787,7 @@ static bool controller_lists_intersect(char **l1, char **l2)
 		if (string_in_list(l2, l1[i]))
 			return true;
 	}
+
 	return false;
 }
 

From 258449e5962dcffd3b81eb43114e0723ccdc2359 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:09:18 +0100
Subject: [PATCH 20/56] cgfsng: controller_list_is_dup()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index b67f41a81..95aa93d74 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -791,10 +791,9 @@ static bool controller_lists_intersect(char **l1, char **l2)
 	return false;
 }
 
-/*
- * For a null-terminated list of controllers @clist, return true if any of
- * those controllers is already listed the null-terminated list of
- * hierarchies @hlist.  Realistically, if one is present, all must be present.
+/* For a null-terminated list of controllers @clist, return true if any of those
+ * controllers is already listed the null-terminated list of hierarchies @hlist.
+ * Realistically, if one is present, all must be present.
  */
 static bool controller_list_is_dup(struct hierarchy **hlist, char **clist)
 {
@@ -802,11 +801,12 @@ static bool controller_list_is_dup(struct hierarchy **hlist, char **clist)
 
 	if (!hlist)
 		return false;
+
 	for (i = 0; hlist[i]; i++)
 		if (controller_lists_intersect(hlist[i]->controllers, clist))
 			return true;
-	return false;
 
+	return false;
 }
 
 /*

From f57ac67f662bd806ffc141106ceda5068ed828c9 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:09:50 +0100
Subject: [PATCH 21/56] cgfsng: controller_found()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 95aa93d74..c1163227f 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -809,9 +809,8 @@ static bool controller_list_is_dup(struct hierarchy **hlist, char **clist)
 	return false;
 }
 
-/*
- * Return true if the controller @entry is found in the null-terminated
- * list of hierarchies @hlist
+/* Return true if the controller @entry is found in the null-terminated list of
+ * hierarchies @hlist.
  */
 static bool controller_found(struct hierarchy **hlist, char *entry)
 {

From e1c27ab0f94f58df36ab10b1286710f3e32d26c9 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:10:49 +0100
Subject: [PATCH 22/56] cgfsng: all_controllers_found()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index c1163227f..44217e745 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -826,14 +826,14 @@ static bool controller_found(struct hierarchy **hlist, char *entry)
 	return false;
 }
 
-/*
- * Return true if all of the controllers which we require have been found.
- * The required list is  freezer and anything in * lxc.cgroup.use.
+/* Return true if all of the controllers which we require have been found.  The
+ * required list is  freezer and anything in lxc.cgroup.use.
  */
 static bool all_controllers_found(void)
 {
-	char *p, *saveptr = NULL;
-	struct hierarchy ** hlist = hierarchies;
+	char *p;
+	char *saveptr = NULL;
+	struct hierarchy **hlist = hierarchies;
 
 	if (!controller_found(hlist, "freezer")) {
 		CGFSNG_DEBUG("No freezer controller mountpoint found\n");
@@ -844,7 +844,7 @@ static bool all_controllers_found(void)
 		return true;
 
 	for (p = strtok_r(cgroup_use, ",", &saveptr); p;
-			p = strtok_r(NULL, ",", &saveptr)) {
+	     p = strtok_r(NULL, ",", &saveptr)) {
 		if (!controller_found(hlist, p)) {
 			CGFSNG_DEBUG("No %s controller mountpoint found\n", p);
 			return false;

From f205f10cf6b663aad7016d3b358ea59784dbc994 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:12:51 +0100
Subject: [PATCH 23/56] cgfsng: cg_hybrid_get_controllers()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 44217e745..d5419ecd9 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -854,17 +854,17 @@ static bool all_controllers_found(void)
 	return true;
 }
 
-/*
- * Get the controllers from a mountinfo line
- * There are other ways we could get this info.  For lxcfs, field 3
- * is /cgroup/controller-list.  For cgroupfs, we could parse the mount
- * options.  But we simply assume that the mountpoint must be
- * /sys/fs/cgroup/controller-list
+/* Get the controllers from a mountinfo line There are other ways we could get
+ * this info. For lxcfs, field 3 is /cgroup/controller-list. For cgroupfs, we
+ * could parse the mount options. But we simply assume that the mountpoint must
+ * be /sys/fs/cgroup/controller-list
  */
 static char **cg_hybrid_get_controllers(char **klist, char **nlist, char *line,
 					int type)
 {
-	/* the fourth field is /sys/fs/cgroup/comma-delimited-controller-list */
+	/* The fourth field is /sys/fs/cgroup/comma-delimited-controller-list
+	 * for legacy hierarchies.
+	 */
 	int i;
 	char *dup, *p2, *tok;
 	char *p = line, *saveptr = NULL, *sep = ",";
@@ -877,9 +877,10 @@ static char **cg_hybrid_get_controllers(char **klist, char **nlist, char *line,
 		p++;
 	}
 
-	/* note - if we change how mountinfo works, then our caller
-	 * will need to verify /sys/fs/cgroup/ in this field */
-	if (strncmp(p, "/sys/fs/cgroup/", 15)) {
+	/* Note, if we change how mountinfo works, then our caller will need to
+	 * verify /sys/fs/cgroup/ in this field.
+	 */
+	if (strncmp(p, "/sys/fs/cgroup/", 15) != 0) {
 		CGFSNG_DEBUG("Found hierarchy not under /sys/fs/cgroup: \"%s\"\n", p);
 		return NULL;
 	}
@@ -907,6 +908,7 @@ static char **cg_hybrid_get_controllers(char **klist, char **nlist, char *line,
 		free(dup);
 	}
 	*p2 = ' ';
+
 	return aret;
 }
 

From 798c3b33f6bc251f698b2b353230b973bd244619 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:14:14 +0100
Subject: [PATCH 24/56] cgfsng: cg_hybrid_get_mountpoint()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index d5419ecd9..e2664decc 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -964,17 +964,15 @@ static struct hierarchy *add_hierarchy(char **clist, char *mountpoint,
 	return new;
 }
 
-/*
- * Get a copy of the mountpoint from @line, which is a line from
- * /proc/self/mountinfo
+/* Get a copy of the mountpoint from @line, which is a line from
+ * /proc/self/mountinfo.
  */
 static char *cg_hybrid_get_mountpoint(char *line)
 {
 	int i;
-	char *p2;
 	size_t len;
-	char *p = line;
-	char *sret = NULL;
+	char *p2;
+	char *p = line, *sret = NULL;
 
 	for (i = 0; i < 4; i++) {
 		p = strchr(p, ' ');
@@ -983,7 +981,7 @@ static char *cg_hybrid_get_mountpoint(char *line)
 		p++;
 	}
 
-	if (strncmp(p, "/sys/fs/cgroup/", 15))
+	if (strncmp(p, "/sys/fs/cgroup/", 15) != 0)
 		return NULL;
 
 	p2 = strchr(p + 15, ' ');

From f523291e3e58ca3e84bf8152852bcda4f05f1aac Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:14:48 +0100
Subject: [PATCH 25/56] cgfsng: copy_to_eol()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index e2664decc..0723ce6b3 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -996,10 +996,7 @@ static char *cg_hybrid_get_mountpoint(char *line)
 	return sret;
 }
 
-/*
- * Given a multi-line string, return a null-terminated copy of the
- * current line.
- */
+/* Given a multi-line string, return a null-terminated copy of the current line. */
 static char *copy_to_eol(char *p)
 {
 	char *p2 = strchr(p, '\n'), *sret;

From bced39de185b881df388ceb54be58bb6e7e57278 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:15:17 +0100
Subject: [PATCH 26/56] cgfsng: controller_in_clist()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 0723ce6b3..aefce12b3 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1012,10 +1012,8 @@ static char *copy_to_eol(char *p)
 	return sret;
 }
 
-/*
- * cgline: pointer to character after the first ':' in a line in a
- * \n-terminated /proc/self/cgroup file. Check whether * controller c is
- * present.
+/* cgline: pointer to character after the first ':' in a line in a \n-terminated
+ * /proc/self/cgroup file. Check whether controller c is present.
  */
 static bool controller_in_clist(char *cgline, char *c)
 {

From c3ef912e97788a7ef307464da107302025cbe5f0 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:15:52 +0100
Subject: [PATCH 27/56] cgfsng: cg_hybrid_get_current_cgroup()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index aefce12b3..6bec51928 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1038,11 +1038,11 @@ static bool controller_in_clist(char *cgline, char *c)
 	return false;
 }
 
-/*
- * @basecginfo is a copy of /proc/$$/cgroup.  Return the current
- * cgroup for @controller
+/* @basecginfo is a copy of /proc/$$/cgroup. Return the current cgroup for
+ * @controller.
  */
-static char *cg_hybrid_get_current_cgroup(char *basecginfo, char *controller, int type)
+static char *cg_hybrid_get_current_cgroup(char *basecginfo, char *controller,
+					  int type)
 {
 	char *p = basecginfo;
 

From 6dfb18bf040fd931b0c87c17968a8209253ac2e5 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:16:20 +0100
Subject: [PATCH 28/56] cgfsng: must_append_string()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 6bec51928..15e913328 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1075,9 +1075,10 @@ static char *cg_hybrid_get_current_cgroup(char *basecginfo, char *controller,
 
 static void must_append_string(char ***list, char *entry)
 {
-	int newentry = append_null_to_list((void ***)list);
+	int newentry;
 	char *copy;
 
+	newentry = append_null_to_list((void ***)list);
 	copy = must_copy_string(entry);
 	(*list)[newentry] = copy;
 }

From 7689dfd7354f16b4be26018ea9ea4142460e46b2 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:16:56 +0100
Subject: [PATCH 29/56] cgfsng: trim()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 15e913328..d1d7c3002 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1132,7 +1132,9 @@ static int get_existing_subsystems(char ***klist, char ***nlist)
 
 static void trim(char *s)
 {
-	size_t len = strlen(s);
+	size_t len;
+
+	len = strlen(s);
 	while ((len > 1) && (s[len - 1] == '\n'))
 		s[--len] = '\0';
 }

From 27d84737573ee56dd10bd1e53693a81b1d2a6558 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:17:43 +0100
Subject: [PATCH 30/56] cgfsng: lxc_cgfsng_print_hierarchies()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index d1d7c3002..aed9181e3 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1154,17 +1154,19 @@ static void lxc_cgfsng_print_handler_data(const struct cgfsng_handler_data *d)
 
 static void lxc_cgfsng_print_hierarchies()
 {
-	struct hierarchy **it;
 	int i;
+	struct hierarchy **it;
 
 	if (!hierarchies) {
 		printf("  No hierarchies found\n");
 		return;
 	}
+
 	printf("  Hierarchies:\n");
 	for (i = 0, it = hierarchies; it && *it; it++, i++) {
-		char **cit;
 		int j;
+		char **cit;
+
 		printf("  %d: base_cgroup: %s\n", i, (*it)->base_cgroup ? (*it)->base_cgroup : "(null)");
 		printf("      mountpoint:  %s\n", (*it)->mountpoint ? (*it)->mountpoint : "(null)");
 		printf("      controllers:\n");

From 0f71dd9b92d5477cf7fe893c365b3fbe68c2a0cd Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:18:08 +0100
Subject: [PATCH 31/56] cgfsng: lxc_cgfsng_print_basecg_debuginfo()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index aed9181e3..870a75dab 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1186,6 +1186,7 @@ static void lxc_cgfsng_print_basecg_debuginfo(char *basecginfo, char **klist,
 
 	for (k = 0, it = klist; it && *it; it++, k++)
 		printf("kernel subsystem %d: %s\n", k, *it);
+
 	for (k = 0, it = nlist; it && *it; it++, k++)
 		printf("named subsystem %d: %s\n", k, *it);
 }

From 96e6f37f51f946fc317fb99971150db5f0192a24 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:20:23 +0100
Subject: [PATCH 32/56] cgfsng: cg_hybrid_init()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 870a75dab..7f6036b87 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1197,9 +1197,8 @@ static void lxc_cgfsng_print_debuginfo(const struct cgfsng_handler_data *d)
 	lxc_cgfsng_print_hierarchies();
 }
 
-/*
- * At startup, parse_hierarchies finds all the info we need about
- * cgroup mountpoints and current cgroups, and stores it in @d.
+/* At startup, parse_hierarchies finds all the info we need about cgroup
+ * mountpoints and current cgroups, and stores it in @d.
  */
 static bool cg_hybrid_init(void)
 {
@@ -1211,8 +1210,7 @@ static bool cg_hybrid_init(void)
 	char *line = NULL;
 	char **klist = NULL, **nlist = NULL;
 
-	/*
-	 * Root spawned containers escape the current cgroup, so use init's
+	/* Root spawned containers escape the current cgroup, so use init's
 	 * cgroups as our base in that case.
 	 */
 	will_escape = (geteuid() == 0);
@@ -1225,7 +1223,7 @@ static bool cg_hybrid_init(void)
 
 	ret = get_existing_subsystems(&klist, &nlist);
 	if (ret < 0) {
-		CGFSNG_DEBUG("Failed to retrieve available cgroup v1 controllers\n");
+		CGFSNG_DEBUG("Failed to retrieve available legacy cgroup controllers\n");
 		free(basecginfo);
 		return false;
 	}
@@ -1244,7 +1242,7 @@ static bool cg_hybrid_init(void)
 		int type;
 		bool writeable;
 		struct hierarchy *new;
-		char *mountpoint = NULL, *base_cgroup = NULL;
+		char *base_cgroup = NULL, *mountpoint = NULL;
 		char **controller_list = NULL;
 
 		type = get_cgroup_version(line);
@@ -1311,6 +1309,7 @@ static bool cg_hybrid_init(void)
 			if (!controller_list)
 				controller_list = cg_unified_make_empty_controller();
 		}
+
 		new = add_hierarchy(controller_list, mountpoint, base_cgroup, type);
 		if (type == CGROUP2_SUPER_MAGIC && !unified)
 			unified = new;
@@ -1332,7 +1331,7 @@ static bool cg_hybrid_init(void)
 	free(line);
 
 	if (lxc_cgfsng_debug) {
-		printf("writeable subsystems:\n");
+		printf("Writable cgroup hierarchies:\n");
 		lxc_cgfsng_print_hierarchies();
 	}
 

From c71d83e17e4e62d5082b995ed15871c1ea29639a Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:20:54 +0100
Subject: [PATCH 33/56] cgfsng: cg_is_pure_unified()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 7f6036b87..dd759a2b4 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1344,19 +1344,20 @@ static bool cg_hybrid_init(void)
 	return true;
 }
 
-static int cg_is_pure_unified(void) {
+static int cg_is_pure_unified(void)
+{
 
 	int ret;
-        struct statfs fs;
+	struct statfs fs;
 
-        ret = statfs("/sys/fs/cgroup", &fs);
-        if (ret < 0)
-                return -ENOMEDIUM;
+	ret = statfs("/sys/fs/cgroup", &fs);
+	if (ret < 0)
+		return -ENOMEDIUM;
 
-        if (is_fs_type(&fs, CGROUP2_SUPER_MAGIC))
+	if (is_fs_type(&fs, CGROUP2_SUPER_MAGIC))
 		return CGROUP2_SUPER_MAGIC;
 
-        return 0;
+	return 0;
 }
 
 /* Get current cgroup from /proc/self/cgroup for the cgroupfs v2 hierarchy. */

From 165dc5109ea7dea79f28314c57b4ac2b8bac5cc1 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:21:30 +0100
Subject: [PATCH 34/56] cgfsng: cg_unified_get_current_cgroup()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index dd759a2b4..a899a889f 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1363,8 +1363,7 @@ static int cg_is_pure_unified(void)
 /* Get current cgroup from /proc/self/cgroup for the cgroupfs v2 hierarchy. */
 static char *cg_unified_get_current_cgroup(void)
 {
-	char *basecginfo;
-	char *base_cgroup;
+	char *basecginfo, *base_cgroup;
 	bool will_escape;
 	char *copy = NULL;
 

From 3d7a68f7076d4e47f7380739f3d25056507d90e0 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:22:31 +0100
Subject: [PATCH 35/56] cgfsng: cgfsng_init()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index a899a889f..a0cddd42e 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1485,7 +1485,7 @@ static void *cgfsng_init(struct lxc_handler *handler)
 	cgroup_pattern = lxc_global_config_value("lxc.cgroup.pattern");
 	if (!cgroup_pattern) {
 		/* lxc.cgroup.pattern is only NULL on error. */
-		ERROR("Error getting cgroup pattern");
+		ERROR("Failed to retrieve cgroup pattern");
 		goto out_free;
 	}
 	d->cgroup_pattern = must_copy_string(cgroup_pattern);

From 4adf9bd3a80d6a0db510b7d34988ee9e9c1f407a Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:23:24 +0100
Subject: [PATCH 36/56] cgfsng: recursive_destroy()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index a0cddd42e..4cbd5c5c8 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1534,7 +1534,7 @@ static int recursive_destroy(char *dirname)
 		ret = lstat(pathname, &mystat);
 		if (ret < 0) {
 			if (!r)
-				WARN("Failed to stat %s", pathname);
+				WARN("Failed to stat \"%s\"", pathname);
 			r = -1;
 			goto next;
 		}
@@ -1552,16 +1552,14 @@ static int recursive_destroy(char *dirname)
 	ret = rmdir(dirname);
 	if (ret < 0) {
 		if (!r)
-			WARN("%s - Failed to delete \"%s\"", strerror(errno),
-			     dirname);
+			WARN("%s - Failed to delete \"%s\"", strerror(errno), dirname);
 		r = -1;
 	}
 
 	ret = closedir(dir);
 	if (ret < 0) {
 		if (!r)
-			WARN("%s - Failed to delete \"%s\"", strerror(errno),
-			     dirname);
+			WARN("%s - Failed to delete \"%s\"", strerror(errno), dirname);
 		r = -1;
 	}
 

From 389d44ec9fbd0c0f7987c2ecbb94203e784d240e Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:24:39 +0100
Subject: [PATCH 37/56] cgfsng: cg_unified_create_cgroup()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 4cbd5c5c8..bedaeb33d 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1667,8 +1667,8 @@ struct cgroup_ops *cgfsng_ops_init(void)
 
 static bool cg_unified_create_cgroup(struct hierarchy *h, char *cgname)
 {
-	char **it;
 	size_t i, parts_len;
+	char **it;
 	size_t full_len = 0;
 	char *add_controllers = NULL, *cgroup = NULL;
 	char **parts = NULL;

From 4b4205e388d4ae7c7088bd7bb4d722067b328cb8 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:25:20 +0100
Subject: [PATCH 38/56] cgfsng: create_path_for_hierarchy()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index bedaeb33d..8bb717fff 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1734,13 +1734,13 @@ static bool create_path_for_hierarchy(struct hierarchy *h, char *cgname)
 	int ret;
 
 	h->fullcgpath = must_make_path(h->mountpoint, h->base_cgroup, cgname, NULL);
-	if (dir_exists(h->fullcgpath)) { /* it must not already exist */
-		ERROR("cgroup \"%s\" already existed", h->fullcgpath);
+	if (dir_exists(h->fullcgpath)) {
+		ERROR("The cgroup \"%s\" already existed", h->fullcgpath);
 		return false;
 	}
 
 	if (!cg_legacy_handle_cpuset_hierarchy(h, cgname)) {
-		ERROR("Failed to handle cgroupfs v1 cpuset controller");
+		ERROR("Failed to handle legacy cpuset controller");
 		return false;
 	}
 

From e56639fb06bd1d7845b6a6cab2543a0b81260ac9 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:26:42 +0100
Subject: [PATCH 39/56] cgfsng: remove_path_for_hierarchy()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 8bb717fff..5f53aee03 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1755,8 +1755,12 @@ static bool create_path_for_hierarchy(struct hierarchy *h, char *cgname)
 
 static void remove_path_for_hierarchy(struct hierarchy *h, char *cgname)
 {
-	if (rmdir(h->fullcgpath) < 0)
-		SYSERROR("Failed to clean up cgroup %s from failed creation attempt", h->fullcgpath);
+	int ret;
+
+	ret = rmdir(h->fullcgpath);
+	if (ret < 0)
+		SYSERROR("Failed to rmdir(\"%s\") from failed creation attempt", h->fullcgpath);
+
 	free(h->fullcgpath);
 	h->fullcgpath = NULL;
 }

From cecad0c11c4e4c22c25e90681058aadf0d8e6dfc Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:27:52 +0100
Subject: [PATCH 40/56] cgfsng: cgfsng_create()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 5f53aee03..9e8a1ca31 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1765,9 +1765,8 @@ static void remove_path_for_hierarchy(struct hierarchy *h, char *cgname)
 	h->fullcgpath = NULL;
 }
 
-/*
- * Try to create the same cgroup in all hierarchies.
- * Start with cgroup_pattern; next cgroup_pattern-1, -2, ..., -999
+/* Try to create the same cgroup in all hierarchies. Start with cgroup_pattern;
+ * next cgroup_pattern-1, -2, ..., -999.
  */
 static inline bool cgfsng_create(void *hdata)
 {
@@ -1804,6 +1803,7 @@ static inline bool cgfsng_create(void *hdata)
 		ERROR("Too many conflicting cgroup names");
 		goto out_free;
 	}
+
 	if (idx) {
 		int ret;
 
@@ -1818,10 +1818,11 @@ static inline bool cgfsng_create(void *hdata)
 			}
 		}
 	}
+
 	for (i = 0; hierarchies[i]; i++) {
 		if (!create_path_for_hierarchy(hierarchies[i], container_cgroup)) {
 			int j;
-			ERROR("Failed to create \"%s\"", hierarchies[i]->fullcgpath);
+			ERROR("Failed to create cgroup \"%s\"", hierarchies[i]->fullcgpath);
 			free(hierarchies[i]->fullcgpath);
 			hierarchies[i]->fullcgpath = NULL;
 			for (j = 0; j < i; j++)
@@ -1830,12 +1831,14 @@ static inline bool cgfsng_create(void *hdata)
 			goto again;
 		}
 	}
-	/* Done */
+
 	d->container_cgroup = container_cgroup;
+
 	return true;
 
 out_free:
 	free(container_cgroup);
+
 	return false;
 }
 

From 08768001650cd132ca3151721e9a0ad59320b33e Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:29:02 +0100
Subject: [PATCH 41/56] cgfsng: cgfsng_enter()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 9e8a1ca31..ba75ebe75 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1844,18 +1844,22 @@ static inline bool cgfsng_create(void *hdata)
 
 static bool cgfsng_enter(void *hdata, pid_t pid)
 {
-	char pidstr[25];
 	int i, len;
+	char pidstr[25];
 
 	len = snprintf(pidstr, 25, "%d", pid);
-	if (len < 0 || len > 25)
+	if (len < 0 || len >= 25)
 		return false;
 
 	for (i = 0; hierarchies[i]; i++) {
-		char *fullpath = must_make_path(hierarchies[i]->fullcgpath,
-						"cgroup.procs", NULL);
-		if (lxc_write_to_file(fullpath, pidstr, len, false) != 0) {
-			SYSERROR("Failed to enter %s", fullpath);
+		int ret;
+		char *fullpath;
+
+		fullpath = must_make_path(hierarchies[i]->fullcgpath,
+					  "cgroup.procs", NULL);
+		ret = lxc_write_to_file(fullpath, pidstr, len, false);
+		if (ret != 0) {
+			SYSERROR("Failed to enter cgroup \"%s\"", fullpath);
 			free(fullpath);
 			return false;
 		}

From f7faba6cf0db6dd4dccb9baeb86f81d48a26070b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:31:16 +0100
Subject: [PATCH 42/56] cgfsng: cgfsng_chown()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index ba75ebe75..b59b273aa 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1986,7 +1986,7 @@ static bool cgfsng_chown(void *hdata, struct lxc_conf *conf)
 
 	if (userns_exec_1(conf, chown_cgroup_wrapper, &wrap,
 			  "chown_cgroup_wrapper") < 0) {
-		ERROR("Error requesting cgroup chown in new namespace");
+		ERROR("Error requesting cgroup chown in new user namespace");
 		return false;
 	}
 

From 233544a0b549ec6bf95c9f5a7b2587cba38fbb09 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:35:03 +0100
Subject: [PATCH 43/56] cgfsng: mount_cgroup_full()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index b59b273aa..9058e2a8f 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1993,42 +1993,51 @@ static bool cgfsng_chown(void *hdata, struct lxc_conf *conf)
 	return true;
 }
 
-/*
- * We've safe-mounted a tmpfs as parent, so we don't need to protect against
- * symlinks any more - just use mount
+/* We've safe-mounted a tmpfs as parent, so we don't need to protect against
+ * symlinks any more - just use mount.
+ *
+ * mount cgroup-full if requested
  */
-
-/* mount cgroup-full if requested */
 static int mount_cgroup_full(int type, struct hierarchy *h, char *dest,
 			     char *container_cgroup)
 {
+	int ret;
+	char *rwpath, *source;
+
 	if (type < LXC_AUTO_CGROUP_FULL_RO || type > LXC_AUTO_CGROUP_FULL_MIXED)
 		return 0;
-	if (mount(h->mountpoint, dest, "cgroup", MS_BIND, NULL) < 0) {
-		SYSERROR("Error bind-mounting %s cgroup onto %s", h->mountpoint,
-			 dest);
+
+	ret = mount(h->mountpoint, dest, "cgroup", MS_BIND, NULL);
+	if (ret < 0) {
+		SYSERROR("Failed to bind mount cgroup \"%s\" onto \"%s\"",
+			 h->mountpoint, dest);
 		return -1;
 	}
+
 	if (type != LXC_AUTO_CGROUP_FULL_RW) {
 		unsigned long flags = MS_BIND | MS_NOSUID | MS_NOEXEC | MS_NODEV |
 				      MS_REMOUNT | MS_RDONLY;
-		if (mount(NULL, dest, "cgroup", flags, NULL) < 0) {
-			SYSERROR("Error remounting %s readonly", dest);
+
+		ret = mount(NULL, dest, "cgroup", flags, NULL);
+		if (ret < 0) {
+			SYSERROR("Failed to remount cgroup \"%s\" read-only", dest);
 			return -1;
 		}
 	}
 
-	INFO("Bind mounted %s onto %s", h->mountpoint, dest);
+	INFO("Bind mounted \"%s\" onto \"%s\"", h->mountpoint, dest);
 	if (type != LXC_AUTO_CGROUP_FULL_MIXED)
 		return 0;
 
 	/* mount just the container path rw */
-	char *source = must_make_path(h->mountpoint, h->base_cgroup, container_cgroup, NULL);
-	char *rwpath = must_make_path(dest, h->base_cgroup, container_cgroup, NULL);
-	if (mount(source, rwpath, "cgroup", MS_BIND, NULL) < 0)
-		WARN("Failed to mount %s read-write: %s", rwpath,
-		     strerror(errno));
-	INFO("Made %s read-write", rwpath);
+	source = must_make_path(h->mountpoint, h->base_cgroup, container_cgroup, NULL);
+	rwpath = must_make_path(dest, h->base_cgroup, container_cgroup, NULL);
+	ret = mount(source, rwpath, "cgroup", MS_BIND, NULL);
+	if (ret < 0)
+		WARN("%s - Failed to mount cgroup \"%s\" read-write",
+		     strerror(errno), rwpath);
+
+	TRACE("Mounted cgroup \"%s\" read-write", rwpath);
 	free(rwpath);
 	free(source);
 	return 0;

From affd10fa62479729d11ceb12ac127e1ff076eb96 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:38:59 +0100
Subject: [PATCH 44/56] cgfsng: cgfsng_mount()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 9058e2a8f..3a3aa395b 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -2153,10 +2153,9 @@ static bool cgfsng_mount(void *hdata, const char *root, int type)
 {
 	int i, ret;
 	char *tmpfspath = NULL;
-	bool retval = false;
+	bool has_cgns = false, retval = false, wants_force_mount = false;
 	struct lxc_handler *handler = hdata;
 	struct cgfsng_handler_data *d = handler->cgroup_data;
-	bool has_cgns = false, wants_force_mount = false;
 
 	if ((type & LXC_AUTO_CGROUP_MASK) == 0)
 		return true;
@@ -2198,11 +2197,13 @@ static bool cgfsng_mount(void *hdata, const char *root, int type)
 		if (!controller)
 			continue;
 		controller++;
+
 		controllerpath = must_make_path(tmpfspath, controller, NULL);
 		if (dir_exists(controllerpath)) {
 			free(controllerpath);
 			continue;
 		}
+
 		ret = mkdir(controllerpath, 0755);
 		if (ret < 0) {
 			SYSERROR("Error creating cgroup path: %s", controllerpath);
@@ -2243,8 +2244,8 @@ static bool cgfsng_mount(void *hdata, const char *root, int type)
 			goto on_error;
 		}
 
-		ret = do_secondstage_mounts_if_needed(
-		    type, h, controllerpath, path2, d->container_cgroup);
+		ret = do_secondstage_mounts_if_needed(type, h, controllerpath,
+						      path2, d->container_cgroup);
 		free(controllerpath);
 		free(path2);
 		if (ret < 0)

From 13c499557851e6336f8d0317af26e281fb583b48 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:39:33 +0100
Subject: [PATCH 45/56] cgfsng: recursive_count_nrtasks()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 3a3aa395b..189635fdf 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -2288,7 +2288,7 @@ static int recursive_count_nrtasks(char *dirname)
 			goto next;
 
 		count += recursive_count_nrtasks(path);
-next:
+	next:
 		free(path);
 	}
 
@@ -2298,7 +2298,7 @@ static int recursive_count_nrtasks(char *dirname)
 		count += ret;
 	free(path);
 
-	(void) closedir(dir);
+	(void)closedir(dir);
 
 	return count;
 }

From 3135c5d47ed8257d8a22c4878468bdd264cf6137 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:40:00 +0100
Subject: [PATCH 46/56] cgfsng: recursive_count_nrtasks()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 189635fdf..7c2b1d7ab 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -2303,10 +2303,11 @@ static int recursive_count_nrtasks(char *dirname)
 	return count;
 }
 
-static int cgfsng_nrtasks(void *hdata) {
-	struct cgfsng_handler_data *d = hdata;
-	char *path;
+static int cgfsng_nrtasks(void *hdata)
+{
 	int count;
+	char *path;
+	struct cgfsng_handler_data *d = hdata;
 
 	if (!d || !d->container_cgroup || !hierarchies)
 		return -1;

From 11c238679785520014dfe4fab772d98f9dd8e501 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:41:04 +0100
Subject: [PATCH 47/56] cgfsng: cgfsng_escape()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 7c2b1d7ab..81b340b66 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -2318,7 +2318,7 @@ static int cgfsng_nrtasks(void *hdata)
 	return count;
 }
 
-/* Only root needs to escape to the cgroup of its init */
+/* Only root needs to escape to the cgroup of its init. */
 static bool cgfsng_escape()
 {
 	int i;
@@ -2327,11 +2327,15 @@ static bool cgfsng_escape()
 		return true;
 
 	for (i = 0; hierarchies[i]; i++) {
-		char *fullpath = must_make_path(hierarchies[i]->mountpoint,
-						hierarchies[i]->base_cgroup,
-						"cgroup.procs", NULL);
-		if (lxc_write_to_file(fullpath, "0", 2, false) != 0) {
-			SYSERROR("Failed to escape to %s", fullpath);
+		int ret;
+		char *fullpath;
+
+		fullpath = must_make_path(hierarchies[i]->mountpoint,
+					  hierarchies[i]->base_cgroup,
+					  "cgroup.procs", NULL);
+		ret = lxc_write_to_file(fullpath, "0", 2, false);
+		if (ret != 0) {
+			SYSERROR("Failed to escape to cgroup \"%s\"", fullpath);
 			free(fullpath);
 			return false;
 		}

From c40c820909afea230ea017badf60a7ae632b89d6 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:42:17 +0100
Subject: [PATCH 48/56] cgfsng: build_full_cgpath_from_monitorpath()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 81b340b66..78324ff3e 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -2405,13 +2405,12 @@ static const char *cgfsng_get_cgroup(void *hdata, const char *subsystem)
 	return h->fullcgpath ? h->fullcgpath + strlen(h->mountpoint) : NULL;
 }
 
-/*
- * Given a cgroup path returned from lxc_cmd_get_cgroup_path, build a
- * full path, which must be freed by the caller.
+/* Given a cgroup path returned from lxc_cmd_get_cgroup_path, build a full path,
+ * which must be freed by the caller.
  */
-static char *build_full_cgpath_from_monitorpath(struct hierarchy *h,
-						const char *inpath,
-						const char *filename)
+static inline char *build_full_cgpath_from_monitorpath(struct hierarchy *h,
+						       const char *inpath,
+						       const char *filename)
 {
 	return must_make_path(h->mountpoint, inpath, filename, NULL);
 }

From 25f66a8fde675eb56d3d8bd5a4f655fb5f4f5230 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:43:46 +0100
Subject: [PATCH 49/56] cgfsng: __cg_unified_attach()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 78324ff3e..c0edd5cc3 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -2415,10 +2415,10 @@ static inline char *build_full_cgpath_from_monitorpath(struct hierarchy *h,
 	return must_make_path(h->mountpoint, inpath, filename, NULL);
 }
 
-/* Technically, we're always at a delegation boundary here. (This is especially
- * true when cgroup namespaces are available.) The reasoning is that in order
+/* Technically, we're always at a delegation boundary here (This is especially
+ * true when cgroup namespaces are available.). The reasoning is that in order
  * for us to have been able to start a container in the first place the root
- * cgroup must have been a leaf node.  Now, either the container's init system
+ * cgroup must have been a leaf node. Now, either the container's init system
  * has populated the cgroup and kept it as a leaf node or it has created
  * subtrees. In the former case we will simply attach to the leaf node we
  * created when we started the container in the latter case we create our own

From 0cb10e11f13d14bcdc3769b9327d8414cb0e942c Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:44:21 +0100
Subject: [PATCH 50/56] cgfsng: cgfsng_attach()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index c0edd5cc3..07fa6b7db 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -2495,7 +2495,7 @@ static bool cgfsng_attach(const char *name, const char *lxcpath, pid_t pid)
 	char pidstr[25];
 
 	len = snprintf(pidstr, 25, "%d", pid);
-	if (len < 0 || len > 25)
+	if (len < 0 || len >= 25)
 		return false;
 
 	for (i = 0; hierarchies[i]; i++) {

From e2bd2b133d3028a07c6d4d22e9310acba1a3f643 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:44:52 +0100
Subject: [PATCH 51/56] cgfsng: cgfsng_get()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 07fa6b7db..b3e52ebf0 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -2530,10 +2530,9 @@ static bool cgfsng_attach(const char *name, const char *lxcpath, pid_t pid)
 	return true;
 }
 
-/*
- * Called externally (i.e. from 'lxc-cgroup') to query cgroup limits.
- * Here we don't have a cgroup_data set up, so we ask the running
- * container through the commands API for the cgroup path
+/* Called externally (i.e. from 'lxc-cgroup') to query cgroup limits.  Here we
+ * don't have a cgroup_data set up, so we ask the running container through the
+ * commands API for the cgroup path.
  */
 static int cgfsng_get(const char *filename, char *value, size_t len,
 		      const char *name, const char *lxcpath)

From eec533e378fee166acf45cfcd5e994113b20bdaf Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:45:12 +0100
Subject: [PATCH 52/56] cgfsng: cgfsng_set()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index b3e52ebf0..22d50b532 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -2567,10 +2567,9 @@ static int cgfsng_get(const char *filename, char *value, size_t len,
 	return ret;
 }
 
-/*
- * Called externally (i.e. from 'lxc-cgroup') to set new cgroup limits.
- * Here we don't have a cgroup_data set up, so we ask the running
- * container through the commands API for the cgroup path
+/* Called externally (i.e. from 'lxc-cgroup') to set new cgroup limits.  Here we
+ * don't have a cgroup_data set up, so we ask the running container through the
+ * commands API for the cgroup path.
  */
 static int cgfsng_set(const char *filename, const char *value, const char *name,
 		      const char *lxcpath)

From 91d1a13a1308141c8970b23ac019d23c1d09a09a Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:46:44 +0100
Subject: [PATCH 53/56] cgfsng: convert_devpath()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 22d50b532..5dee010de 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -2604,41 +2604,43 @@ static int cgfsng_set(const char *filename, const char *value, const char *name,
 	return ret;
 }
 
-/*
- * take devices cgroup line
+/* take devices cgroup line
  *    /dev/foo rwx
  * and convert it to a valid
  *    type major:minor mode
- * line.  Return <0 on error.  Dest is a preallocated buffer
- * long enough to hold the output.
+ * line. Return <0 on error. Dest is a preallocated buffer long enough to hold
+ * the output.
  */
 static int convert_devpath(const char *invalue, char *dest)
 {
 	int n_parts;
 	char *p, *path, type;
-	struct stat sb;
 	unsigned long minor, major;
+	struct stat sb;
 	int ret = -EINVAL;
 	char *mode = NULL;
 
 	path = must_copy_string(invalue);
 
-	/*
-	 * read path followed by mode;  ignore any trailing text.
-	 * A '    # comment' would be legal.  Technically other text
-	 * is not legal, we could check for that if we cared to
+	/* Read path followed by mode. Ignore any trailing text.
+	 * A '    # comment' would be legal. Technically other text is not
+	 * legal, we could check for that if we cared to.
 	 */
 	for (n_parts = 1, p = path; *p && n_parts < 3; p++) {
 		if (*p != ' ')
 			continue;
 		*p = '\0';
+
 		if (n_parts != 1)
 			break;
 		p++;
 		n_parts++;
+
 		while (*p == ' ')
 			p++;
+
 		mode = p;
+
 		if (*p == '\0')
 			goto out;
 	}
@@ -2659,7 +2661,7 @@ static int convert_devpath(const char *invalue, char *dest)
 		type = 'c';
 		break;
 	default:
-		ERROR("Unsupported device type %i for %s", m, path);
+		ERROR("Unsupported device type %i for \"%s\"", m, path);
 		ret = -EINVAL;
 		goto out;
 	}

From 90e9728449bf9225bbd2a2e559f2b498850f5d6a Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:47:23 +0100
Subject: [PATCH 54/56] cgfsng: cg_legacy_set_data()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 5dee010de..a9eed90a9 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -2682,15 +2682,14 @@ static int convert_devpath(const char *invalue, char *dest)
 	return ret;
 }
 
-/*
- * Called from setup_limits - here we have the container's cgroup_data because
- * we created the cgroups
+/* Called from setup_limits - here we have the container's cgroup_data because
+ * we created the cgroups.
  */
 static int cg_legacy_set_data(const char *filename, const char *value,
 			      struct cgfsng_handler_data *d)
 {
-	char *fullpath, *p;
 	size_t len;
+	char *fullpath, *p;
 	/* "b|c <2^64-1>:<2^64-1> r|w|m" = 47 chars max */
 	char converted_value[50];
 	struct hierarchy *h;

From c347df58468462f17aae3591b974d73204b87898 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:48:59 +0100
Subject: [PATCH 55/56] cgfsng: __cg_legacy_setup_limits()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index a9eed90a9..f62debea4 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -2730,9 +2730,9 @@ static bool __cg_legacy_setup_limits(void *hdata,
 				     struct lxc_list *cgroup_settings,
 				     bool do_devices)
 {
-	struct cgfsng_handler_data *d = hdata;
-	struct lxc_list *iterator, *sorted_cgroup_settings, *next;
+	struct lxc_list *iterator, *next, *sorted_cgroup_settings;
 	struct lxc_cgroup *cg;
+	struct cgfsng_handler_data *d = hdata;
 	bool ret = false;
 
 	if (lxc_list_empty(cgroup_settings))
@@ -2748,15 +2748,16 @@ static bool __cg_legacy_setup_limits(void *hdata,
 		if (do_devices == !strncmp("devices", cg->subsystem, 7)) {
 			if (cg_legacy_set_data(cg->subsystem, cg->value, d)) {
 				if (do_devices && (errno == EACCES || errno == EPERM)) {
-					WARN("Error setting %s to %s for %s",
-					      cg->subsystem, cg->value, d->name);
+					WARN("Failed to set \"%s\" to \"%s\"",
+					     cg->subsystem, cg->value);
 					continue;
 				}
-				SYSERROR("Error setting %s to %s for %s",
-				      cg->subsystem, cg->value, d->name);
+				WARN("Failed to set \"%s\" to \"%s\"",
+				     cg->subsystem, cg->value);
 				goto out;
 			}
-			DEBUG("cgroup '%s' set to '%s'", cg->subsystem, cg->value);
+			DEBUG("Set controller \"%s\" set to \"%s\"",
+			      cg->subsystem, cg->value);
 		}
 	}
 

From b2ac2cb7557f264851af8db18f22fe5c773de979 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sat, 17 Feb 2018 19:49:31 +0100
Subject: [PATCH 56/56] cgfsng: __cg_unified_setup_limits()

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

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index f62debea4..f491da35d 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -2793,7 +2793,8 @@ static bool __cg_unified_setup_limits(void *hdata,
 		ret = lxc_write_to_file(fullpath, cg->value, strlen(cg->value), false);
 		free(fullpath);
 		if (ret < 0) {
-			SYSERROR("Failed to set \"%s\" to \"%s\"", cg->subsystem, cg->value);
+			SYSERROR("Failed to set \"%s\" to \"%s\"",
+				 cg->subsystem, cg->value);
 			return false;
 		}
 		TRACE("Set \"%s\" to \"%s\"", cg->subsystem, cg->value);


More information about the lxc-devel mailing list