From d3e84ddb885e9d5f0ae9930eb905910e3a81f157 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 6 Nov 2013 02:03:04 +0100 Subject: machined: keep track of the initial leader PID of a machine This way we can without races always determine the machine for a leader PID. This allows machine managers to query the machine for a forked off container/VM without a race where the child might already have died before we could read the cgroup information from /proc/$PID/cgroup. --- src/machine/machine.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/machine/machine.c') diff --git a/src/machine/machine.c b/src/machine/machine.c index a33a111043..cf3ef15456 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -85,6 +85,9 @@ void machine_free(Machine *m) { hashmap_remove(m->manager->machines, m->name); + if (m->leader > 0) + hashmap_remove_value(m->manager->machine_leaders, UINT_TO_PTR(m->leader), m); + sd_bus_message_unref(m->create_message); free(m->name); @@ -263,6 +266,10 @@ int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error) { if (m->started) return 0; + r = hashmap_put(m->manager->machine_leaders, UINT_TO_PTR(m->leader), m); + if (r < 0) + return r; + /* Create cgroup */ r = machine_start_scope(m, properties, error); if (r < 0) -- cgit v1.2.3-54-g00ecf