mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-07-15 14:15:22 +00:00
cgfsng: fix cgroup creation
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: d97919abf2
("cgroups: partially switch to cleanup macros")
Reported-by: Stéphane Graber <stgraber@ubuntu.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
parent
d99d5c935a
commit
c74da4abd2
@ -1426,9 +1426,11 @@ __cgfsng_ops static inline bool cgfsng_payload_create(struct cgroup_ops *ops,
|
|||||||
offset = container_cgroup + len - 5;
|
offset = container_cgroup + len - 5;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
int ret = snprintf(offset, 5, "-%d", idx);
|
if (idx) {
|
||||||
if (ret < 0 || (size_t)ret >= 5)
|
int ret = snprintf(offset, 5, "-%d", idx);
|
||||||
return false;
|
if (ret < 0 || (size_t)ret >= 5)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; ops->hierarchies[i]; i++) {
|
for (i = 0; ops->hierarchies[i]; i++) {
|
||||||
if (!container_create_path_for_hierarchy(ops->hierarchies[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;
|
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);
|
} while (ops->hierarchies[i] && idx > 0 && idx < 1000);
|
||||||
|
|
||||||
if (idx == 1000)
|
if (idx == 1000)
|
||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -392,4 +392,11 @@ enum {
|
|||||||
/* Maximum number of bytes sendfile() is able to send in one go. */
|
/* Maximum number of bytes sendfile() is able to send in one go. */
|
||||||
#define LXC_SENDFILE_MAX 0x7ffff000
|
#define LXC_SENDFILE_MAX 0x7ffff000
|
||||||
|
|
||||||
|
#define steal_ptr(ptr) \
|
||||||
|
({ \
|
||||||
|
typeof(ptr) _ptr_ = (ptr); \
|
||||||
|
(ptr) = NULL; \
|
||||||
|
_ptr_; \
|
||||||
|
})
|
||||||
|
|
||||||
#endif /* __LXC_MACRO_H */
|
#endif /* __LXC_MACRO_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user