From 6e0f959360cef85b93e1893dc15b4b19e660c2f1 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sat, 17 Aug 2024 13:18:31 +0200 Subject: [PATCH] core/unit: unit_is_filtered() -> unit_passes_filter() and invert logic Follow-up for 6d2984d21bf2a8f71d379ef6bc13a761bb2e2756 The current semantics of "filtered" in unit_is_filtered() are actually the contrary of ListUnitsFiltered(). Let's make things consistent, i.e. return true when the unit shall be included. --- src/basic/strv.h | 1 - src/core/dbus-manager.c | 2 +- src/core/unit.c | 8 ++++---- src/core/unit.h | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/basic/strv.h b/src/basic/strv.h index 965189d36e8..bd90305e63e 100644 --- a/src/basic/strv.h +++ b/src/basic/strv.h @@ -235,7 +235,6 @@ bool strv_fnmatch_full(char* const* patterns, const char *s, int flags, size_t * static inline bool strv_fnmatch(char* const* patterns, const char *s) { return strv_fnmatch_full(patterns, s, 0, NULL); } - static inline bool strv_fnmatch_or_empty(char* const* patterns, const char *s, int flags) { assert(s); return strv_isempty(patterns) || diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 1fa8b15a801..91c10a4e00c 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -1218,7 +1218,7 @@ static int list_units_filtered(sd_bus_message *message, void *userdata, sd_bus_e if (k != u->id) continue; - if (unit_is_filtered(u, states, patterns)) + if (!unit_passes_filter(u, states, patterns)) continue; r = reply_unit_info(reply, u); diff --git a/src/core/unit.c b/src/core/unit.c index e0f9f9b84a6..5d8b940608c 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -6472,20 +6472,20 @@ int unit_arm_timer( return 0; } -bool unit_is_filtered(Unit *u, char *const *states, char *const *patterns) { +bool unit_passes_filter(Unit *u, char * const *states, char * const *patterns) { assert(u); if (!strv_isempty(states)) { - char *const *unit_states = STRV_MAKE( + char * const *unit_states = STRV_MAKE( unit_load_state_to_string(u->load_state), unit_active_state_to_string(unit_active_state(u)), unit_sub_state_to_string(u)); if (!strv_overlap(states, unit_states)) - return true; + return false; } - return !strv_isempty(patterns) && !strv_fnmatch_or_empty(patterns, u->id, FNM_NOESCAPE); + return strv_fnmatch_or_empty(patterns, u->id, FNM_NOESCAPE); } static int unit_get_nice(Unit *u) { diff --git a/src/core/unit.h b/src/core/unit.h index bb360e30ed2..cabf7cc4219 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -1040,7 +1040,7 @@ Condition *unit_find_failed_condition(Unit *u); int unit_arm_timer(Unit *u, sd_event_source **source, bool relative, usec_t usec, sd_event_time_handler_t handler); -bool unit_is_filtered(Unit *u, char *const *states, char *const *patterns); +bool unit_passes_filter(Unit *u, char * const *states, char * const *patterns); int unit_compare_priority(Unit *a, Unit *b);