1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-03 05:18:09 +03:00

networkd-sysctl: tweak error handling and log level a bit

Follow-up for 6d9ef22acd

- Downgrade log level for bpf not installed or kernel version
  being too old to LOG_DEBUG. Otherwise, on kernels older than 6.12
  the log becomes quite annoying.
- Always propagate the error and ignore only on caller's side.
  The current style is a messy mix.
This commit is contained in:
Mike Yuan 2024-12-18 14:34:59 +01:00
parent 22583a002e
commit cffae6e113
No known key found for this signature in database
GPG Key ID: 417471C0A40F58B3

View File

@ -102,10 +102,10 @@ int manager_install_sysctl_monitor(Manager *manager) {
assert(manager); assert(manager);
r = dlopen_bpf(); r = dlopen_bpf();
if (r < 0) { if (ERRNO_IS_NEG_NOT_SUPPORTED(r))
log_info_errno(r, "sysctl monitor disabled, as BPF support is not available."); return log_debug_errno(r, "sysctl monitor disabled, as BPF support is not available.");
return 0; if (r < 0)
} return log_warning_errno(r, "Failed to load libbpf, not installing sysctl monitor: %m");
r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, 0, &cgroup); r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, 0, &cgroup);
if (r < 0) if (r < 0)
@ -113,13 +113,12 @@ int manager_install_sysctl_monitor(Manager *manager) {
root_cgroup_fd = cg_path_open(SYSTEMD_CGROUP_CONTROLLER, "/"); root_cgroup_fd = cg_path_open(SYSTEMD_CGROUP_CONTROLLER, "/");
if (root_cgroup_fd < 0) if (root_cgroup_fd < 0)
return log_warning_errno(root_cgroup_fd, "Failed to open cgroup, ignoring: %m."); return log_warning_errno(root_cgroup_fd, "Failed to open cgroup, ignoring: %m");
obj = sysctl_monitor_bpf__open_and_load(); obj = sysctl_monitor_bpf__open_and_load();
if (!obj) { if (!obj)
log_info_errno(errno, "Unable to load sysctl monitor BPF program, ignoring: %m."); return log_full_errno(errno == EINVAL ? LOG_DEBUG : LOG_INFO, errno,
return 0; "Unable to load sysctl monitor BPF program, ignoring: %m");
}
cgroup_fd = cg_path_open(SYSTEMD_CGROUP_CONTROLLER, cgroup); cgroup_fd = cg_path_open(SYSTEMD_CGROUP_CONTROLLER, cgroup);
if (cgroup_fd < 0) if (cgroup_fd < 0)
@ -130,10 +129,8 @@ int manager_install_sysctl_monitor(Manager *manager) {
sysctl_link = sym_bpf_program__attach_cgroup(obj->progs.sysctl_monitor, root_cgroup_fd); sysctl_link = sym_bpf_program__attach_cgroup(obj->progs.sysctl_monitor, root_cgroup_fd);
r = bpf_get_error_translated(sysctl_link); r = bpf_get_error_translated(sysctl_link);
if (r < 0) { if (r < 0)
log_info_errno(r, "Unable to attach sysctl monitor BPF program to cgroup, ignoring: %m."); return log_warning_errno(r, "Unable to attach sysctl monitor BPF program to cgroup, ignoring: %m");
return 0;
}
fd = sym_bpf_map__fd(obj->maps.written_sysctls); fd = sym_bpf_map__fd(obj->maps.written_sysctls);
if (fd < 0) if (fd < 0)