* here: the first unit interested in a PID is stored in the hashmap 'watch_pids', keyed by the
* PID. If there are other units interested too they'll be stored in a NULL-terminated array, stored
* in the hashmap 'watch_pids_more', keyed by the PID. Thus to go through the full list of units
- * interested in a PID we must look into both hashmaps. */
+ * interested in a PID we must look into both hashmaps.
+ *
+ * NB: the ownership of PidRefs is held by Unit.pids! */
Hashmap *watch_pids; /* PidRef* → Unit* */
Hashmap *watch_pids_more; /* PidRef* → NUL terminated array of Unit* */
if (exclusive)
manager_unwatch_pidref(u->manager, pid);
- if (set_contains(u->pids, pid)) /* early exit if already being watched */
+ if (set_contains(u->pids, pid)) { /* early exit if already being watched */
+ assert(!exclusive);
return 0;
+ }
r = pidref_dup(pid, &pid_dup);
if (r < 0)
pid = TAKE_PTR(pid_dup); /* continue with our copy now that we have installed it properly in our set */
/* Second, insert it into the simple global table, see if that works */
- r = hashmap_ensure_put(&u->manager->watch_pids, &pidref_hash_ops_free, pid, u);
+ r = hashmap_ensure_put(&u->manager->watch_pids, &pidref_hash_ops, pid, u);
if (r != -EEXIST)
return r;
new_array[n+1] = NULL;
/* Add or replace the old array */
- r = hashmap_ensure_replace(&u->manager->watch_pids_more, &pidref_hash_ops_free, old_pid ?: pid, new_array);
+ r = hashmap_ensure_replace(&u->manager->watch_pids_more, &pidref_hash_ops, old_pid ?: pid, new_array);
if (r < 0)
return r;