Skip to content

Commit

Permalink
bpf-firewall: invert test
Browse files Browse the repository at this point in the history
Following our coding style of exiting early (instead of deep nesting),
let's invert the if check here.

Inspired by: systemd#21602 (review)
  • Loading branch information
poettering authored and keszybz committed Mar 24, 2022
1 parent bbd2620 commit d011331
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/core/bpf-firewall.c
Original file line number Diff line number Diff line change
Expand Up @@ -927,16 +927,17 @@ void emit_bpf_firewall_warning(Unit *u) {
assert(u);
assert(u->manager);

if (!warned && !MANAGER_IS_TEST_RUN(u->manager)) {
bool quiet = bpf_firewall_unsupported_reason == -EPERM && detect_container() > 0;

log_unit_full_errno(u, quiet ? LOG_DEBUG : LOG_WARNING, bpf_firewall_unsupported_reason,
"unit configures an IP firewall, but %s.\n"
"(This warning is only shown for the first unit using IP firewalling.)",
getuid() != 0 ? "not running as root" :
"the local system does not support BPF/cgroup firewalling");
warned = true;
}
if (warned || MANAGER_IS_TEST_RUN(u->manager))
return;

bool quiet = ERRNO_IS_PRIVILEGE(bpf_firewall_unsupported_reason) && detect_container() > 0;

log_unit_full_errno(u, quiet ? LOG_DEBUG : LOG_WARNING, bpf_firewall_unsupported_reason,
"unit configures an IP firewall, but %s.\n"
"(This warning is only shown for the first unit using IP firewalling.)",
getuid() != 0 ? "not running as root" :
"the local system does not support BPF/cgroup firewalling");
warned = true;
}

void bpf_firewall_close(Unit *u) {
Expand Down

0 comments on commit d011331

Please sign in to comment.