summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-09-01 18:47:46 +0200
committerLennart Poettering <lennart@poettering.net>2015-09-01 18:47:46 +0200
commit5fe8876b320e9f6355425df9991ac38363684117 (patch)
treee332347c31f75f794de722e37045f6cc33ef27c6 /src
parent6fd66507378bd8706cba38f82167a54d9d116e43 (diff)
core: when looking for the unit for a process, look at the PID hashmaps first
It's cheaper that going to cgroupfs, and also usually the better choice since it's not racy and can map PIDs even if they were moved to a different unit.
Diffstat (limited to 'src')
-rw-r--r--src/core/cgroup.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index aafd75f424..e92d2cc850 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -1005,6 +1005,7 @@ Unit* manager_get_unit_by_cgroup(Manager *m, const char *cgroup) {
Unit *manager_get_unit_by_pid(Manager *m, pid_t pid) {
_cleanup_free_ char *cgroup = NULL;
+ Unit *u;
int r;
assert(m);
@@ -1012,6 +1013,14 @@ Unit *manager_get_unit_by_pid(Manager *m, pid_t pid) {
if (pid <= 1)
return NULL;
+ u = hashmap_get(m->watch_pids1, LONG_TO_PTR(pid));
+ if (u)
+ return u;
+
+ u = hashmap_get(m->watch_pids2, LONG_TO_PTR(pid));
+ if (u)
+ return u;
+
r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &cgroup);
if (r < 0)
return NULL;