daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
65878a
From 8581dc72de05227a236b6ff3751c40f1e0be1b2f Mon Sep 17 00:00:00 2001
65878a
From: Lennart Poettering <lennart@poettering.net>
65878a
Date: Thu, 6 Mar 2014 02:19:42 +0100
65878a
Subject: [PATCH] core: correctly unregister PIDs from PID hashtables
65878a
65878a
Conflicts:
65878a
	src/core/unit.c
65878a
---
65878a
 src/core/unit.c | 41 ++++++++++++++++++-----------------------
65878a
 1 file changed, 18 insertions(+), 23 deletions(-)
65878a
65878a
diff --git a/src/core/unit.c b/src/core/unit.c
65878a
index a510eb2..6ee34ec 100644
65878a
--- a/src/core/unit.c
65878a
+++ b/src/core/unit.c
65878a
@@ -1668,11 +1668,11 @@ int unit_watch_pid(Unit *u, pid_t pid) {
65878a
         /* Watch a specific PID. We only support one or two units
65878a
          * watching each PID for now, not more. */
65878a
 
65878a
-        r = hashmap_ensure_allocated(&u->manager->watch_pids1, trivial_hash_func, trivial_compare_func);
65878a
+        r = set_ensure_allocated(&u->pids, trivial_hash_func, trivial_compare_func);
65878a
         if (r < 0)
65878a
                 return r;
65878a
 
65878a
-        r = set_ensure_allocated(&u->pids, trivial_hash_func, trivial_compare_func);
65878a
+        r = hashmap_ensure_allocated(&u->manager->watch_pids1, trivial_hash_func, trivial_compare_func);
65878a
         if (r < 0)
65878a
                 return r;
65878a
 
65878a
@@ -1701,7 +1701,17 @@ void unit_unwatch_pid(Unit *u, pid_t pid) {
65878a
         set_remove(u->pids, LONG_TO_PTR(pid));
65878a
 }
65878a
 
65878a
-static int watch_pids_in_path(Unit *u, const char *path) {
65878a
+void unit_unwatch_all_pids(Unit *u) {
65878a
+        assert(u);
65878a
+
65878a
+        while (!set_isempty(u->pids))
65878a
+                unit_unwatch_pid(u, PTR_TO_LONG(set_first(u->pids)));
65878a
+
65878a
+        set_free(u->pids);
65878a
+        u->pids = NULL;
65878a
+}
65878a
+
65878a
+static int unit_watch_pids_in_path(Unit *u, const char *path) {
65878a
         _cleanup_closedir_ DIR *d = NULL;
65878a
         _cleanup_fclose_ FILE *f = NULL;
65878a
         int ret = 0, r;
65878a
@@ -1739,7 +1749,7 @@ static int watch_pids_in_path(Unit *u, const char *path) {
65878a
                         if (!p)
65878a
                                 return -ENOMEM;
65878a
 
65878a
-                        r = watch_pids_in_path(u, p);
65878a
+                        r = unit_watch_pids_in_path(u, p);
65878a
                         if (r < 0 && ret >= 0)
65878a
                                 ret = r;
65878a
                 }
65878a
@@ -1756,27 +1766,12 @@ static int watch_pids_in_path(Unit *u, const char *path) {
65878a
 int unit_watch_all_pids(Unit *u) {
65878a
         assert(u);
65878a
 
65878a
-        if (!u->cgroup_path)
65878a
-                return -ENOENT;
65878a
-
65878a
         /* Adds all PIDs from our cgroup to the set of PIDs we watch */
65878a
 
65878a
-        return watch_pids_in_path(u, u->cgroup_path);
65878a
-}
65878a
-
65878a
-void unit_unwatch_all_pids(Unit *u) {
65878a
-        Iterator i;
65878a
-        void *e;
65878a
-
65878a
-        assert(u);
65878a
-
65878a
-        SET_FOREACH(e, u->pids, i) {
65878a
-                hashmap_remove_value(u->manager->watch_pids1, e, u);
65878a
-                hashmap_remove_value(u->manager->watch_pids2, e, u);
65878a
-        }
65878a
+        if (!u->cgroup_path)
65878a
+                return -ENOENT;
65878a
 
65878a
-        set_free(u->pids);
65878a
-        u->pids = NULL;
65878a
+        return unit_watch_pids_in_path(u, u->cgroup_path);
65878a
 }
65878a
 
65878a
 void unit_tidy_watch_pids(Unit *u, pid_t except1, pid_t except2) {
65878a
@@ -1794,7 +1789,7 @@ void unit_tidy_watch_pids(Unit *u, pid_t except1, pid_t except2) {
65878a
                         continue;
65878a
 
65878a
                 if (kill(pid, 0) < 0 && errno == ESRCH)
65878a
-                        set_remove(u->pids, e);
65878a
+                        unit_unwatch_pid(u, pid);
65878a
         }
65878a
 }
65878a