diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-01-18 01:13:26 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-01-18 11:14:00 -0500 |
commit | 3f98659cce700fea91959312297950f15011b07b (patch) | |
tree | e472fa9b619c72e80e18e36dc323815a1973eeb4 /src | |
parent | 64abe9aa3f7dc7d755a4d3d1783fe3f0285edaea (diff) |
core/group-util: merge two functions
Diffstat (limited to 'src')
-rw-r--r-- | src/shared/cgroup-util.c | 44 |
1 files 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); } |