metadata: reflect change in task_cgroup_name
authorHristo Venev <hristo@venev.name>
Wed, 9 Apr 2014 17:20:29 +0000 (20:20 +0300)
committerDaniel Mack <zonque@gmail.com>
Wed, 9 Apr 2014 17:27:12 +0000 (19:27 +0200)
Change: e61734c55c24cdf11b07e52a74aec4dc4a7f4bd0.
Merged: dc5ed40686a4da95881c35d913b60f867755cbe2 in 3.15-rc1.

task_cgroup_name returns a pointer to the path or NULL if there is not
enough space in the buffer (used to return nonnegative or
-ENAMETOOLONG).

On systemd systems fixes a kernel panic about init dying while opening a
bus. Now it boots properly.

metadata.c

index 5b47bb2652d433de4c0b347a6d711f4f43565943..0db53922692a4c8440846f8da7b98660d84a0021 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/sizes.h>
 #include <linux/slab.h>
 #include <linux/uaccess.h>
+#include <linux/version.h>
 
 #include "connection.h"
 #include "message.h"
@@ -335,18 +336,29 @@ static int kdbus_meta_append_caps(struct kdbus_meta *meta)
 #ifdef CONFIG_CGROUPS
 static int kdbus_meta_append_cgroup(struct kdbus_meta *meta)
 {
-       char *tmp;
+       char *buf, *path;
        int ret;
 
-       tmp = (char *)__get_free_page(GFP_TEMPORARY | __GFP_ZERO);
-       if (!tmp)
+       buf = (char *)__get_free_page(GFP_TEMPORARY | __GFP_ZERO);
+       if (!buf)
                return -ENOMEM;
 
-       ret = task_cgroup_path(current, tmp, PAGE_SIZE);
-       if (ret >= 0)
-               ret = kdbus_meta_append_str(meta, KDBUS_ITEM_CGROUP, tmp);
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,15,0)
+       path = task_cgroup_path(current, buf, PAGE_SIZE);
+#else
+       ret = task_cgroup_path(current, buf, PAGE_SIZE);
+       if (ret < 0)
+               path = NULL;
+       else
+               path = buf;
+#endif
 
-       free_page((unsigned long) tmp);
+       if (path)
+               ret = kdbus_meta_append_str(meta, KDBUS_ITEM_CGROUP, path);
+       else
+               ret = -ENAMETOOLONG;
+
+       free_page((unsigned long) buf);
 
        return ret;
 }