]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
dbus: handle unix server in a new function
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Tue, 8 Feb 2022 13:55:49 +0000 (17:55 +0400)
committerSimon McVittie <smcv@collabora.com>
Fri, 15 Jul 2022 15:26:18 +0000 (16:26 +0100)
Split _dbus_server_listen_platform_specific() to handle unix listenable
address independently, allowing Windows support in following commit.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
dbus/dbus-server-protected.h
dbus/dbus-server-unix.c
dbus/dbus-server.c

index 650963f12b89b35db28a3e3a1867e5b71c7405f6..d9254f47d78bb6b5cd7e1556abbc2f140918c36e 100644 (file)
@@ -126,6 +126,10 @@ typedef enum
   DBUS_SERVER_LISTEN_ADDRESS_ALREADY_USED /**< address is already used */
 } DBusServerListenResult;
 
+DBusServerListenResult _dbus_server_listen_unix_socket (DBusAddressEntry *entry,
+                                                        DBusServer      **server_p,
+                                                        DBusError        *error);
+
 DBusServerListenResult _dbus_server_listen_platform_specific (DBusAddressEntry  *entry,
                                                               DBusServer       **server_p,
                                                               DBusError         *error);
index 80da348bcadea237dfb8e71eb49517b6e3ec3677..fbb87dcb1d9b53a461d1fb79bb78a8c520924b37 100644 (file)
@@ -40,8 +40,9 @@
  */
 
 /**
- * Tries to interpret the address entry in a platform-specific
- * way, creating a platform-specific server type if appropriate.
+ * Tries to interpret the address entry for UNIX socket
+ * addresses.
+ *
  * Sets error if the result is not OK.
  *
  * @param entry an address entry
@@ -51,9 +52,9 @@
  *
  */
 DBusServerListenResult
-_dbus_server_listen_platform_specific (DBusAddressEntry *entry,
-                                       DBusServer      **server_p,
-                                       DBusError        *error)
+_dbus_server_listen_unix_socket (DBusAddressEntry *entry,
+                                 DBusServer      **server_p,
+                                 DBusError        *error)
 {
   const char *method;
 
@@ -217,7 +218,38 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry,
           return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
         }
     }
-  else if (strcmp (method, "systemd") == 0)
+  else
+    {
+      /* If we don't handle the method, we return NULL with the
+       * error unset
+       */
+      _DBUS_ASSERT_ERROR_IS_CLEAR(error);
+      return DBUS_SERVER_LISTEN_NOT_HANDLED;
+    }
+}
+
+/**
+ * Tries to interpret the address entry in a platform-specific
+ * way, creating a platform-specific server type if appropriate.
+ * Sets error if the result is not OK.
+ *
+ * @param entry an address entry
+ * @param server_p location to store a new DBusServer, or #NULL on failure.
+ * @param error location to store rationale for failure on bad address
+ * @returns the outcome
+ *
+ */
+DBusServerListenResult
+_dbus_server_listen_platform_specific (DBusAddressEntry *entry,
+                                       DBusServer      **server_p,
+                                       DBusError        *error)
+{
+  const char *method;
+
+  *server_p = NULL;
+
+  method = dbus_address_entry_get_method (entry);
+  if (strcmp (method, "systemd") == 0)
     {
       int i, n;
       DBusSocket *fds;
index cde3c986dcc143268074f5e12ec8560f1b28fa1a..7051c467c1de48ff6e808324d43d3b3111cc6e4e 100644 (file)
@@ -527,6 +527,9 @@ static const struct {
                                    DBusError        *error);
 } listen_funcs[] = {
   { _dbus_server_listen_socket }
+#ifndef _WIN32 /* FIXME: remove in next commit */
+  , { _dbus_server_listen_unix_socket }
+#endif
   , { _dbus_server_listen_platform_specific }
 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
   , { _dbus_server_listen_debug_pipe }