]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
machined: always look for leader PID first
authorLennart Poettering <lennart@poettering.net>
Sun, 23 Aug 2015 12:04:31 +0000 (14:04 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 24 Aug 2015 20:46:45 +0000 (22:46 +0200)
When looking for the machine belonging to a PID, always look for the
leader first, only then fall back to a cgroup check. We keep direct
track of the leader PID, but only indirectly of the cgroup, hence prefer
the PID.

src/machine/machined-dbus.c

index da3ab26e898a212657b7b8cf76d3172d7dea6a16..93514986f32ad3c97c16ad29dc1cf5d5aaafdc5e 100644 (file)
@@ -1477,7 +1477,6 @@ int manager_job_is_active(Manager *manager, const char *path) {
 }
 
 int manager_get_machine_by_pid(Manager *m, pid_t pid, Machine **machine) {
-        _cleanup_free_ char *unit = NULL;
         Machine *mm;
         int r;
 
@@ -1485,12 +1484,14 @@ int manager_get_machine_by_pid(Manager *m, pid_t pid, Machine **machine) {
         assert(pid >= 1);
         assert(machine);
 
-        r = cg_pid_get_unit(pid, &unit);
-        if (r < 0)
-                mm = hashmap_get(m->machine_leaders, UINT_TO_PTR(pid));
-        else
-                mm = hashmap_get(m->machine_units, unit);
+        mm = hashmap_get(m->machine_leaders, UINT_TO_PTR(pid));
+        if (!mm) {
+                _cleanup_free_ char *unit = NULL;
 
+                r = cg_pid_get_unit(pid, &unit);
+                if (r >= 0)
+                        mm = hashmap_get(m->machine_units, unit);
+        }
         if (!mm)
                 return 0;