Demo of a race-free GDBus daemon that exits when idle
Background: https://bugs.freedesktop.org/show_bug.cgi?id=11454
This is what the above does - systemd is tracking our process state, and thus ensures mutual exclusion.
Needs a GDBus patch to clean up.
TODO: Debug why this is
The systemd event loop has special support for exiting, which GMainLoop doesn't. This demo app uses a tristate.
One thing that wasn't obvious to me at the start, but due to the way DBus policies work, any attempt to send a message to the non-current owner of the name will be denied (which happens when the service is exiting and has released the name).
Thus, clients should always send messages to the well-known name.
A stateful service needs to actually save things on disk, this app demos how to do that in an async/timed fashion.