PATCH: Shortcut activation if exec is already being started
Mikael Hallendal
micke@imendio.com
Thu Mar 11 14:27:36 PST 2004
--=-Y7QVo/qBpr2OGtByMvvH
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
tor 2004-03-11 klockan 14.44 skrev Havoc Pennington:
Hi,
> Of course:
> /* FIXME we need to support a full command line, not just a single
> * argv[0]
> */
> Maybe we should fix that ;-)
Yeah, I think that this functionality can be fixed when that is fixed
aswell. :)
> A problem with the patch is that the second activation will always time
> out if the activated process exits with a failure code, while the first
> activation will be canceled immediately. Maybe there's an easy and
> uncomplicated way to fix that? It's probably best to just ignore if the
> fix makes a mess.
I've updated the patch to also go through the pending activation hash to
see if other pending activations are also pending for the failing
executable and if so send the same error to them.
Regards,
Mikael
--
Mikael Hallendal micke@imendio.com
Imendio HB http://www.imendio.com
Phone: +46 (0)709 718 918
--=-Y7QVo/qBpr2OGtByMvvH
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 14:24:57 -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);
@@ -740,10 +742,22 @@ babysitter_watch_callback (DBusWatch
if (_dbus_babysitter_get_child_exited (babysitter))
{
DBusError error;
+ DBusHashIter iter;
dbus_error_init (&error);
_dbus_babysitter_set_child_exit_error (babysitter, &error);
+ /* Destroy all pending activations with the same exec */
+ _dbus_hash_iter_init (pending_activation->activation->pending_activations,
+ &iter);
+ while (_dbus_hash_iter_next (&iter))
+ {
+ BusPendingActivation *p = _dbus_hash_iter_get_value (&iter);
+
+ if (p != pending_activation && strcmp (p->exec, pending_activation->exec) == 0)
+ pending_activation_failed (p, &error);
+ }
+
/* Destroys the pending activation */
pending_activation_failed (pending_activation, &error);
@@ -786,6 +800,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 +870,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 +985,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 +1039,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 +1077,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;
--=-Y7QVo/qBpr2OGtByMvvH--
More information about the dbus
mailing list