PATCH: Shortcut activation if exec is already being started

Mikael Hallendal micke@imendio.com
Thu Mar 11 12:49:39 PST 2004


--=-LbPMIFT8Vk3tkmGMaSQJ
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

Hi!

This is a patch that shortcuts the spawning of another instance of the
same exec if it's already in the pending queue. This is useful if two
services are provided by the same binary, if one of the services are
already pending there is no point in starting another instance of the
same executable.

Regards,
  Mikael Hallendal
-- 
Mikael Hallendal               micke@imendio.com
Imendio HB                     http://www.imendio.com
Phone: +46 (0)709 718 918


--=-LbPMIFT8Vk3tkmGMaSQJ
Content-Disposition: attachment; filename=exec-pending.patch
Content-Type: text/x-patch; name=exec-pending.patch; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

? doc/dbus-tutorial.html
? python/.deps
? python/.libs
? python/Makefile
? python/Makefile.in
? python/dbus_bindings.c
? python/dbus_bindings.la
? python/dbus_bindings.lo
? python/dbus_bindings.pyx
? test/glib/.deps
? test/glib/.libs
? test/glib/Makefile
? test/glib/Makefile.in
? test/glib/run-test.conf
? test/glib/test-dbus-glib
? test/glib/test-profile
? test/glib/test-service-glib
? test/glib/test-thread-client
? test/glib/test-thread-server
? tools/dbus-viewer
Index: bus/activation.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/activation.c,v
retrieving revision 1.31
diff -u -b -B -p -r1.31 activation.c
--- a/bus/activation.c	2 Dec 2003 10:44:21 -0000	1.31
+++ b/bus/activation.c	11 Mar 2004 11:33:20 -0000
@@ -70,6 +70,7 @@ typedef struct
   int refcount;
   BusActivation *activation;
   char *service_name;
+  char *exec;
   DBusList *entries;
   int n_entries;
   DBusBabysitter *babysitter;
@@ -145,6 +146,7 @@ bus_pending_activation_unref (BusPending
     }
   
   dbus_free (pending_activation->service_name);
+  dbus_free (pending_activation->exec);
 
   link = _dbus_list_get_first_link (&pending_activation->entries);
 
@@ -786,6 +788,7 @@ pending_activation_timed_out (void *data
    * (not sure this is what we want to do, but
    * may as well try it for now)
    */
+  if (pending_activation->babysitter) 
   _dbus_babysitter_kill_child (pending_activation->babysitter);
 
   dbus_error_init (&error);
@@ -855,6 +858,8 @@ bus_activation_activate_service (BusActi
   DBusString service_str;
   char *argv[2];
   dbus_bool_t retval;
+  DBusHashIter iter;
+  dbus_bool_t activated = TRUE;
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
 
@@ -968,6 +973,16 @@ bus_activation_activate_service (BusActi
 	  return FALSE;
 	}
 
+      pending_activation->exec = _dbus_strdup (entry->exec);
+      if (!pending_activation->exec)
+	{
+	  _dbus_verbose ("Failed to copy service exec for pending activation\n");
+	  BUS_SET_OOM (error);
+	  bus_pending_activation_unref (pending_activation);
+	  bus_pending_activation_entry_free (pending_activation_entry);
+	  return FALSE;
+	}
+
       pending_activation->timeout =
         _dbus_timeout_new (bus_context_get_activation_timeout (activation->context),
                            pending_activation_timed_out,
@@ -1012,6 +1027,19 @@ bus_activation_activate_service (BusActi
       pending_activation->n_entries += 1;
       pending_activation->activation->n_pending_activations += 1;
       
+      activated = FALSE;
+      _dbus_hash_iter_init (activation->pending_activations, &iter);
+      while (_dbus_hash_iter_next (&iter))
+	{
+	  BusPendingActivation *p = _dbus_hash_iter_get_value (&iter);
+	  
+	  if (strcmp (p->exec, entry->exec) == 0) 
+	    {
+	      activated = TRUE;
+	      break;
+	    }
+	}
+     
       if (!_dbus_hash_table_insert_string (activation->pending_activations,
 					   pending_activation->service_name,
                                            pending_activation))
@@ -1037,6 +1065,12 @@ bus_activation_activate_service (BusActi
    * argv[0]
    */
   
+  if (activated == TRUE) 
+    {
+      pending_activation->babysitter = NULL;
+      return TRUE;
+    }
+
   /* Now try to spawn the process */
   argv[0] = entry->exec;
   argv[1] = NULL;

--=-LbPMIFT8Vk3tkmGMaSQJ--





More information about the dbus mailing list