[systemd-devel] [PATCH v2 4/5] unified-cgroup: fix cg_pid_get_path() and cg_get_path().

Dimitri John Ledkov dimitri.j.ledkov at intel.com
Fri May 29 13:46:44 PDT 2015


---
 src/shared/cgroup-util.c    |  8 ++++++++
 src/test/test-cgroup-util.c | 18 ++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
index 2bca32a..eae9f5d 100644
--- a/src/shared/cgroup-util.c
+++ b/src/shared/cgroup-util.c
@@ -749,6 +749,11 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
         } else
                 controller = SYSTEMD_CGROUP_CONTROLLER;
 
+#ifdef HAVE_UNIFIED_CGROUP
+        if (!strcmp("systemd", controller))
+                controller = "";
+#endif
+
         fs = procfs_file_alloca(pid, "cgroup");
 
         f = fopen(fs, "re");
@@ -774,6 +779,9 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
                 if (!e)
                         continue;
 
+                if (cs == 0 && e == l)
+                        found = true;
+
                 *e = 0;
 
                 FOREACH_WORD_SEPARATOR(word, k, l, ",", state) {
diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c
index 015d3d7..59e2c7f 100644
--- a/src/test/test-cgroup-util.c
+++ b/src/test/test-cgroup-util.c
@@ -219,6 +219,22 @@ static void test_proc(void) {
         }
 }
 
+static void test_cg_pid_get_path(void) {
+        _cleanup_free_ char *path = NULL;
+
+        assert_se(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, 0, &path) == 0);
+
+        assert_se(cg_pid_get_path("", 0, &path) == 0);
+
+        assert_se(cg_pid_get_path(NULL, 0, &path) == 0);
+}
+
+static void test_cg_get_path(void) {
+        _cleanup_free_ char *path = NULL;
+
+        assert_se(cg_get_path(SYSTEMD_CGROUP_CONTROLLER, "", "", &path) == 0);
+}
+
 static void test_escape_one(const char *s, const char *r) {
         _cleanup_free_ char *b;
 
@@ -306,6 +322,8 @@ int main(void) {
         test_path_get_user_slice();
         TEST_REQ_RUNNING_SYSTEMD(test_get_paths());
         test_proc();
+        test_cg_pid_get_path();
+        test_cg_get_path();
         TEST_REQ_RUNNING_SYSTEMD(test_escape());
         test_controller_is_valid();
         test_slice_to_path();
-- 
2.1.4



More information about the systemd-devel mailing list