diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-12-10 22:06:44 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-12-10 22:06:44 +0100 |
commit | 7b3fd6313c4b07b6f822a9f979d0c22350a401d9 (patch) | |
tree | 936f7fa948b9d5eb2e417204108353c13e6485a9 /src/core | |
parent | 0cd385d31814c8c1bc0c81d11ef321036b8b0921 (diff) |
scope: make attachment of initial PIDs a bit more robust
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/cgroup.c | 42 | ||||
-rw-r--r-- | src/core/cgroup.h | 1 | ||||
-rw-r--r-- | src/core/execute.c | 2 | ||||
-rw-r--r-- | src/core/scope.c | 6 |
4 files changed, 33 insertions, 18 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 83678e6e03..35b862d5c2 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -605,7 +605,6 @@ static const char *migrate_callback(CGroupControllerMask mask, void *userdata) { } static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) { - _cleanup_free_ char *path = NULL; CGroupContext *c; int r; @@ -615,18 +614,22 @@ static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) { if (!c) return 0; - path = unit_default_cgroup_path(u); - if (!path) - return log_oom(); + if (!u->cgroup_path) { + _cleanup_free_ char *path = NULL; - r = hashmap_put(u->manager->cgroup_unit, path, u); - if (r < 0) { - log_error(r == -EEXIST ? "cgroup %s exists already: %s" : "hashmap_put failed for %s: %s", path, strerror(-r)); - return r; - } - if (r > 0) { - u->cgroup_path = path; - path = NULL; + path = unit_default_cgroup_path(u); + if (!path) + return log_oom(); + + r = hashmap_put(u->manager->cgroup_unit, path, u); + if (r < 0) { + log_error(r == -EEXIST ? "cgroup %s exists already: %s" : "hashmap_put failed for %s: %s", path, strerror(-r)); + return r; + } + if (r > 0) { + u->cgroup_path = path; + path = NULL; + } } /* First, create our own group */ @@ -651,6 +654,21 @@ static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) { return 0; } +int unit_attach_pids_to_cgroup(Unit *u) { + int r; + assert(u); + + r = unit_realize_cgroup(u); + if (r < 0) + return r; + + r = cg_attach_many_everywhere(u->manager->cgroup_supported, u->cgroup_path, u->pids, migrate_callback, u); + if (r < 0) + return r; + + return 0; +} + static bool unit_has_mask_realized(Unit *u, CGroupControllerMask mask) { assert(u); diff --git a/src/core/cgroup.h b/src/core/cgroup.h index 16d661357b..7150e5e7e2 100644 --- a/src/core/cgroup.h +++ b/src/core/cgroup.h @@ -110,6 +110,7 @@ CGroupControllerMask unit_get_target_mask(Unit *u); void unit_update_cgroup_members_masks(Unit *u); int unit_realize_cgroup(Unit *u); void unit_destroy_cgroup_if_empty(Unit *u); +int unit_attach_pids_to_cgroup(Unit *u); int manager_setup_cgroup(Manager *m); void manager_shutdown_cgroup(Manager *m, bool delete); diff --git a/src/core/execute.c b/src/core/execute.c index 955090c446..5e4135e030 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -1351,7 +1351,7 @@ static int exec_child(ExecCommand *command, } if (params->cgroup_path) { - err = cg_attach_everywhere(params->cgroup_supported, params->cgroup_path, 0); + err = cg_attach_everywhere(params->cgroup_supported, params->cgroup_path, 0, NULL, NULL); if (err < 0) { *error = EXIT_CGROUP; return err; diff --git a/src/core/scope.c b/src/core/scope.c index f0efec0516..e0da6e4db7 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -288,11 +288,7 @@ static int scope_start(Unit *u) { if (!u->transient && UNIT(s)->manager->n_reloading <= 0) return -ENOENT; - r = unit_realize_cgroup(u); - if (r < 0) - return log_error_errno(r, "Failed to realize cgroup: %m"); - - r = cg_attach_many_everywhere(u->manager->cgroup_supported, u->cgroup_path, UNIT(s)->pids); + r = unit_attach_pids_to_cgroup(u); if (r < 0) return r; |