Julien, dbus and hal make handling server reconnection correctly Hard, or impossible, in my limited experience. This information is what I can remember based on git logs from when I beat my brains against this particular wall for a few days.
You'd think you could check for an exception after calling
libhal_device_get*
. Maybe org.freedesktop.dbus.error.disconnected
. But
this doesn't work if dbus is down. Instead the function, IIRC, crashes.
So instead, it seems you have to check dbus_connection_get_is_connected
before every attempt to use hal, and reconnect if it's down. But this means
you've introduced a race condition.
Also, once you notice the connection is down, it'd make sense to tell hal to close the connection to dbus. Except, if dbus is down, hal crashes instead, IIRC. So there's no way to close an old hal connection in this case; the best thing to do seems to be to leave it open, and open a new one. So now your program is not just racey, but it's leaking.
The dbus people claim dbus is never supposed to be restarted. Ever. In other words: dbus/hal is badly designed crap. Do not use.