From 3f98659cce700fea91959312297950f15011b07b Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Fri, 18 Jan 2013 01:13:26 -0500 Subject: core/group-util: merge two functions --- src/shared/cgroup-util.c | 44 ++++++++------------------------------------ 1 file changed, 8 insertions(+), 36 deletions(-) diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c index 3d12233a1b..af5227848d 100644 --- a/src/shared/cgroup-util.c +++ b/src/shared/cgroup-util.c @@ -1277,9 +1277,9 @@ static int cgroup_to_unit(char *cgroup, char **unit){ return 0; } -int cg_pid_get_unit(pid_t pid, char **unit) { +static int cg_pid_get(const char *prefix, pid_t pid, char **unit) { int r; - char *cgroup; + char _cleanup_free_ *cgroup = NULL; assert(pid >= 0); assert(unit); @@ -1288,45 +1288,17 @@ int cg_pid_get_unit(pid_t pid, char **unit) { if (r < 0) return r; - if (!startswith(cgroup, "/system/")) { - free(cgroup); + if (!startswith(cgroup, prefix)) return -ENOENT; - } r = cgroup_to_unit(cgroup, unit); - if (r < 0){ - free(cgroup); - return r; - } - - free(cgroup); + return r; +} - return 0; +int cg_pid_get_unit(pid_t pid, char **unit) { + return cg_pid_get("/system/", pid, unit); } int cg_pid_get_user_unit(pid_t pid, char **unit) { - int r; - char *cgroup; - - assert(pid >= 0); - assert(unit); - - r = cg_pid_get_cgroup(pid, NULL, &cgroup); - if (r < 0) - return r; - - if (!startswith(cgroup, "/user/")) { - free(cgroup); - return -ENOENT; - } - - r = cgroup_to_unit(cgroup, unit); - if (r < 0) { - free(cgroup); - return r; - } - - free(cgroup); - - return 0; + return cg_pid_get("/user/", pid, unit); } -- cgit v1.2.3-54-g00ecf