-static char *shortened_cgroup_path(pid_t pid) {
- int r;
- char _cleanup_free_ *process_path = NULL, *init_path = NULL;
- char *path;
-
- assert(pid > 0);
-
- r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, pid, &process_path);
- if (r < 0)
- return NULL;
-
- r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, 1, &init_path);
- if (r < 0)
- return NULL;
-
- if (endswith(init_path, "/system"))
- init_path[strlen(init_path) - 7] = 0;
- else if (streq(init_path, "/"))
- init_path[0] = 0;
-
- if (startswith(process_path, init_path)) {
- path = strdup(process_path + strlen(init_path));
- } else {
- path = process_path;
- process_path = NULL;
- }
-
- return path;
-}
-