]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/dbus: introduce bus_verify_manage_units_async_impl()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 8 Oct 2024 21:28:06 +0000 (06:28 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 8 Oct 2024 21:55:32 +0000 (06:55 +0900)
Then, make bus_verify_manage_units_async() and _full() inline.

Co-authored-by: Renjaya Raga Zenta <ragazenta@gmail.com>
src/core/dbus-util.c
src/core/dbus-util.h

index 28cb095cb279901e9e0599d44416c4a6b00dc106..2f13555f8f9954c7377488886d970ed89cb9b7bf 100644 (file)
@@ -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);
 }
 
index 5eb4e836c722a5dde81ff411f58f3f8650c08df2..471c64acb6552c42b6ab777c1110db07c3d110f5 100644 (file)
@@ -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);