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