]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
dbus-daemon: Implement signal 'ActivatableServicesChanged'
authorRalf Habacker <ralf.habacker@freenet.de>
Tue, 15 Feb 2022 23:14:37 +0000 (00:14 +0100)
committerRalf Habacker <ralf.habacker@freenet.de>
Wed, 16 Feb 2022 13:00:13 +0000 (14:00 +0100)
After any reload of the activatable service files the mentioned signal is
emitted to the current bus to inform clients.

The calls to signal emmission have not been implemented in the platform
specific functions _dbus_daemon_report_reloaded() to avoid duplicate
implementations.

Fixes #376
Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
bus/bus.c
bus/driver.c

index ea508d726ec447454f4a081d41af08d780fbec54..9003860e219be446b6e808d852319e84cc8232e4 100644 (file)
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -30,6 +30,7 @@
 #include "activation.h"
 #include "connection.h"
 #include "containers.h"
+#include "dispatch.h"
 #include "services.h"
 #include "utils.h"
 #include "policy.h"
@@ -1075,6 +1076,66 @@ bus_context_get_id (BusContext       *context,
   return _dbus_uuid_encode (&context->uuid, uuid);
 }
 
+/**
+ * Send signal to the buses that the activatable services may be changed
+ *
+ * @param context bus context to use
+ * @param error the error to set, if NULL no error will be set
+ * @return #FALSE if an error occurred, the reason is returned in \p error
+ */
+static dbus_bool_t
+bus_context_send_activatable_services_changed (BusContext *context,
+                                               DBusError  *error)
+{
+  DBusMessage *message;
+  BusTransaction *transaction;
+  dbus_bool_t retval = FALSE;
+
+  _DBUS_ASSERT_ERROR_IS_CLEAR (error);
+
+  transaction = bus_transaction_new (context);
+  if (transaction == NULL)
+    {
+      BUS_SET_OOM (error);
+      return FALSE;
+    }
+
+  message = dbus_message_new_signal (DBUS_PATH_DBUS,
+                                     DBUS_INTERFACE_DBUS,
+                                     "ActivatableServicesChanged");
+
+  if (message == NULL)
+    {
+      BUS_SET_OOM (error);
+      goto out;
+    }
+
+  if (!dbus_message_set_sender (message, DBUS_SERVICE_DBUS))
+    {
+      BUS_SET_OOM (error);
+      goto out;
+    }
+
+  if (!bus_transaction_capture (transaction, NULL, NULL, message))
+    {
+      BUS_SET_OOM (error);
+      goto out;
+    }
+
+  retval = bus_dispatch_matches (transaction, NULL, NULL, message, error);
+
+out:
+  if (transaction != NULL)
+    {
+      if (retval)
+        bus_transaction_execute_and_free (transaction);
+      else
+        bus_transaction_cancel_and_free (transaction);
+    }
+  dbus_clear_message (&message);
+  return retval;
+}
+
 dbus_bool_t
 bus_context_reload_config (BusContext *context,
                           DBusError  *error)
@@ -1116,6 +1177,15 @@ bus_context_reload_config (BusContext *context,
   if (parser != NULL)
     bus_config_parser_unref (parser);
 
+  {
+    DBusError local_error = DBUS_ERROR_INIT;
+
+    if (!bus_context_send_activatable_services_changed (context, &local_error))
+      bus_context_log (context, DBUS_SYSTEM_LOG_INFO, "Unable to send signal that configuration has been reloaded: %s", local_error.message);
+
+    dbus_error_free (&local_error);
+  }
+
   _dbus_daemon_report_reloaded ();
   return ret;
 }
index ef1b957f6ad6ac9e3ec7c120c2e15363b693eaeb..8ea2955b02bfac6629a7cb9900ba814e091e525c 100644 (file)
@@ -2737,6 +2737,8 @@ static InterfaceHandler interface_handlers[] = {
     "    </signal>\n"
     "    <signal name=\"NameAcquired\">\n"
     "      <arg type=\"s\"/>\n"
+    "    </signal>\n"
+    "    <signal name=\"ActivatableServicesChanged\">\n"
     "    </signal>\n",
     /* Not in the Interfaces property because if you can get the properties
      * of the o.fd.DBus interface, then you certainly have the o.fd.DBus
@@ -3158,6 +3160,12 @@ features_getter (BusContext      *context,
                                          &arr_iter))
     return FALSE;
 
+  s = "ActivatableServicesChanged";
+
+  if (!dbus_message_iter_append_basic (&arr_iter, DBUS_TYPE_STRING, &s))
+    goto abandon;
+
+
   if (bus_apparmor_enabled ())
     {
       s = "AppArmor";