[daemon-dev][lib-fix] Start of daemon with kdbus and fix in match rules in libdbus
authorRadoslaw Pajak <r.pajak@samsung.com>
Thu, 5 Sep 2013 06:58:13 +0000 (08:58 +0200)
committerRadoslaw Pajak <r.pajak@samsung.com>
Thu, 5 Sep 2013 06:58:13 +0000 (08:58 +0200)
 - start of dbus-daemon supporting kdbus (bus making and services starting)
 - fix in match rules translating into kdbus in libdbus

Change-Id: I4e60472af75b3f6735a4ea498ce1b65604c6a161

bus/Makefile.am
bus/bus.c
bus/bus.h
bus/kdbus-d.c [new file with mode: 0644]
bus/kdbus-d.h [new file with mode: 0644]
dbus/dbus-transport-kdbus.c

index cd0c67d..9a646af 100644 (file)
@@ -76,6 +76,8 @@ BUS_SOURCES=                                  \
        driver.h                                \
        expirelist.c                            \
        expirelist.h                            \
+       kdbus-d.c                                       \
+       kdbus-d.h                                       \       
        policy.c                                \
        policy.h                                \
        selinux.h                               \
index 307c158..dd9072a 100644 (file)
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -39,6 +39,7 @@
 #include <dbus/dbus-hash.h>
 #include <dbus/dbus-credentials.h>
 #include <dbus/dbus-internals.h>
+#include <kdbus-d.h>
 
 #ifdef DBUS_CYGWIN
 #include <signal.h>
@@ -68,6 +69,8 @@ struct BusContext
   unsigned int keep_umask : 1;
   unsigned int allow_anonymous : 1;
   unsigned int systemd_activation : 1;
+  unsigned int is_kdbus : 1;
+  DBusConnection *myConnection;
 };
 
 static dbus_int32_t server_data_slot = -1;
@@ -423,22 +426,45 @@ process_config_first_time_only (BusContext       *context,
 
   if (address)
     {
-      DBusServer *server;
+      if(!strcmp(_dbus_string_get_const_data(address), "kdbus"))
+      {
+         DBusBusType type;
 
-      server = dbus_server_listen (_dbus_string_get_const_data(address), error);
-      if (server == NULL)
-        {
-          _DBUS_ASSERT_ERROR_IS_SET (error);
-          goto failed;
-        }
-      else if (!setup_server (context, server, auth_mechanisms, error))
-        {
-          _DBUS_ASSERT_ERROR_IS_SET (error);
-          goto failed;
-        }
+         context->is_kdbus = TRUE;
 
-      if (!_dbus_list_append (&context->servers, server))
-        goto oom;
+         if(!strcmp (context->type, "system"))
+                 type = DBUS_BUS_SYSTEM;
+         else if(!strcmp (context->type, "session"))
+                 type = DBUS_BUS_SESSION;
+         else
+                 type = DBUS_BUS_STARTER;
+
+         if(!make_kdbus_bus(type, error))
+                 goto failed;
+
+         context->myConnection = daemon_as_client(type, error);
+         if(context->myConnection == NULL)
+                 goto failed;
+      }
+      else
+      {
+                 DBusServer *server;
+
+                 server = dbus_server_listen (_dbus_string_get_const_data(address), error);
+                 if (server == NULL)
+                       {
+                         _DBUS_ASSERT_ERROR_IS_SET (error);
+                         goto failed;
+                       }
+                 else if (!setup_server (context, server, auth_mechanisms, error))
+                       {
+                         _DBUS_ASSERT_ERROR_IS_SET (error);
+                         goto failed;
+                       }
+
+                 if (!_dbus_list_append (&context->servers, server))
+                       goto oom;
+      }
     }
   else
     {
@@ -1175,6 +1201,11 @@ bus_context_get_loop (BusContext *context)
   return context->loop;
 }
 
+DBusConnection* bus_context_get_myConnection(BusContext *context)
+{
+  return context->myConnection;
+}
+
 dbus_bool_t
 bus_context_allow_unix_user (BusContext   *context,
                              unsigned long uid)
index 3597884..b1e2967 100644 (file)
--- a/bus/bus.h
+++ b/bus/bus.h
@@ -95,6 +95,7 @@ BusConnections*   bus_context_get_connections                    (BusContext
 BusActivation*    bus_context_get_activation                     (BusContext       *context);
 BusMatchmaker*    bus_context_get_matchmaker                     (BusContext       *context);
 DBusLoop*         bus_context_get_loop                           (BusContext       *context);
+DBusConnection*   bus_context_get_myConnection                                  (BusContext       *context);
 dbus_bool_t       bus_context_allow_unix_user                    (BusContext       *context,
                                                                   unsigned long     uid);
 dbus_bool_t       bus_context_allow_windows_user                 (BusContext       *context,
diff --git a/bus/kdbus-d.c b/bus/kdbus-d.c
new file mode 100644 (file)
index 0000000..5fa6cf3
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * kdbus-d.c
+ *
+ *  Created on: Sep 4, 2013
+ *      Author: r.pajak
+ *
+ *  kdbus add-on to dbus daemon
+ *
+ */
+
+#include <kdbus-d.h>
+#include <dbus/dbus-connection-internal.h>
+
+dbus_bool_t make_kdbus_bus(DBusBusType type, DBusError *error)
+{
+
+       return TRUE;
+}
+
+DBusConnection* daemon_as_client(DBusBusType type, DBusError *error)
+{
+       DBusConnection* connection;
+
+       connection = dbus_bus_get(type, error);
+       if(connection == NULL)
+               return NULL;
+
+       if(dbus_bus_request_name(connection, DBUS_SERVICE_DBUS, 0, error) != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
+               goto failed;
+
+       dbus_bus_add_match(connection, "type='signal', member='NameAcquired'", error);
+       dbus_bus_add_match(connection, "type='signal', member='NameLost'", error);
+       if(dbus_error_is_set(error))
+               goto failed;
+
+       return connection;
+
+failed:
+       _dbus_connection_close_possibly_shared (connection);
+       dbus_connection_unref (connection);
+       connection = NULL;
+       return NULL;
+}
diff --git a/bus/kdbus-d.h b/bus/kdbus-d.h
new file mode 100644 (file)
index 0000000..34705aa
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * kdbus-d.h
+ *
+ *  Created on: Sep 4, 2013
+ *      Author: r.pajak
+ *
+ *  kdbus add-on to dbus daemon
+ *
+ */
+
+#ifndef KDBUS_D_H_
+#define KDBUS_D_H_
+
+#include <dbus/dbus-bus.h>
+#include <bus.h>
+
+dbus_bool_t make_kdbus_bus(DBusBusType type, DBusError *error);
+DBusConnection* daemon_as_client(DBusBusType type, DBusError *error);
+
+
+#endif /* KDBUS_H_ */
index ee87648..42f0c7b 100644 (file)
@@ -2845,6 +2845,11 @@ void dbus_bus_add_match_kdbus (DBusConnection *connection, const char *rule, DBu
 
        if(strstr(rule, "member='NameOwnerChanged'"))
        {
+               kernel_item = ~0;
+               size += KDBUS_ITEM_SIZE(1)*3 + KDBUS_ITEM_SIZE(sizeof(__u64))*2;  /*std DBus: 3 name related items plus 2 id related items*/
+       }
+       else if(strstr(rule, "member='NameChanged'"))
+       {
                kernel_item = KDBUS_MATCH_NAME_CHANGE;
                size += KDBUS_ITEM_SIZE(1);
        }