[daemon-fix][daemon-dev] Fixed crashing when name is primary owned again
authorRadoslaw Pajak <r.pajak@samsung.com>
Fri, 27 Sep 2013 12:54:05 +0000 (14:54 +0200)
committerRadoslaw Pajak <r.pajak@samsung.com>
Fri, 27 Sep 2013 12:54:05 +0000 (14:54 +0200)
 - Fixed daemon crashing when the name is primary_owned after being completely released.
 - Begin of development of starting services by direct message.

Change-Id: Ib4968e10ad5effdf4ca56da5fd85ca95c5325cf7
Signed-off-by: Radoslaw Pajak <r.pajak@samsung.com>
bus/bus.c
bus/kdbus-d.c
bus/kdbus-d.h
bus/services.c

index 774952d..f3ef668 100644 (file)
--- a/bus/bus.c
+++ b/bus/bus.c
@@ -978,11 +978,17 @@ bus_context_new (const DBusString *config_file,
          _dbus_string_init_const(&unique_name, ":1.1"); //dbus_bus_get_unique_name(context->myConnection)); this is without :1.
          if(!bus_connection_complete(context->myKdbusConnection, &unique_name, error))
          {
-                 _dbus_verbose ("bus connection complete failed for kdbus\n");
+                 _dbus_verbose ("Bus connection complete failed for kdbus!\n");
                  _dbus_string_free(&unique_name);
                  goto failed;
          }
          _dbus_string_free(&unique_name);
+
+         if(!register_kdbus_starters(context->myKdbusConnection))
+         {
+          _dbus_verbose ("Registering kdbus starters for dbus activatable names failed!\n");
+          goto failed;
+         }
   }
 
   return context;
index b0466ee..bd4832b 100644 (file)
@@ -17,6 +17,7 @@
 #include <dbus/dbus-transport.h>
 #include <dbus/dbus-transport-kdbus.h>
 #include "connection.h"
+#include "activation.h"
 
 #include <utils.h>
 #include <stdlib.h>
@@ -102,7 +103,7 @@ DBusConnection* daemon_as_client(DBusBusType type, char* address, DBusError *err
 
        dbus_bus_set_bus_connection_address(type, address);
 
-       connection = dbus_bus_get(type, error);
+       connection = dbus_bus_get(type, error);  /*todo possibly could be optimised by using lower functions*/
        if(connection == NULL)
                return NULL;
 
@@ -113,9 +114,7 @@ DBusConnection* daemon_as_client(DBusBusType type, char* address, DBusError *err
        if(kdbus_request_name(connection, &daemon_name, 0, 0) != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
                goto failed;
 
-//     dbus_bus_add_match(connection, "type='signal', member='NameAcquired'", error);  //not needed if request name ioctled  by daemon not libdbus
-//     dbus_bus_add_match(connection, "type='signal', member='NameLost'", error);  //todo dispatch and digest this  or ioctl about name where daemon checks name presence
-       if(!add_match_kdbus (dbus_connection_get_transport(connection), 1, "type='signal', member='NameLost'"))
+       if(!add_match_kdbus (dbus_connection_get_transport(connection), 1, "type='signal', member='NameLost'"))  //todo handle tis in dispatch
        {
              dbus_set_error (error, _dbus_error_from_errno (errno), "Could not add match for id:1, %s", _dbus_strerror_from_errno ());
              return FALSE;
@@ -315,3 +314,27 @@ DBusConnection* create_phantom_connection(DBusConnection* connection, const char
 
     return phantom_connection;
 }
+
+dbus_bool_t register_kdbus_starters(DBusConnection* connection)
+{
+    int i, len;
+    char **services;
+    dbus_bool_t retval = FALSE;
+    int fd;
+
+    if (!bus_activation_list_services (bus_connection_get_activation (connection), &services, &len))
+        return FALSE;
+
+    _dbus_transport_get_socket_fd(dbus_connection_get_transport(connection), &fd);
+
+   /* for(i=0; i<len; i++)
+    {
+        if (request_kdbus_name(fd, services[i], DBUS_NAME_FLAG_ALLOW_REPLACEMENT, 1) < 0)
+            goto out;
+    }*/
+    retval = TRUE;
+
+out:
+    dbus_free_string_array (services);
+    return retval;
+}
index bd69167..c9b8fcd 100644 (file)
@@ -33,4 +33,5 @@ dbus_bool_t kdbus_get_connection_unix_process_id(DBusConnection* connection, DBu
 dbus_bool_t kdbus_get_connection_unix_selinux_security_context(DBusConnection* connection, DBusMessage* message, DBusMessage* reply, DBusError* error);
 
 DBusConnection* create_phantom_connection(DBusConnection* connection, const char* unique_name);
+dbus_bool_t register_kdbus_starters(DBusConnection* connection);
 #endif /* KDBUS_H_ */
index e88ca10..de99fea 100644 (file)
@@ -710,8 +710,11 @@ bus_registry_acquire_kdbus_service (BusRegistry      *registry,
            if (!bus_service_add_owner (service, phantom, flags, transaction, error))
                goto out;  /* todo FIXME what to do with phantom connection? look into create_phantom_connection for a clue*/
            if(*result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
-               if (!bus_service_remove_owner (service, connection, transaction, error))
-                   goto out;  /* todo FIXME what to do with phantom connection? look into create_phantom_connection for a clue*/
+           {
+               if(_bus_service_find_owner_link (service, connection))
+                if (!bus_service_remove_owner (service, connection, transaction, error))
+                    goto out;  /* todo FIXME what to do with phantom connection? look into create_phantom_connection for a clue*/
+           }
        }
 
   activation = bus_context_get_activation (registry->context);