Integration / D Bus Interview Questions
What happens internally when a service calls RequestName?
When a process calls RequestName on org.freedesktop.DBus, the bus daemon has to resolve a small state machine around ownership, not just record a simple string-to-connection mapping.
- The bus daemon checks whether the requested name is currently unowned. If so, the calling connection immediately becomes the primary owner, and a
NameOwnerChangedsignal is broadcast announcing the new owner. - If the name is already owned, the daemon checks the flags passed with the request. With
DBUS_NAME_FLAG_DO_NOT_QUEUEset, the call simply fails, returningDBUS_REQUEST_NAME_REPLY_EXISTS. Without it, the caller is added to a queue of processes waiting for that name. - If the current owner set
DBUS_NAME_FLAG_ALLOW_REPLACEMENTand the new requester setDBUS_NAME_FLAG_REPLACE_EXISTING, ownership can be transferred immediately instead of queued, again firing aNameOwnerChangedsignal. - If the current owner later releases the name or disconnects, the bus daemon automatically promotes the next connection in the queue, if any, to primary owner, firing another
NameOwnerChangedsignal.
This queueing behavior is what allows patterns like a primary service instance with standby replacements ready to take over ownership automatically if the primary exits.
More Related questions...