diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-09-03 14:57:44 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-09-04 09:07:31 +0200 |
commit | b3ac818be8d73c97dc4f74ba8bbd2091506df2e6 (patch) | |
tree | b2c5055a9ba2fd3da48005e305ad27d3d273de9b /src/core/cgroup.c | |
parent | 569b19d8fedc4525a6c15f1a3ab9c15dcb7c694a (diff) |
core: split up manager_get_unit_by_pid()
Let's move the actual cgroup part of it into a new separate function
manager_get_unit_by_pid_cgroup(), and then make
manager_get_unit_by_pid() just a wrapper that also checks the two pid
hashmaps.
Then, let's make sure the various calls that want to deliver events to
the owners of a PID check both hashmaps and the cgroup and deliver the
event to *each* of them. OTOH make sure bus calls like GetUnitByPID()
continue to check the PID hashmaps first and the cgroup only as
fallback.
Diffstat (limited to 'src/core/cgroup.c')
-rw-r--r-- | src/core/cgroup.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 9f06b28f26..0a5a08aeba 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -1378,9 +1378,8 @@ Unit* manager_get_unit_by_cgroup(Manager *m, const char *cgroup) { } } -Unit *manager_get_unit_by_pid(Manager *m, pid_t pid) { +Unit *manager_get_unit_by_pid_cgroup(Manager *m, pid_t pid) { _cleanup_free_ char *cgroup = NULL; - Unit *u; int r; assert(m); @@ -1388,6 +1387,21 @@ Unit *manager_get_unit_by_pid(Manager *m, pid_t pid) { if (pid <= 0) return NULL; + r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &cgroup); + if (r < 0) + return NULL; + + return manager_get_unit_by_cgroup(m, cgroup); +} + +Unit *manager_get_unit_by_pid(Manager *m, pid_t pid) { + Unit *u; + + assert(m); + + if (pid <= 0) + return NULL; + if (pid == 1) return hashmap_get(m->units, SPECIAL_INIT_SCOPE); @@ -1399,11 +1413,7 @@ Unit *manager_get_unit_by_pid(Manager *m, pid_t pid) { if (u) return u; - r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &cgroup); - if (r < 0) - return NULL; - - return manager_get_unit_by_cgroup(m, cgroup); + return manager_get_unit_by_pid_cgroup(m, pid); } int manager_notify_cgroup_empty(Manager *m, const char *cgroup) { |