chiark / gitweb /
cgroup: use CGROUP_LIMIT_MAX where appropriate
authorLennart Poettering <lennart@poettering.net>
Wed, 17 Jan 2018 14:39:16 +0000 (15:39 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 30 May 2018 05:50:16 +0000 (07:50 +0200)
src/core/cgroup.c

index 0b69a8c56191d7c3988295b50952e5f0bd821454..8ebb3d2b93c6a916b1f9440b8643f2f994f02fd7 100644 (file)
@@ -1063,7 +1063,7 @@ CGroupMask cgroup_context_get_mask(CGroupContext *c) {
                 mask |= CGROUP_MASK_DEVICES;
 
         if (c->tasks_accounting ||
-            c->tasks_max != (uint64_t) -1)
+            c->tasks_max != CGROUP_LIMIT_MAX)
                 mask |= CGROUP_MASK_PIDS;
 
         return mask;
@@ -1828,31 +1828,6 @@ static int unit_watch_pids_in_path(Unit *u, const char *path) {
         return ret;
 }
 
-int unit_synthesize_cgroup_empty_event(Unit *u) {
-        int r;
-
-        assert(u);
-
-        /* Enqueue a synthetic cgroup empty event if this unit doesn't watch any PIDs anymore. This is compatibility
-         * support for non-unified systems where notifications aren't reliable, and hence need to take whatever we can
-         * get as notification source as soon as we stopped having any useful PIDs to watch for. */
-
-        if (!u->cgroup_path)
-                return -ENOENT;
-
-        r = cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER);
-        if (r < 0)
-                return r;
-        if (r > 0) /* On unified we have reliable notifications, and don't need this */
-                return 0;
-
-        if (!set_isempty(u->pids))
-                return 0;
-
-        unit_add_to_cgroup_empty_queue(u);
-        return 0;
-}
-
 int unit_watch_all_pids(Unit *u) {
         int r;
 
@@ -2223,46 +2198,40 @@ Unit* manager_get_unit_by_cgroup(Manager *m, const char *cgroup) {
 
 Unit *manager_get_unit_by_pid_cgroup(Manager *m, pid_t pid) {
         _cleanup_free_ char *cgroup = NULL;
+        int r;
 
         assert(m);
 
-        if (!pid_is_valid(pid))
+        if (pid <= 0)
                 return NULL;
 
-        if (cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &cgroup) < 0)
+        r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &cgroup);
+        if (r < 0)
                 return NULL;
 
         return manager_get_unit_by_cgroup(m, cgroup);
 }
 
 Unit *manager_get_unit_by_pid(Manager *m, pid_t pid) {
-        Unit *u, **array;
+        Unit *u;
 
         assert(m);
 
-        /* Note that a process might be owned by multiple units, we return only one here, which is good enough for most
-         * cases, though not strictly correct. We prefer the one reported by cgroup membership, as that's the most
-         * relevant one as children of the process will be assigned to that one, too, before all else. */
-
-        if (!pid_is_valid(pid))
+        if (pid <= 0)
                 return NULL;
 
-        if (pid == getpid_cached())
+        if (pid == 1)
                 return hashmap_get(m->units, SPECIAL_INIT_SCOPE);
 
-        u = manager_get_unit_by_pid_cgroup(m, pid);
+        u = hashmap_get(m->watch_pids1, PID_TO_PTR(pid));
         if (u)
                 return u;
 
-        u = hashmap_get(m->watch_pids, PID_TO_PTR(pid));
+        u = hashmap_get(m->watch_pids2, PID_TO_PTR(pid));
         if (u)
                 return u;
 
-        array = hashmap_get(m->watch_pids, PID_TO_PTR(-pid));
-        if (array)
-                return array[0];
-
-        return NULL;
+        return manager_get_unit_by_pid_cgroup(m, pid);
 }
 #endif // 0