cgroup-setup: drop unnecessary controller argument
This also removes unnecessary cg_{create,attach,trim}_everywhere(),
and rename cg_enable_everywhere() -> cg_enable().
This commit is contained in:
+8
-8
@@ -2379,7 +2379,7 @@ static int unit_update_cgroup(
|
||||
CGroupRuntime *crt = ASSERT_PTR(unit_get_cgroup_runtime(u));
|
||||
|
||||
/* First, create our own group */
|
||||
r = cg_create_everywhere(u->manager->cgroup_supported, target_mask, crt->cgroup_path);
|
||||
r = cg_create(crt->cgroup_path);
|
||||
if (r < 0)
|
||||
return log_unit_error_errno(u, r, "Failed to create cgroup %s: %m", empty_to_root(crt->cgroup_path));
|
||||
created = r;
|
||||
@@ -2405,7 +2405,7 @@ static int unit_update_cgroup(
|
||||
CGroupMask result_mask = 0;
|
||||
|
||||
/* Enable all controllers we need */
|
||||
r = cg_enable_everywhere(u->manager->cgroup_supported, enable_mask, crt->cgroup_path, &result_mask);
|
||||
r = cg_enable(u->manager->cgroup_supported, enable_mask, crt->cgroup_path, &result_mask);
|
||||
if (r < 0)
|
||||
log_unit_warning_errno(u, r, "Failed to enable/disable controllers on cgroup %s, ignoring: %m", empty_to_root(crt->cgroup_path));
|
||||
|
||||
@@ -2515,7 +2515,7 @@ int unit_attach_pids_to_cgroup(Unit *u, Set *pids, const char *suffix_path) {
|
||||
continue;
|
||||
}
|
||||
|
||||
r = cg_attach(SYSTEMD_CGROUP_CONTROLLER, p, pid->pid);
|
||||
r = cg_attach(p, pid->pid);
|
||||
if (r < 0) {
|
||||
bool again = MANAGER_IS_USER(u->manager) && ERRNO_IS_NEG_PRIVILEGE(r);
|
||||
|
||||
@@ -2590,7 +2590,7 @@ int unit_remove_subcgroup(Unit *u, const char *suffix_path) {
|
||||
|
||||
log_unit_debug(u, "Removing subcgroup '%s'...", d);
|
||||
|
||||
r = cg_trim_everywhere(u->manager->cgroup_supported, d, delete_root);
|
||||
r = cg_trim(d, delete_root);
|
||||
if (r < 0)
|
||||
return log_unit_debug_errno(u, r, "Failed to fully %s cgroup '%s': %m", delete_root ? "remove" : "trim", d);
|
||||
|
||||
@@ -3113,7 +3113,7 @@ void unit_prune_cgroup(Unit *u) {
|
||||
|
||||
is_root_slice = unit_has_name(u, SPECIAL_ROOT_SLICE);
|
||||
|
||||
r = cg_trim_everywhere(u->manager->cgroup_supported, crt->cgroup_path, !is_root_slice);
|
||||
r = cg_trim(crt->cgroup_path, !is_root_slice);
|
||||
if (r < 0) {
|
||||
int k = unit_prune_cgroup_via_bus(u);
|
||||
|
||||
@@ -3614,10 +3614,10 @@ int manager_setup_cgroup(Manager *m) {
|
||||
|
||||
/* 5. Make sure we are in the special "init.scope" unit in the root slice. */
|
||||
const char *scope_path = strjoina(m->cgroup_root, "/" SPECIAL_INIT_SCOPE);
|
||||
r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, scope_path, /* pid = */ 0);
|
||||
r = cg_create_and_attach(scope_path, /* pid = */ 0);
|
||||
if (r >= 0) {
|
||||
/* Also, move all other userspace processes remaining in the root cgroup into that scope. */
|
||||
r = cg_migrate(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_root, SYSTEMD_CGROUP_CONTROLLER, scope_path, 0);
|
||||
r = cg_migrate(m->cgroup_root, scope_path, 0);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Couldn't move remaining userspace processes, ignoring: %m");
|
||||
|
||||
@@ -3650,7 +3650,7 @@ void manager_shutdown_cgroup(Manager *m, bool delete) {
|
||||
/* We can't really delete the group, since we are in it. But
|
||||
* let's trim it. */
|
||||
if (delete && m->cgroup_root && !FLAGS_SET(m->test_run_flags, MANAGER_TEST_RUN_MINIMAL))
|
||||
(void) cg_trim(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_root, false);
|
||||
(void) cg_trim(m->cgroup_root, false);
|
||||
|
||||
m->cgroup_empty_event_source = sd_event_source_disable_unref(m->cgroup_empty_event_source);
|
||||
|
||||
|
||||
@@ -4967,7 +4967,7 @@ int exec_invoke(
|
||||
return log_exec_error_errno(context, params, r, "Failed to acquire cgroup path: %m");
|
||||
}
|
||||
|
||||
r = cg_attach_everywhere(params->cgroup_supported, p, 0);
|
||||
r = cg_attach(p, 0);
|
||||
if (r == -EUCLEAN) {
|
||||
*exit_status = EXIT_CGROUP;
|
||||
return log_exec_error_errno(context, params, r,
|
||||
@@ -5190,7 +5190,7 @@ int exec_invoke(
|
||||
if (params->flags & EXEC_CGROUP_DELEGATE) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
|
||||
r = cg_set_access(SYSTEMD_CGROUP_CONTROLLER, params->cgroup_path, uid, gid);
|
||||
r = cg_set_access(params->cgroup_path, uid, gid);
|
||||
if (r < 0) {
|
||||
*exit_status = EXIT_CGROUP;
|
||||
return log_exec_error_errno(context, params, r, "Failed to adjust control group access: %m");
|
||||
@@ -5202,7 +5202,7 @@ int exec_invoke(
|
||||
return log_exec_error_errno(context, params, r, "Failed to acquire cgroup path: %m");
|
||||
}
|
||||
if (r > 0) {
|
||||
r = cg_set_access_recursive(SYSTEMD_CGROUP_CONTROLLER, p, uid, gid);
|
||||
r = cg_set_access_recursive(p, uid, gid);
|
||||
if (r < 0) {
|
||||
*exit_status = EXIT_CGROUP;
|
||||
return log_exec_error_errno(context, params, r, "Failed to adjust control subgroup access: %m");
|
||||
|
||||
+2
-2
@@ -508,7 +508,7 @@ int exec_spawn(
|
||||
/* If there's a subcgroup, then let's create it here now (the main cgroup was already
|
||||
* realized by the unit logic) */
|
||||
|
||||
r = cg_create(SYSTEMD_CGROUP_CONTROLLER, subcgroup_path);
|
||||
r = cg_create(subcgroup_path);
|
||||
if (r < 0)
|
||||
return log_unit_error_errno(unit, r, "Failed to create subcgroup '%s': %m", subcgroup_path);
|
||||
}
|
||||
@@ -593,7 +593,7 @@ int exec_spawn(
|
||||
* executed outside of the cgroup) and in the parent (so that we can be sure that when we kill the cgroup the
|
||||
* process will be killed too). */
|
||||
if (r == 0 && subcgroup_path)
|
||||
(void) cg_attach(SYSTEMD_CGROUP_CONTROLLER, subcgroup_path, pidref.pid);
|
||||
(void) cg_attach(subcgroup_path, pidref.pid);
|
||||
/* r > 0: Already in the right cgroup thanks to CLONE_INTO_CGROUP */
|
||||
|
||||
log_unit_debug(unit, "Forked %s as " PID_FMT " (%s CLONE_INTO_CGROUP)",
|
||||
|
||||
+1
-1
@@ -371,7 +371,7 @@ static int scope_enter_start_chown(Scope *s) {
|
||||
}
|
||||
}
|
||||
|
||||
r = cg_set_access(SYSTEMD_CGROUP_CONTROLLER, s->cgroup_runtime->cgroup_path, uid, gid);
|
||||
r = cg_set_access(s->cgroup_runtime->cgroup_path, uid, gid);
|
||||
if (r < 0) {
|
||||
log_unit_error_errno(UNIT(s), r, "Failed to adjust control group access: %m");
|
||||
_exit(EXIT_CGROUP);
|
||||
|
||||
+1
-1
@@ -5405,7 +5405,7 @@ int unit_fork_helper_process(Unit *u, const char *name, bool into_cgroup, PidRef
|
||||
(void) ignore_signals(SIGPIPE);
|
||||
|
||||
if (crt && crt->cgroup_path) {
|
||||
r = cg_attach_everywhere(u->manager->cgroup_supported, crt->cgroup_path, 0);
|
||||
r = cg_attach(crt->cgroup_path, 0);
|
||||
if (r < 0) {
|
||||
log_unit_error_errno(u, r, "Failed to join unit cgroup %s: %m", empty_to_root(crt->cgroup_path));
|
||||
_exit(EXIT_CGROUP);
|
||||
|
||||
@@ -88,9 +88,9 @@ int create_subcgroup(
|
||||
return log_oom();
|
||||
|
||||
if (userns_mode != USER_NAMESPACE_MANAGED)
|
||||
r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, payload, pid);
|
||||
r = cg_create_and_attach(payload, pid);
|
||||
else
|
||||
r = cg_create(SYSTEMD_CGROUP_CONTROLLER, payload);
|
||||
r = cg_create(payload);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create %s subcgroup: %m", payload);
|
||||
|
||||
@@ -125,13 +125,13 @@ int create_subcgroup(
|
||||
if (!supervisor)
|
||||
return log_oom();
|
||||
|
||||
r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, supervisor, 0);
|
||||
r = cg_create_and_attach(supervisor, 0);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create %s subcgroup: %m", supervisor);
|
||||
}
|
||||
|
||||
/* Try to enable as many controllers as possible for the new payload. */
|
||||
(void) cg_enable_everywhere(supported, supported, cgroup, NULL);
|
||||
(void) cg_enable(supported, supported, cgroup, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ static void test_oomd_cgroup_kill(void) {
|
||||
* by the test so that pid1 doesn't delete it before we can read the xattrs. */
|
||||
cgroup = path_join(cgroup_root, "oomdkilltest");
|
||||
assert_se(cgroup);
|
||||
assert_se(cg_create(SYSTEMD_CGROUP_CONTROLLER, cgroup) >= 0);
|
||||
assert_se(cg_create(cgroup) >= 0);
|
||||
|
||||
/* If we don't have permissions to set xattrs we're likely in a userns or missing capabilities */
|
||||
r = cg_set_xattr(cgroup, "user.oomd_test", "test", 4, 0);
|
||||
@@ -65,7 +65,7 @@ static void test_oomd_cgroup_kill(void) {
|
||||
|
||||
for (int j = 0; j < 2; j++) {
|
||||
pid[j] = fork_and_sleep(5);
|
||||
assert_se(cg_attach(SYSTEMD_CGROUP_CONTROLLER, cgroup, pid[j]) >= 0);
|
||||
assert_se(cg_attach(cgroup, pid[j]) >= 0);
|
||||
}
|
||||
|
||||
r = oomd_cgroup_kill(cgroup, false /* recurse */, false /* dry run */);
|
||||
@@ -477,7 +477,7 @@ static void test_oomd_fetch_cgroup_oom_preference(void) {
|
||||
* owned by the same user. */
|
||||
if (test_xattrs && !empty_or_root(cgroup)) {
|
||||
ctx = oomd_cgroup_context_free(ctx);
|
||||
assert_se(cg_set_access(SYSTEMD_CGROUP_CONTROLLER, cgroup, 61183, 0) >= 0);
|
||||
assert_se(cg_set_access(cgroup, 61183, 0) >= 0);
|
||||
assert_se(oomd_cgroup_context_acquire(cgroup, &ctx) == 0);
|
||||
|
||||
assert_se(oomd_fetch_cgroup_oom_preference(ctx, NULL) == 0);
|
||||
|
||||
+19
-43
@@ -70,13 +70,11 @@ static int trim_cb(
|
||||
return RECURSE_DIR_CONTINUE;
|
||||
}
|
||||
|
||||
int cg_trim(const char *controller, const char *path, bool delete_root) {
|
||||
int cg_trim(const char *path, bool delete_root) {
|
||||
_cleanup_free_ char *fs = NULL;
|
||||
int r;
|
||||
|
||||
assert(controller);
|
||||
|
||||
r = cg_get_path(controller, path, NULL, &fs);
|
||||
r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -109,13 +107,11 @@ int cg_trim(const char *controller, const char *path, bool delete_root) {
|
||||
/* Create a cgroup in the hierarchy of controller.
|
||||
* Returns 0 if the group already existed, 1 on success, negative otherwise.
|
||||
*/
|
||||
int cg_create(const char *controller, const char *path) {
|
||||
int cg_create(const char *path) {
|
||||
_cleanup_free_ char *fs = NULL;
|
||||
int r;
|
||||
|
||||
assert(controller);
|
||||
|
||||
r = cg_get_path_and_check(controller, path, NULL, &fs);
|
||||
r = cg_get_path_and_check(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -132,16 +128,15 @@ int cg_create(const char *controller, const char *path) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int cg_attach(const char *controller, const char *path, pid_t pid) {
|
||||
int cg_attach(const char *path, pid_t pid) {
|
||||
_cleanup_free_ char *fs = NULL;
|
||||
char c[DECIMAL_STR_MAX(pid_t) + 2];
|
||||
int r;
|
||||
|
||||
assert(controller);
|
||||
assert(path);
|
||||
assert(pid >= 0);
|
||||
|
||||
r = cg_get_path_and_check(controller, path, "cgroup.procs", &fs);
|
||||
r = cg_get_path_and_check(SYSTEMD_CGROUP_CONTROLLER, path, "cgroup.procs", &fs);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -174,18 +169,18 @@ int cg_fd_attach(int fd, pid_t pid) {
|
||||
return write_string_file_at(fd, "cgroup.procs", c, WRITE_STRING_FILE_DISABLE_BUFFER);
|
||||
}
|
||||
|
||||
int cg_create_and_attach(const char *controller, const char *path, pid_t pid) {
|
||||
int cg_create_and_attach(const char *path, pid_t pid) {
|
||||
int r, q;
|
||||
|
||||
/* This does not remove the cgroup on failure */
|
||||
|
||||
assert(pid >= 0);
|
||||
|
||||
r = cg_create(controller, path);
|
||||
r = cg_create(path);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
q = cg_attach(controller, path, pid);
|
||||
q = cg_attach(path, pid);
|
||||
if (q < 0)
|
||||
return q;
|
||||
|
||||
@@ -193,7 +188,6 @@ int cg_create_and_attach(const char *controller, const char *path, pid_t pid) {
|
||||
}
|
||||
|
||||
int cg_set_access(
|
||||
const char *controller,
|
||||
const char *path,
|
||||
uid_t uid,
|
||||
gid_t gid) {
|
||||
@@ -218,7 +212,7 @@ int cg_set_access(
|
||||
return 0;
|
||||
|
||||
/* Configure access to the cgroup itself */
|
||||
r = cg_get_path(controller, path, NULL, &fs);
|
||||
r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -230,7 +224,7 @@ int cg_set_access(
|
||||
FOREACH_ELEMENT(i, attributes) {
|
||||
fs = mfree(fs);
|
||||
|
||||
r = cg_get_path(controller, path, i->name, &fs);
|
||||
r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, i->name, &fs);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -276,7 +270,6 @@ static int access_callback(
|
||||
}
|
||||
|
||||
int cg_set_access_recursive(
|
||||
const char *controller,
|
||||
const char *path,
|
||||
uid_t uid,
|
||||
gid_t gid) {
|
||||
@@ -285,7 +278,6 @@ int cg_set_access_recursive(
|
||||
_cleanup_free_ char *fs = NULL;
|
||||
int r;
|
||||
|
||||
assert(controller);
|
||||
assert(path);
|
||||
|
||||
/* A recursive version of cg_set_access(). But note that this one changes ownership of *all* files,
|
||||
@@ -295,7 +287,7 @@ int cg_set_access_recursive(
|
||||
if (!uid_is_valid(uid) && !gid_is_valid(gid))
|
||||
return 0;
|
||||
|
||||
r = cg_get_path(controller, path, NULL, &fs);
|
||||
r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, NULL, &fs);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
@@ -323,20 +315,16 @@ int cg_set_access_recursive(
|
||||
}
|
||||
|
||||
int cg_migrate(
|
||||
const char *cfrom,
|
||||
const char *pfrom,
|
||||
const char *cto,
|
||||
const char *pto,
|
||||
const char *from,
|
||||
const char *to,
|
||||
CGroupFlags flags) {
|
||||
|
||||
_cleanup_set_free_ Set *s = NULL;
|
||||
bool done;
|
||||
int r, ret = 0;
|
||||
|
||||
assert(cfrom);
|
||||
assert(pfrom);
|
||||
assert(cto);
|
||||
assert(pto);
|
||||
assert(from);
|
||||
assert(to);
|
||||
|
||||
do {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
@@ -344,7 +332,7 @@ int cg_migrate(
|
||||
|
||||
done = true;
|
||||
|
||||
r = cg_enumerate_processes(cfrom, pfrom, &f);
|
||||
r = cg_enumerate_processes(SYSTEMD_CGROUP_CONTROLLER, from, &f);
|
||||
if (r < 0)
|
||||
return RET_GATHER(ret, r);
|
||||
|
||||
@@ -364,7 +352,7 @@ int cg_migrate(
|
||||
if (pid_is_kernel_thread(pid) > 0)
|
||||
continue;
|
||||
|
||||
r = cg_attach(cto, pto, pid);
|
||||
r = cg_attach(to, pid);
|
||||
if (r < 0) {
|
||||
if (r != -ESRCH)
|
||||
RET_GATHER(ret, r);
|
||||
@@ -384,19 +372,7 @@ int cg_migrate(
|
||||
return ret;
|
||||
}
|
||||
|
||||
int cg_create_everywhere(CGroupMask supported, CGroupMask mask, const char *path) {
|
||||
return cg_create(SYSTEMD_CGROUP_CONTROLLER, path);
|
||||
}
|
||||
|
||||
int cg_attach_everywhere(CGroupMask supported, const char *path, pid_t pid) {
|
||||
return cg_attach(SYSTEMD_CGROUP_CONTROLLER, path, pid);
|
||||
}
|
||||
|
||||
int cg_trim_everywhere(CGroupMask supported, const char *path, bool delete_root) {
|
||||
return cg_trim(SYSTEMD_CGROUP_CONTROLLER, path, delete_root);
|
||||
}
|
||||
|
||||
int cg_enable_everywhere(
|
||||
int cg_enable(
|
||||
CGroupMask supported,
|
||||
CGroupMask mask,
|
||||
const char *p,
|
||||
|
||||
@@ -10,21 +10,18 @@
|
||||
int cg_weight_parse(const char *s, uint64_t *ret);
|
||||
int cg_cpu_weight_parse(const char *s, uint64_t *ret);
|
||||
|
||||
int cg_trim(const char *controller, const char *path, bool delete_root);
|
||||
int cg_trim(const char *path, bool delete_root);
|
||||
|
||||
int cg_create(const char *controller, const char *path);
|
||||
int cg_attach(const char *controller, const char *path, pid_t pid);
|
||||
int cg_create(const char *path);
|
||||
int cg_attach(const char *path, pid_t pid);
|
||||
int cg_fd_attach(int fd, pid_t pid);
|
||||
int cg_create_and_attach(const char *controller, const char *path, pid_t pid);
|
||||
int cg_create_and_attach(const char *path, pid_t pid);
|
||||
|
||||
int cg_set_access(const char *controller, const char *path, uid_t uid, gid_t gid);
|
||||
int cg_set_access_recursive(const char *controller, const char *path, uid_t uid, gid_t gid);
|
||||
int cg_set_access(const char *path, uid_t uid, gid_t gid);
|
||||
int cg_set_access_recursive(const char *path, uid_t uid, gid_t gid);
|
||||
|
||||
int cg_create_everywhere(CGroupMask supported, CGroupMask mask, const char *path);
|
||||
int cg_attach_everywhere(CGroupMask supported, const char *path, pid_t pid);
|
||||
int cg_trim_everywhere(CGroupMask supported, const char *path, bool delete_root);
|
||||
int cg_enable_everywhere(CGroupMask supported, CGroupMask mask, const char *p, CGroupMask *ret_result_mask);
|
||||
int cg_enable(CGroupMask supported, CGroupMask mask, const char *p, CGroupMask *ret_result_mask);
|
||||
|
||||
int cg_migrate(const char *cfrom, const char *pfrom, const char *cto, const char *pto, CGroupFlags flags);
|
||||
int cg_migrate(const char *from, const char *to, CGroupFlags flags);
|
||||
|
||||
int cg_has_legacy(void);
|
||||
|
||||
+1
-5
@@ -306,11 +306,7 @@ static int enter_cgroup(char **ret_cgroup, bool enter_subroot) {
|
||||
/* If this fails, then we don't mind as the later cgroup operations will fail too, and it's fine if
|
||||
* we handle any errors at that point. */
|
||||
|
||||
r = cg_create_everywhere(supported, _CGROUP_MASK_ALL, cgroup_subroot);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = cg_attach_everywhere(supported, cgroup_subroot, 0);
|
||||
r = cg_create_and_attach(cgroup_subroot, 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
||||
@@ -466,7 +466,7 @@ int main(int argc, char *argv[]) {
|
||||
/* Let's trim the cgroup tree on each iteration so that we leave an empty cgroup tree around,
|
||||
* so that container managers get a nice notify event when we are down */
|
||||
if (cgroup)
|
||||
(void) cg_trim(SYSTEMD_CGROUP_CONTROLLER, cgroup, false);
|
||||
(void) cg_trim(cgroup, false);
|
||||
|
||||
if (need_umount) {
|
||||
log_info("Unmounting file systems.");
|
||||
|
||||
@@ -299,8 +299,7 @@ int main(int argc, char *argv[]) {
|
||||
ASSERT_OK(path_extract_directory(cgroup, &parent));
|
||||
|
||||
ASSERT_OK(cg_mask_supported(&supported));
|
||||
r = cg_attach_everywhere(supported, parent, 0);
|
||||
ASSERT_OK(r);
|
||||
ASSERT_OK(cg_attach(parent, 0));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+11
-11
@@ -63,32 +63,32 @@ TEST(cg_create) {
|
||||
log_info("Paths for test:\n%s\n%s", test_a, test_b);
|
||||
|
||||
/* Possibly clean up left-overs from aboted previous runs */
|
||||
(void) cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_a, /* delete_root= */ true);
|
||||
(void) cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_b, /* delete_root= */ true);
|
||||
(void) cg_trim(test_a, /* delete_root= */ true);
|
||||
(void) cg_trim(test_b, /* delete_root= */ true);
|
||||
|
||||
r = cg_create(SYSTEMD_CGROUP_CONTROLLER, test_a);
|
||||
r = cg_create(test_a);
|
||||
if (IN_SET(r, -EPERM, -EACCES, -EROFS)) {
|
||||
log_info_errno(r, "Skipping %s: %m", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
ASSERT_OK_EQ(r, 1);
|
||||
ASSERT_OK_ZERO(cg_create(SYSTEMD_CGROUP_CONTROLLER, test_a));
|
||||
ASSERT_OK_EQ(cg_create(SYSTEMD_CGROUP_CONTROLLER, test_b), 1);
|
||||
ASSERT_OK_EQ(cg_create(SYSTEMD_CGROUP_CONTROLLER, test_c), 1);
|
||||
ASSERT_OK_ZERO(cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, test_b, 0));
|
||||
ASSERT_OK_ZERO(cg_create(test_a));
|
||||
ASSERT_OK_EQ(cg_create(test_b), 1);
|
||||
ASSERT_OK_EQ(cg_create(test_c), 1);
|
||||
ASSERT_OK_ZERO(cg_create_and_attach(test_b, 0));
|
||||
|
||||
ASSERT_OK_ZERO(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path));
|
||||
ASSERT_STREQ(path, test_b);
|
||||
free(path);
|
||||
|
||||
ASSERT_OK_ZERO(cg_attach(SYSTEMD_CGROUP_CONTROLLER, test_a, 0));
|
||||
ASSERT_OK_ZERO(cg_attach(test_a, 0));
|
||||
|
||||
ASSERT_OK_ZERO(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path));
|
||||
ASSERT_TRUE(path_equal(path, test_a));
|
||||
free(path);
|
||||
|
||||
ASSERT_OK_EQ(cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, test_d, 0), 1);
|
||||
ASSERT_OK_EQ(cg_create_and_attach(test_d, 0), 1);
|
||||
|
||||
ASSERT_OK_ZERO(cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, getpid_cached(), &path));
|
||||
ASSERT_TRUE(path_equal(path, test_d));
|
||||
@@ -114,8 +114,8 @@ TEST(cg_create) {
|
||||
ASSERT_OK_ZERO(cg_kill_recursive(test_a, 0, 0, NULL, NULL, NULL));
|
||||
ASSERT_OK_POSITIVE(cg_kill_recursive(test_b, 0, 0, NULL, NULL, NULL));
|
||||
|
||||
ASSERT_OK(cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_a, true));
|
||||
ASSERT_ERROR(cg_trim(SYSTEMD_CGROUP_CONTROLLER, test_b, true), EBUSY);
|
||||
ASSERT_OK(cg_trim(test_a, true));
|
||||
ASSERT_ERROR(cg_trim(test_b, true), EBUSY);
|
||||
}
|
||||
|
||||
TEST(id) {
|
||||
|
||||
Reference in New Issue
Block a user