]>
Commit | Line | Data |
---|---|---|
8c759b33 LP |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2017 Lennart Poettering | |
5 | ||
6 | systemd is free software; you can redistribute it and/or modify it | |
7 | under the terms of the GNU Lesser General Public License as published by | |
8 | the Free Software Foundation; either version 2.1 of the License, or | |
9 | (at your option) any later version. | |
10 | ||
11 | systemd is distributed in the hope that it will be useful, but | |
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public License | |
17 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
18 | ***/ | |
19 | ||
20 | #include "test-helper.h" | |
21 | #include "random-util.h" | |
22 | #include "alloc-util.h" | |
23 | #include "cgroup-util.h" | |
24 | ||
25 | void enter_cgroup_subroot(void) { | |
26 | _cleanup_free_ char *cgroup_root = NULL, *cgroup_subroot = NULL; | |
27 | CGroupMask supported; | |
28 | ||
29 | assert_se(cg_pid_get_path(NULL, 0, &cgroup_root) >= 0); | |
30 | assert_se(asprintf(&cgroup_subroot, "%s/%" PRIx64, cgroup_root, random_u64()) >= 0); | |
31 | assert_se(cg_mask_supported(&supported) >= 0); | |
32 | ||
33 | /* If this fails, then we don't mind as the later cgroup operations will fail too, and it's fine if we handle | |
34 | * any errors at that point. */ | |
35 | ||
36 | if (cg_create_everywhere(supported, _CGROUP_MASK_ALL, cgroup_subroot) < 0) | |
37 | return; | |
38 | ||
39 | if (cg_attach_everywhere(supported, cgroup_subroot, 0, NULL, NULL) < 0) | |
40 | return; | |
41 | } |