]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
8c759b33 LP |
2 | |
3 | #include "test-helper.h" | |
4 | #include "random-util.h" | |
5 | #include "alloc-util.h" | |
6 | #include "cgroup-util.h" | |
7 | ||
651d47d1 | 8 | int enter_cgroup_subroot(void) { |
8c759b33 LP |
9 | _cleanup_free_ char *cgroup_root = NULL, *cgroup_subroot = NULL; |
10 | CGroupMask supported; | |
651d47d1 ZJS |
11 | int r; |
12 | ||
13 | r = cg_pid_get_path(NULL, 0, &cgroup_root); | |
14 | if (r == -ENOMEDIUM) | |
15 | return log_warning_errno(r, "cg_pid_get_path(NULL, 0, ...) failed: %m"); | |
16 | assert(r >= 0); | |
8c759b33 | 17 | |
8c759b33 LP |
18 | assert_se(asprintf(&cgroup_subroot, "%s/%" PRIx64, cgroup_root, random_u64()) >= 0); |
19 | assert_se(cg_mask_supported(&supported) >= 0); | |
20 | ||
21 | /* If this fails, then we don't mind as the later cgroup operations will fail too, and it's fine if we handle | |
22 | * any errors at that point. */ | |
23 | ||
651d47d1 ZJS |
24 | r = cg_create_everywhere(supported, _CGROUP_MASK_ALL, cgroup_subroot); |
25 | if (r < 0) | |
26 | return r; | |
8c759b33 | 27 | |
651d47d1 | 28 | return cg_attach_everywhere(supported, cgroup_subroot, 0, NULL, NULL); |
8c759b33 | 29 | } |