Replacing evil looping code

Havoc Pennington hp at redhat.com
Mon Nov 6 07:12:08 PST 2006


Hi,

> Is it possible to replace all that crap with decent D-Bus code?
> 
> I don't think we can use a service, as we're depending on some
> command-line arguments (should we pass those to the service in some
> other way instead?).

Remember you can autostart a service by just sending it a method call, 
so if your command line args can be args to a method that might work.

The showstopper for using a service in your case looks like the dynamic 
bus name creation (putting the pid in there), there's no way to put the 
dynamic bus name in the .service file.

If you figured a way around that, then just calling 
dbus_connection_send_with_reply_and_block() (or glib equivalent) would 
be what you want; it would send a method call, which would block until 
the service started up, and then return.

Otherwise, your code doesn't seem that horrible to me, it's pretty much 
the usual "block in main loop code" (looks about the same as 
gtk_dialog_run() for example). I usually try to avoid this and just do 
things asynchronously, but I'm guessing your code is in some scary 
mozilla context that makes that difficult...

dbus could have a dbus_connection_block_for_signal() call, but it might 
be somewhat dangerous; unlike method call replies, signals aren't 
usually very reliably known to be about to arrive, and dbus does not 
block in a reentrant way so the app would be locked up...

Havoc



More information about the dbus mailing list