The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxc/pull/2836

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Signed-off-by: Christian Brauner <[email protected]>
From f2668eea509deccb77a90dac8a12f43bfcb6178f Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Sun, 10 Feb 2019 10:51:43 +0100
Subject: [PATCH 1/3] cgfsng: coding style for cgfsng_monitor_create()

Signed-off-by: Christian Brauner <[email protected]>
---
 src/lxc/cgroups/cgfsng.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 2049363b3..d03fcf390 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1329,7 +1329,7 @@ static void remove_path_for_hierarchy(struct hierarchy 
*h, char *cgname, bool mo
 }
 
 __cgfsng_ops static inline bool cgfsng_monitor_create(struct cgroup_ops *ops,
-                                                       struct lxc_handler 
*handler)
+                                                     struct lxc_handler 
*handler)
 {
        __do_free char *monitor_cgroup = NULL;
        char *offset, *tmp;
@@ -1367,10 +1367,14 @@ __cgfsng_ops static inline bool 
cgfsng_monitor_create(struct cgroup_ops *ops,
                }
 
                for (i = 0; ops->hierarchies[i]; i++) {
-                       if 
(!monitor_create_path_for_hierarchy(ops->hierarchies[i], monitor_cgroup)) {
-                               ERROR("Failed to create cgroup \"%s\"", 
ops->hierarchies[i]->monitor_full_path);
+                       if 
(!monitor_create_path_for_hierarchy(ops->hierarchies[i],
+                                                              monitor_cgroup)) 
{
+                               ERROR("Failed to create cgroup \"%s\"",
+                                     ops->hierarchies[i]->monitor_full_path);
                                for (int j = 0; j < i; j++)
-                                       
remove_path_for_hierarchy(ops->hierarchies[j], monitor_cgroup, true);
+                                       
remove_path_for_hierarchy(ops->hierarchies[j],
+                                                                 
monitor_cgroup,
+                                                                 true);
 
                                idx++;
                                break;

From d99d5c935a9ee2eb66ba9e55e85bd707d4c1647b Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Sun, 10 Feb 2019 10:52:45 +0100
Subject: [PATCH 2/3] cgfsng: coding style for cgfsng_payload_create()

Signed-off-by: Christian Brauner <[email protected]>
---
 src/lxc/cgroups/cgfsng.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index d03fcf390..76c7647b5 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1431,10 +1431,14 @@ __cgfsng_ops static inline bool 
cgfsng_payload_create(struct cgroup_ops *ops,
                        return false;
 
                for (i = 0; ops->hierarchies[i]; i++) {
-                       if 
(!container_create_path_for_hierarchy(ops->hierarchies[i], container_cgroup)) {
-                               ERROR("Failed to create cgroup \"%s\"", 
ops->hierarchies[i]->container_full_path);
+                       if 
(!container_create_path_for_hierarchy(ops->hierarchies[i],
+                                                                
container_cgroup)) {
+                               ERROR("Failed to create cgroup \"%s\"",
+                                     ops->hierarchies[i]->container_full_path);
                                for (int j = 0; j < i; j++)
-                                       
remove_path_for_hierarchy(ops->hierarchies[j], container_cgroup, false);
+                                       
remove_path_for_hierarchy(ops->hierarchies[j],
+                                                                 
container_cgroup,
+                                                                 false);
                                idx++;
                                break;
                        }

From c74da4abd20ede6a30c358dc275ba43b1d12e8d5 Mon Sep 17 00:00:00 2001
From: Christian Brauner <[email protected]>
Date: Sun, 10 Feb 2019 10:53:06 +0100
Subject: [PATCH 3/3] cgfsng: fix cgroup creation
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

When cgroup creation failed we reset container_cgroup to NULL to avoid
issues with __cleanup__. Fix that logic:
- add steal_ptr() based on take_ptr()
- move stealing the pointer out of the loop

lxc ctImport 20190210050705.858 DEBUG    network - 
network.c:instantiate_veth:202 - Instantiated veth "vethGQMH7I/vethSPXNL3", 
index is "272"
lxc ctImport 20190210050705.858 ERROR    cgfsng - 
cgroups/cgfsng.c:mkdir_eexist_on_last:1262 - File exists - Failed to create 
directory "/sys/fs/cgroup/unified//lxc.payload/ctImport-0"
lxc ctImport 20190210050705.858 ERROR    cgfsng - 
cgroups/cgfsng.c:container_create_path_for_hierarchy:1302 - Failed to create 
cgroup "/sys/fs/cgroup/unified//lxc.payload/ctImport-0"
lxc ctImport 20190210050705.858 ERROR    cgfsng - 
cgroups/cgfsng.c:cgfsng_payload_create:1431 - Failed to create cgroup 
"/sys/fs/cgroup/unified//lxc.payload/ctImport-0"
lxc ctImport 20190210050705.858 INFO     cgfsng - 
cgroups/cgfsng.c:cgfsng_payload_create:1441 - The container uses 
"lxc.payload/ctImport-0" as cgroup
lxc ctImport 20190210050705.858 ERROR    cgfsng - 
cgroups/cgfsng.c:mkdir_eexist_on_last:1262 - File exists - Failed to create 
directory "/sys/fs/cgroup/unified/"
lxc ctImport 20190210050705.858 ERROR    cgfsng - 
cgroups/cgfsng.c:container_create_path_for_hierarchy:1302 - Failed to create 
cgroup "/sys/fs/cgroup/unified/"
lxc ctImport 20190210050705.858 ERROR    cgfsng - 
cgroups/cgfsng.c:cgfsng_payload_create:1431 - Failed to create cgroup 
"/sys/fs/cgroup/unified/"
lxc ctImport 20190210050705.858 INFO     cgfsng - 
cgroups/cgfsng.c:cgfsng_payload_create:1441 - The container uses "(null)" as 
cgroup

Fixes: d97919abf22 ("cgroups: partially switch to cleanup macros")
Reported-by: Stéphane Graber <[email protected]>
Signed-off-by: Christian Brauner <[email protected]>
---
 src/lxc/cgroups/cgfsng.c | 15 +++++++--------
 src/lxc/macro.h          |  7 +++++++
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/lxc/cgroups/cgfsng.c b/src/lxc/cgroups/cgfsng.c
index 76c7647b5..971c6a523 100644
--- a/src/lxc/cgroups/cgfsng.c
+++ b/src/lxc/cgroups/cgfsng.c
@@ -1426,9 +1426,11 @@ __cgfsng_ops static inline bool 
cgfsng_payload_create(struct cgroup_ops *ops,
        offset = container_cgroup + len - 5;
 
        do {
-               int ret = snprintf(offset, 5, "-%d", idx);
-               if (ret < 0 || (size_t)ret >= 5)
-                       return false;
+               if (idx) {
+                       int ret = snprintf(offset, 5, "-%d", idx);
+                       if (ret < 0 || (size_t)ret >= 5)
+                               return false;
+               }
 
                for (i = 0; ops->hierarchies[i]; i++) {
                        if 
(!container_create_path_for_hierarchy(ops->hierarchies[i],
@@ -1443,16 +1445,13 @@ __cgfsng_ops static inline bool 
cgfsng_payload_create(struct cgroup_ops *ops,
                                break;
                        }
                }
-
-               ops->container_cgroup = container_cgroup;
-               container_cgroup = NULL;
-               INFO("The container uses \"%s\" as cgroup", 
ops->container_cgroup);
        } while (ops->hierarchies[i] && idx > 0 && idx < 1000);
 
        if (idx == 1000)
                return false;
 
-       INFO("The container process uses \"%s\" as cgroup", 
ops->container_cgroup);
+       INFO("The container process uses \"%s\" as cgroup", container_cgroup);
+       ops->container_cgroup = steal_ptr(container_cgroup);
        return true;
 }
 
diff --git a/src/lxc/macro.h b/src/lxc/macro.h
index 30aa2a5a5..14e12670e 100644
--- a/src/lxc/macro.h
+++ b/src/lxc/macro.h
@@ -392,4 +392,11 @@ enum {
 /* Maximum number of bytes sendfile() is able to send in one go. */
 #define LXC_SENDFILE_MAX 0x7ffff000
 
+#define steal_ptr(ptr)                     \
+       ({                                 \
+               typeof(ptr) _ptr_ = (ptr); \
+               (ptr) = NULL;              \
+               _ptr_;                     \
+       })
+
 #endif /* __LXC_MACRO_H */
_______________________________________________
lxc-devel mailing list
[email protected]
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to