From 0881cf3d511b8614307bb08f2dec374e55195232 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 9 Oct 2024 06:28:06 +0900 Subject: [PATCH] core/dbus: introduce bus_verify_manage_units_async_impl() Then, make bus_verify_manage_units_async() and _full() inline. Co-authored-by: Renjaya Raga Zenta --- src/core/dbus-util.c | 44 +++++++++++++++++++++++++------------------- src/core/dbus-util.h | 10 ++++++++-- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/core/dbus-util.c b/src/core/dbus-util.c index 28cb095cb27..2f13555f8f9 100644 --- a/src/core/dbus-util.c +++ b/src/core/dbus-util.c @@ -150,39 +150,45 @@ int bus_set_transient_usec_internal( return 1; } -int bus_verify_manage_units_async_full( - Unit *u, +int bus_verify_manage_units_async_impl( + Manager *manager, + const char *id, const char *verb, const char *polkit_message, sd_bus_message *call, sd_bus_error *error) { - const char *details[9] = { - "unit", u->id, - "verb", verb, + const char *details[9]; + size_t n_details = 0; + + assert(manager); + assert(call); + + if (id) { + details[n_details++] = "unit"; + details[n_details++] = id; + } + + if (verb) { + details[n_details++] = "verb"; + details[n_details++] = verb; }; if (polkit_message) { - details[4] = "polkit.message"; - details[5] = polkit_message; - details[6] = "polkit.gettext_domain"; - details[7] = GETTEXT_PACKAGE; + details[n_details++] = "polkit.message"; + details[n_details++] = polkit_message; + details[n_details++] = "polkit.gettext_domain"; + details[n_details++] = GETTEXT_PACKAGE; } - return bus_verify_polkit_async( - call, - "org.freedesktop.systemd1.manage-units", - details, - &u->manager->polkit_registry, - error); -} + assert(n_details < ELEMENTSOF(details)); + details[n_details] = NULL; -int bus_verify_manage_units_async(Manager *m, sd_bus_message *call, sd_bus_error *error) { return bus_verify_polkit_async( call, "org.freedesktop.systemd1.manage-units", - /* details= */ NULL, - &m->polkit_registry, + n_details > 0 ? details : NULL, + &manager->polkit_registry, error); } diff --git a/src/core/dbus-util.h b/src/core/dbus-util.h index 5eb4e836c72..471c64acb65 100644 --- a/src/core/dbus-util.h +++ b/src/core/dbus-util.h @@ -251,8 +251,14 @@ static inline int bus_set_transient_usec_fix_0(Unit *u, const char *name, usec_t return bus_set_transient_usec_internal(u, name, p, true, message, flags, error); } -int bus_verify_manage_units_async_full(Unit *u, const char *verb, const char *polkit_message, sd_bus_message *call, sd_bus_error *error); -int bus_verify_manage_units_async(Manager *m, sd_bus_message *call, sd_bus_error *error); +int bus_verify_manage_units_async_impl(Manager *manager, const char *id, const char *verb, const char *polkit_message, sd_bus_message *call, sd_bus_error *error); +static inline int bus_verify_manage_units_async_full(Unit *u, const char *verb, const char *polkit_message, sd_bus_message *call, sd_bus_error *error) { + assert(u); + return bus_verify_manage_units_async_impl(u->manager, u->id, verb, polkit_message, call, error); +} +static inline int bus_verify_manage_units_async(Manager *manager, sd_bus_message *call, sd_bus_error *error) { + return bus_verify_manage_units_async_impl(manager, NULL, NULL, NULL, call, error); +} int bus_verify_manage_unit_files_async(Manager *m, sd_bus_message *call, sd_bus_error *error); int bus_verify_reload_daemon_async(Manager *m, sd_bus_message *call, sd_bus_error *error); int bus_verify_set_environment_async(Manager *m, sd_bus_message *call, sd_bus_error *error); -- 2.47.3