chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
aa62a89
)
core: correctly unregister PIDs from PID hashtables
author
Lennart Poettering
<lennart@poettering.net>
Thu, 6 Mar 2014 01:19:42 +0000
(
02:19
+0100)
committer
Lennart Poettering
<lennart@poettering.net>
Thu, 6 Mar 2014 03:00:42 +0000
(
04:00
+0100)
src/core/unit.c
patch
|
blob
|
history
diff --git
a/src/core/unit.c
b/src/core/unit.c
index 2437ee3f66afd113763db4eab10167a8cf578d8f..85250ca2aa74a2dac7f0abc5026380d7cea903ba 100644
(file)
--- a/
src/core/unit.c
+++ b/
src/core/unit.c
@@
-1704,11
+1704,11
@@
int unit_watch_pid(Unit *u, pid_t pid) {
/* Watch a specific PID. We only support one or two units
* watching each PID for now, not more. */
/* Watch a specific PID. We only support one or two units
* watching each PID for now, not more. */
- r =
hashmap_ensure_allocated(&u->manager->watch_pids1
, trivial_hash_func, trivial_compare_func);
+ r =
set_ensure_allocated(&u->pids
, trivial_hash_func, trivial_compare_func);
if (r < 0)
return r;
if (r < 0)
return r;
- r =
set_ensure_allocated(&u->pids
, trivial_hash_func, trivial_compare_func);
+ r =
hashmap_ensure_allocated(&u->manager->watch_pids1
, trivial_hash_func, trivial_compare_func);
if (r < 0)
return r;
if (r < 0)
return r;
@@
-1737,7
+1737,17
@@
void unit_unwatch_pid(Unit *u, pid_t pid) {
set_remove(u->pids, LONG_TO_PTR(pid));
}
set_remove(u->pids, LONG_TO_PTR(pid));
}
-static int watch_pids_in_path(Unit *u, const char *path) {
+void unit_unwatch_all_pids(Unit *u) {
+ assert(u);
+
+ while (!set_isempty(u->pids))
+ unit_unwatch_pid(u, PTR_TO_LONG(set_first(u->pids)));
+
+ set_free(u->pids);
+ u->pids = NULL;
+}
+
+static int unit_watch_pids_in_path(Unit *u, const char *path) {
_cleanup_closedir_ DIR *d = NULL;
_cleanup_fclose_ FILE *f = NULL;
int ret = 0, r;
_cleanup_closedir_ DIR *d = NULL;
_cleanup_fclose_ FILE *f = NULL;
int ret = 0, r;
@@
-1775,7
+1785,7
@@
static int watch_pids_in_path(Unit *u, const char *path) {
if (!p)
return -ENOMEM;
if (!p)
return -ENOMEM;
- r = watch_pids_in_path(u, p);
+ r =
unit_
watch_pids_in_path(u, p);
if (r < 0 && ret >= 0)
ret = r;
}
if (r < 0 && ret >= 0)
ret = r;
}
@@
-1788,31
+1798,15
@@
static int watch_pids_in_path(Unit *u, const char *path) {
return ret;
}
return ret;
}
-
int unit_watch_all_pids(Unit *u) {
assert(u);
int unit_watch_all_pids(Unit *u) {
assert(u);
- if (!u->cgroup_path)
- return -ENOENT;
-
/* Adds all PIDs from our cgroup to the set of PIDs we watch */
/* Adds all PIDs from our cgroup to the set of PIDs we watch */
- return watch_pids_in_path(u, u->cgroup_path);
-}
-
-void unit_unwatch_all_pids(Unit *u) {
- Iterator i;
- void *e;
-
- assert(u);
-
- SET_FOREACH(e, u->pids, i) {
- hashmap_remove_value(u->manager->watch_pids1, e, u);
- hashmap_remove_value(u->manager->watch_pids2, e, u);
- }
+ if (!u->cgroup_path)
+ return -ENOENT;
- set_free(u->pids);
- u->pids = NULL;
+ return unit_watch_pids_in_path(u, u->cgroup_path);
}
void unit_tidy_watch_pids(Unit *u, pid_t except1, pid_t except2) {
}
void unit_tidy_watch_pids(Unit *u, pid_t except1, pid_t except2) {
@@
-1830,7
+1824,7
@@
void unit_tidy_watch_pids(Unit *u, pid_t except1, pid_t except2) {
continue;
if (!pid_is_unwaited(pid))
continue;
if (!pid_is_unwaited(pid))
-
set_remove(u->pids, e
);
+
unit_unwatch_pid(u, pid
);
}
}
}
}