Fix build with older python/glibc/bpf and add CI job to cover it (#38500)
This commit is contained in:
@@ -307,8 +307,7 @@ def generate_fs_in_group():
|
||||
print(' switch (fs_group) {')
|
||||
|
||||
for name, _, *filesystems in FILESYSTEM_SETS:
|
||||
magics = sorted(set(sum((NAME_TO_MAGIC[fs] for fs in filesystems),
|
||||
start=[])))
|
||||
magics = sorted(set(sum((NAME_TO_MAGIC[fs] for fs in filesystems), [])))
|
||||
enum = 'FILESYSTEM_SET_' + name[1:].upper().replace('-', '_')
|
||||
print(f' case {enum}:')
|
||||
opts = '\n || '.join(f'F_TYPE_EQUAL(st->f_type, {magic})'
|
||||
@@ -355,7 +354,7 @@ def magic_defines():
|
||||
|
||||
def check():
|
||||
kernel_magics = set(magic_defines())
|
||||
our_magics = set(sum(NAME_TO_MAGIC.values(), start=[]))
|
||||
our_magics = set(sum(NAME_TO_MAGIC.values(), []))
|
||||
extra = kernel_magics - our_magics
|
||||
if extra:
|
||||
sys.exit(f"kernel knows additional filesystem magics: {', '.join(sorted(extra))}")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
if conf.get('HAVE_VMLINUX_H') != 1
|
||||
if conf.get('ENABLE_SYSCTL_BPF') != 1
|
||||
subdir_done()
|
||||
endif
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ networkctl_sources = files(
|
||||
networkd_network_gperf_gperf = files('networkd-network-gperf.gperf')
|
||||
networkd_netdev_gperf_gperf = files('netdev/netdev-gperf.gperf')
|
||||
|
||||
if conf.get('HAVE_VMLINUX_H') == 1
|
||||
if conf.get('ENABLE_SYSCTL_BPF') == 1
|
||||
systemd_networkd_extract_sources += sysctl_monitor_skel_h
|
||||
endif
|
||||
|
||||
|
||||
@@ -646,7 +646,7 @@ int manager_new(Manager **ret, bool test_mode) {
|
||||
.dhcp_server_persist_leases = DHCP_SERVER_PERSIST_LEASES_YES,
|
||||
.serialization_fd = -EBADF,
|
||||
.ip_forwarding = { -1, -1, },
|
||||
#if HAVE_VMLINUX_H
|
||||
#if ENABLE_SYSCTL_BPF
|
||||
.cgroup_fd = -EBADF,
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -117,7 +117,7 @@ typedef struct Manager {
|
||||
|
||||
/* sysctl */
|
||||
int ip_forwarding[2];
|
||||
#if HAVE_VMLINUX_H
|
||||
#if ENABLE_SYSCTL_BPF
|
||||
Hashmap *sysctl_shadow;
|
||||
sd_event_source *sysctl_event_source;
|
||||
struct ring_buffer *sysctl_buffer;
|
||||
@@ -148,7 +148,7 @@ int manager_set_timezone(Manager *m, const char *timezone);
|
||||
int manager_reload(Manager *m, sd_bus_message *message);
|
||||
|
||||
static inline Hashmap** manager_get_sysctl_shadow(Manager *manager) {
|
||||
#if HAVE_VMLINUX_H
|
||||
#if ENABLE_SYSCTL_BPF
|
||||
return &ASSERT_PTR(manager)->sysctl_shadow;
|
||||
#else
|
||||
return NULL;
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "string-util.h"
|
||||
#include "sysctl-util.h"
|
||||
|
||||
#if HAVE_VMLINUX_H
|
||||
#if ENABLE_SYSCTL_BPF
|
||||
|
||||
#include "bpf-link.h"
|
||||
#include "bpf/sysctl-monitor/sysctl-monitor-skel.h"
|
||||
|
||||
@@ -22,7 +22,7 @@ typedef enum IPReversePathFilter {
|
||||
_IP_REVERSE_PATH_FILTER_INVALID = -EINVAL,
|
||||
} IPReversePathFilter;
|
||||
|
||||
#if HAVE_VMLINUX_H
|
||||
#if ENABLE_SYSCTL_BPF
|
||||
int manager_install_sysctl_monitor(Manager *manager);
|
||||
void manager_remove_sysctl_monitor(Manager *manager);
|
||||
int link_clear_sysctl_shadows(Link *link);
|
||||
|
||||
@@ -68,6 +68,8 @@ TEST(oomd_cgroup_kill) {
|
||||
/* Create another cgroup below this one for the pids we forked off. We need this to be managed
|
||||
* by the test so that pid1 doesn't delete it before we can read the xattrs. */
|
||||
ASSERT_NOT_NULL(subcgroup = path_join(cgroup, "oomdkilltest"));
|
||||
/* Always start clean, in case of repeated runs and failures */
|
||||
ASSERT_OK(cg_trim(subcgroup, /* delete_root */ true));
|
||||
ASSERT_OK(cg_create(subcgroup));
|
||||
|
||||
/* If we don't have permissions to set xattrs we're likely in a userns or missing capabilities */
|
||||
@@ -106,6 +108,8 @@ TEST(oomd_cgroup_kill) {
|
||||
ASSERT_OK(cg_get_xattr(subcgroup, "user.oomd_kill", &v, /* ret_size= */ NULL));
|
||||
ASSERT_STREQ(v, i == 0 ? "2" : "4");
|
||||
}
|
||||
|
||||
ASSERT_OK(cg_trim(subcgroup, /* delete_root */ true));
|
||||
}
|
||||
|
||||
TEST(oomd_cgroup_context_acquire_and_insert) {
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
/* This needs to be included before the seccomp headers, otherwise missing syscalls will be defined in this
|
||||
* file and pass the ifdef, but they won't be defined in the seccomp headers so things like
|
||||
* SCMP_SYS(fchmodat2) will resolve as empty and fail the build with older glibc/libseccomp. */
|
||||
#include <sys/syscall.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/seccomp.h>
|
||||
#include <sched.h>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "tests.h"
|
||||
|
||||
static int intro(void) {
|
||||
#if __LIBBPF_CURRENT_VERSION_GEQ(1, 5)
|
||||
#if defined(LIBBPF_MAJOR_VERSION) && (LIBBPF_MAJOR_VERSION > 1 || (LIBBPF_MAJOR_VERSION == 1 && LIBBPF_MINOR_VERSION >= 5))
|
||||
_cleanup_close_ int bpffs_fd = open("/sys/fs/bpf", O_RDONLY);
|
||||
if (bpffs_fd < 0)
|
||||
return log_error_errno(errno, "Failed to open '/sys/fs/bpf': %m");
|
||||
|
||||
@@ -51,10 +51,12 @@ TEST(cg_create) {
|
||||
_cleanup_free_ char *here = NULL;
|
||||
ASSERT_OK(cg_pid_get_path_shifted(0, NULL, &here));
|
||||
|
||||
_cleanup_free_ char *test_a = ASSERT_NOT_NULL(path_join(here, "/test-a")),
|
||||
*test_b = ASSERT_NOT_NULL(path_join(here, "/test-b")),
|
||||
*test_c = ASSERT_NOT_NULL(path_join(here, "/test-b/test-c")),
|
||||
*test_d = ASSERT_NOT_NULL(path_join(here, "/test-b/test-d"));
|
||||
/* cg_* will use path_simplify(), so use it here too otherwise when running in a container at the
|
||||
* root it asserts with "/test-b != //test-b" */
|
||||
_cleanup_free_ char *test_a = ASSERT_NOT_NULL(path_simplify(path_join(here, "/test-a"))),
|
||||
*test_b = ASSERT_NOT_NULL(path_simplify(path_join(here, "/test-b"))),
|
||||
*test_c = ASSERT_NOT_NULL(path_simplify(path_join(here, "/test-b/test-c"))),
|
||||
*test_d = ASSERT_NOT_NULL(path_simplify(path_join(here, "/test-b/test-d")));
|
||||
char *path;
|
||||
|
||||
log_info("Paths for test:\n%s\n%s", test_a, test_b);
|
||||
|
||||
Reference in New Issue
Block a user