]>
Commit | Line | Data |
---|---|---|
bb0b01ed ZJS |
1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
2 | ||
3 | #include "bpf-dlopen.h" | |
4 | #include "bpf-util.h" | |
5 | #include "cgroup-util.h" | |
baa6a42d | 6 | #include "initrd-util.h" |
bb0b01ed ZJS |
7 | #include "log.h" |
8 | ||
9 | bool cgroup_bpf_supported(void) { | |
10 | static int supported = -1; | |
11 | int r; | |
12 | ||
13 | if (supported >= 0) | |
14 | return supported; | |
15 | ||
16 | r = cg_unified_controller(SYSTEMD_CGROUP_CONTROLLER); | |
17 | if (r < 0) { | |
18 | log_warning_errno(r, "Can't determine whether the unified hierarchy is used: %m"); | |
19 | return (supported = false); | |
20 | } | |
21 | ||
22 | if (r == 0) { | |
23 | log_info_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), | |
24 | "Not running with unified cgroup hierarchy, disabling cgroup BPF features."); | |
25 | return (supported = false); | |
26 | } | |
27 | ||
28 | r = dlopen_bpf(); | |
29 | if (r < 0) { | |
ea4f2d5f ZJS |
30 | log_full_errno(in_initrd() ? LOG_DEBUG : LOG_INFO, |
31 | r, "Failed to open libbpf, cgroup BPF features disabled: %m"); | |
bb0b01ed ZJS |
32 | return (supported = false); |
33 | } | |
34 | ||
35 | return (supported = true); | |
36 | } |