From: Lennart Poettering Date: Wed, 17 Jan 2018 14:39:16 +0000 (+0100) Subject: cgroup: use CGROUP_LIMIT_MAX where appropriate X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=729aa3508600f570c9bb37e2e8c8253c0106dc56;p=elogind.git cgroup: use CGROUP_LIMIT_MAX where appropriate --- diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 0b69a8c56..8ebb3d2b9 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -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