cgroups: rework __cg_unified_attach()

We didn't account for cgroup_attach() succeeding and just tried to attach to the same cgroup again which doesn't make sense. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 7c2c435c
...@@ -2194,23 +2194,27 @@ static int __cg_unified_attach(const struct hierarchy *h, ...@@ -2194,23 +2194,27 @@ static int __cg_unified_attach(const struct hierarchy *h,
const char *controller) const char *controller)
{ {
__do_close int unified_fd = -EBADF; __do_close int unified_fd = -EBADF;
__do_free char *path = NULL, *cgroup = NULL;
int ret; int ret;
if (!conf || !name || !lxcpath || pid <= 0) if (!conf || !name || !lxcpath || pid <= 0)
return ret_errno(EINVAL); return ret_errno(EINVAL);
ret = cgroup_attach(conf, name, lxcpath, pid); ret = cgroup_attach(conf, name, lxcpath, pid);
if (ret < 0) { if (ret == 0)
__do_free char *path = NULL, *cgroup = NULL; return log_trace(0, "Attached to unified cgroup via command handler");
if (ret != -EBADF)
return log_error_errno(ret, errno, "Failed to attach to unified cgroup");
cgroup = lxc_cmd_get_cgroup_path(name, lxcpath, controller); /* Fall back to retrieving the path for the unified cgroup. */
/* not running */ cgroup = lxc_cmd_get_cgroup_path(name, lxcpath, controller);
if (!cgroup) /* not running */
return 0; if (!cgroup)
return 0;
path = must_make_path(h->mountpoint, cgroup, NULL); path = must_make_path(h->mountpoint, cgroup, NULL);
unified_fd = open(path, O_DIRECTORY | O_RDONLY | O_CLOEXEC);
} unified_fd = open(path, O_PATH | O_DIRECTORY | O_CLOEXEC);
if (unified_fd < 0) if (unified_fd < 0)
return ret_errno(EBADF); return ret_errno(EBADF);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment