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.
r = cg_pid_get_unit(pid, &unit);
if (r < 0)
r = cg_pid_get_unit(pid, &unit);
if (r < 0)
s = hashmap_get(m->session_units, unit);
if (!s)
s = hashmap_get(m->session_units, unit);
if (!s)
r = cg_pid_get_slice(pid, &unit);
if (r < 0)
r = cg_pid_get_slice(pid, &unit);
if (r < 0)
u = hashmap_get(m->user_units, unit);
if (!u)
u = hashmap_get(m->user_units, unit);
if (!u)
hashmap_remove(m->manager->machines, m->name);
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);
sd_bus_message_unref(m->create_message);
free(m->name);
if (m->started)
return 0;
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)
/* Create cgroup */
r = machine_start_scope(m, properties, error);
if (r < 0)
m->machines = hashmap_new(string_hash_func, string_compare_func);
m->machine_units = hashmap_new(string_hash_func, string_compare_func);
m->machines = hashmap_new(string_hash_func, string_compare_func);
m->machine_units = hashmap_new(string_hash_func, string_compare_func);
+ m->machine_leaders = hashmap_new(trivial_hash_func, trivial_compare_func);
- if (!m->machines || !m->machine_units) {
+ if (!m->machines || !m->machine_units || !m->machine_leaders) {
manager_free(m);
return NULL;
}
manager_free(m);
return NULL;
}
hashmap_free(m->machines);
hashmap_free(m->machine_units);
hashmap_free(m->machines);
hashmap_free(m->machine_units);
+ hashmap_free(m->machine_leaders);
sd_bus_unref(m->bus);
sd_event_unref(m->event);
sd_bus_unref(m->bus);
sd_event_unref(m->event);
r = cg_pid_get_unit(pid, &unit);
if (r < 0)
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_units, unit);
Hashmap *machines;
Hashmap *machine_units;
Hashmap *machines;
Hashmap *machine_units;
+ Hashmap *machine_leaders;
LIST_HEAD(Machine, machine_gc_queue);
};
LIST_HEAD(Machine, machine_gc_queue);
};