]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroups: rework __cg_unified_attach() 3330/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Fri, 27 Mar 2020 10:05:50 +0000 (11:05 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Fri, 27 Mar 2020 10:47:49 +0000 (11:47 +0100)
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: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfsng.c

index 387350b4363fc54ea1748e1a6a82dee2ef148c0f..4bcdf0c925d98a4f02ed1526863a38f7889a92a6 100644 (file)
@@ -2194,23 +2194,27 @@ static int __cg_unified_attach(const struct hierarchy *h,
                               const char *controller)
 {
        __do_close int unified_fd = -EBADF;
+       __do_free char *path = NULL, *cgroup = NULL;
        int ret;
 
        if (!conf || !name || !lxcpath || pid <= 0)
                return ret_errno(EINVAL);
 
        ret = cgroup_attach(conf, name, lxcpath, pid);
-       if (ret < 0) {
-               __do_free char *path = NULL, *cgroup = NULL;
+       if (ret == 0)
+               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);
-               /* not running */
-               if (!cgroup)
-                       return 0;
+       /* Fall back to retrieving the path for the unified cgroup. */
+       cgroup = lxc_cmd_get_cgroup_path(name, lxcpath, controller);
+       /* not running */
+       if (!cgroup)
+               return 0;
 
-               path = must_make_path(h->mountpoint, cgroup, NULL);
-               unified_fd = open(path, O_DIRECTORY | O_RDONLY | O_CLOEXEC);
-       }
+       path = must_make_path(h->mountpoint, cgroup, NULL);
+
+       unified_fd = open(path, O_PATH | O_DIRECTORY | O_CLOEXEC);
        if (unified_fd < 0)
                return ret_errno(EBADF);