scope: make attachment of initial PIDs a bit more robust
This commit is contained in:
parent
0cd385d318
commit
7b3fd6313c
|
@ -605,7 +605,6 @@ static const char *migrate_callback(CGroupControllerMask mask, void *userdata) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) {
|
static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) {
|
||||||
_cleanup_free_ char *path = NULL;
|
|
||||||
CGroupContext *c;
|
CGroupContext *c;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
@ -615,18 +614,22 @@ static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) {
|
||||||
if (!c)
|
if (!c)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
path = unit_default_cgroup_path(u);
|
if (!u->cgroup_path) {
|
||||||
if (!path)
|
_cleanup_free_ char *path = NULL;
|
||||||
return log_oom();
|
|
||||||
|
|
||||||
r = hashmap_put(u->manager->cgroup_unit, path, u);
|
path = unit_default_cgroup_path(u);
|
||||||
if (r < 0) {
|
if (!path)
|
||||||
log_error(r == -EEXIST ? "cgroup %s exists already: %s" : "hashmap_put failed for %s: %s", path, strerror(-r));
|
return log_oom();
|
||||||
return r;
|
|
||||||
}
|
r = hashmap_put(u->manager->cgroup_unit, path, u);
|
||||||
if (r > 0) {
|
if (r < 0) {
|
||||||
u->cgroup_path = path;
|
log_error(r == -EEXIST ? "cgroup %s exists already: %s" : "hashmap_put failed for %s: %s", path, strerror(-r));
|
||||||
path = NULL;
|
return r;
|
||||||
|
}
|
||||||
|
if (r > 0) {
|
||||||
|
u->cgroup_path = path;
|
||||||
|
path = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* First, create our own group */
|
/* First, create our own group */
|
||||||
|
@ -651,6 +654,21 @@ static int unit_create_cgroups(Unit *u, CGroupControllerMask mask) {
|
||||||
return 0;
|
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) {
|
static bool unit_has_mask_realized(Unit *u, CGroupControllerMask mask) {
|
||||||
assert(u);
|
assert(u);
|
||||||
|
|
||||||
|
|
|
@ -110,6 +110,7 @@ CGroupControllerMask unit_get_target_mask(Unit *u);
|
||||||
void unit_update_cgroup_members_masks(Unit *u);
|
void unit_update_cgroup_members_masks(Unit *u);
|
||||||
int unit_realize_cgroup(Unit *u);
|
int unit_realize_cgroup(Unit *u);
|
||||||
void unit_destroy_cgroup_if_empty(Unit *u);
|
void unit_destroy_cgroup_if_empty(Unit *u);
|
||||||
|
int unit_attach_pids_to_cgroup(Unit *u);
|
||||||
|
|
||||||
int manager_setup_cgroup(Manager *m);
|
int manager_setup_cgroup(Manager *m);
|
||||||
void manager_shutdown_cgroup(Manager *m, bool delete);
|
void manager_shutdown_cgroup(Manager *m, bool delete);
|
||||||
|
|
|
@ -1351,7 +1351,7 @@ static int exec_child(ExecCommand *command,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->cgroup_path) {
|
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) {
|
if (err < 0) {
|
||||||
*error = EXIT_CGROUP;
|
*error = EXIT_CGROUP;
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -288,11 +288,7 @@ static int scope_start(Unit *u) {
|
||||||
if (!u->transient && UNIT(s)->manager->n_reloading <= 0)
|
if (!u->transient && UNIT(s)->manager->n_reloading <= 0)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
r = unit_realize_cgroup(u);
|
r = unit_attach_pids_to_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);
|
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
|
|
@ -1624,7 +1624,7 @@ int cg_create_everywhere(CGroupControllerMask supported, CGroupControllerMask ma
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cg_attach_everywhere(CGroupControllerMask supported, const char *path, pid_t pid) {
|
int cg_attach_everywhere(CGroupControllerMask supported, const char *path, pid_t pid, cg_migrate_callback_t path_callback, void *userdata) {
|
||||||
CGroupControllerMask bit = 1;
|
CGroupControllerMask bit = 1;
|
||||||
const char *n;
|
const char *n;
|
||||||
int r;
|
int r;
|
||||||
|
@ -1634,8 +1634,18 @@ int cg_attach_everywhere(CGroupControllerMask supported, const char *path, pid_t
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
NULSTR_FOREACH(n, mask_names) {
|
NULSTR_FOREACH(n, mask_names) {
|
||||||
if (supported & bit)
|
|
||||||
|
if (supported & bit) {
|
||||||
|
const char *p = NULL;
|
||||||
|
|
||||||
|
if (path_callback)
|
||||||
|
p = path_callback(bit, userdata);
|
||||||
|
|
||||||
|
if (!p)
|
||||||
|
p = path;
|
||||||
|
|
||||||
cg_attach_fallback(n, path, pid);
|
cg_attach_fallback(n, path, pid);
|
||||||
|
}
|
||||||
|
|
||||||
bit <<= 1;
|
bit <<= 1;
|
||||||
}
|
}
|
||||||
|
@ -1643,7 +1653,7 @@ int cg_attach_everywhere(CGroupControllerMask supported, const char *path, pid_t
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int cg_attach_many_everywhere(CGroupControllerMask supported, const char *path, Set* pids) {
|
int cg_attach_many_everywhere(CGroupControllerMask supported, const char *path, Set* pids, cg_migrate_callback_t path_callback, void *userdata) {
|
||||||
Iterator i;
|
Iterator i;
|
||||||
void *pidp;
|
void *pidp;
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
@ -1652,7 +1662,7 @@ int cg_attach_many_everywhere(CGroupControllerMask supported, const char *path,
|
||||||
pid_t pid = PTR_TO_LONG(pidp);
|
pid_t pid = PTR_TO_LONG(pidp);
|
||||||
int q;
|
int q;
|
||||||
|
|
||||||
q = cg_attach_everywhere(supported, path, pid);
|
q = cg_attach_everywhere(supported, path, pid, path_callback, userdata);
|
||||||
if (q < 0)
|
if (q < 0)
|
||||||
r = q;
|
r = q;
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,8 +126,8 @@ int cg_slice_to_path(const char *unit, char **ret);
|
||||||
typedef const char* (*cg_migrate_callback_t)(CGroupControllerMask mask, void *userdata);
|
typedef const char* (*cg_migrate_callback_t)(CGroupControllerMask mask, void *userdata);
|
||||||
|
|
||||||
int cg_create_everywhere(CGroupControllerMask supported, CGroupControllerMask mask, const char *path);
|
int cg_create_everywhere(CGroupControllerMask supported, CGroupControllerMask mask, const char *path);
|
||||||
int cg_attach_everywhere(CGroupControllerMask supported, const char *path, pid_t pid);
|
int cg_attach_everywhere(CGroupControllerMask supported, const char *path, pid_t pid, cg_migrate_callback_t callback, void *userdata);
|
||||||
int cg_attach_many_everywhere(CGroupControllerMask supported, const char *path, Set* pids);
|
int cg_attach_many_everywhere(CGroupControllerMask supported, const char *path, Set* pids, cg_migrate_callback_t callback, void *userdata);
|
||||||
int cg_migrate_everywhere(CGroupControllerMask supported, const char *from, const char *to, cg_migrate_callback_t callback, void *userdata);
|
int cg_migrate_everywhere(CGroupControllerMask supported, const char *from, const char *to, cg_migrate_callback_t callback, void *userdata);
|
||||||
int cg_trim_everywhere(CGroupControllerMask supported, const char *path, bool delete_root);
|
int cg_trim_everywhere(CGroupControllerMask supported, const char *path, bool delete_root);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue