Revision as of 10:15, 27 January 2006 editJmax- (talk | contribs)910 editsm spelling error← Previous edit | Latest revision as of 00:38, 22 October 2024 edit undoNaruyoko (talk | contribs)469 edits →sd-bus: Add the release year of version 221, in parity with the initial statement and for easier referenceTag: 2017 wikitext editor | ||
(674 intermediate revisions by more than 100 users not shown) | |||
Line 1: | Line 1: | ||
{{Short description|Linux middleware}} | |||
'''D-BUS''' is the name of a ] system that provides a simple way for different applications to communicate with each other. It is developed as part of the ] project. | |||
{{Redirect|DBus|the Tibetan province|Ü (region){{!}}Dbus}} | |||
{{Infobox software | |||
| name = Desktop Bus | |||
| logo = | |||
| screenshot = | |||
| caption = | |||
| developer = ] | |||
| released = {{Start date and age|2006|11}} | |||
| latest_release_version = 1.14.10 | |||
| latest_release_date = {{start date and age|2023|09|01}}<ref>{{cite web |url= https://cgit.freedesktop.org/dbus/dbus/tree/NEWS?h=dbus-1.14|title= D-Bus 1.14.x changelog|access-date=30 December 2023}}</ref> | |||
| latest_preview_version = 1.15.8 | |||
| latest_preview_date = {{start date and age|2023|08|21}}<ref>{{cite web|url=https://cgit.freedesktop.org/dbus/dbus/tree/NEWS?h=master|title=NEWS file for current branch|access-date=30 December 2023}}</ref> | |||
| programming_language = ] | |||
| operating_system = ] | |||
| platform = | |||
| replaces = ]<br />] | |||
| genre = {{unbulleted list|] ] | ]}} | |||
| license = ] or ] 2.1<ref></ref> | |||
| website = {{URL|http://www.freedesktop.org/Software/dbus}} | |||
}} | |||
'''D-Bus''' (short for "'''Desktop Bus'''"<ref> | |||
==Introduction== | |||
{{cite book | |||
==Architecture== | |||
| last1 = Ward | |||
It is a interprocess communication (]) system with three architectural layers: | |||
| first1 = Brian | |||
| url = https://books.google.com/books?id=fP5WBQAAQBAJ | |||
| year = 2004 | |||
| chapter = 14: A brief survey of the Linux desktop | |||
| title = How Linux Works: What Every Superuser Should Know | |||
| edition = 2 | |||
| location = San Francisco | |||
| publisher = No Starch Press | |||
| publication-date = 2014 | |||
| page = 305 | |||
| isbn = 9781593275679 | |||
| access-date = 2016-11-07 | |||
| quote = One of the most important developments to come out of the Linux desktop is the Desktop Bus (D-Bus), a message-passing system. D-Bus is important because it serves as an interprocess communication mechanism that allows desktop applications to talk to each other . | |||
}} | |||
</ref>) | |||
is a ] mechanism that allows communication between multiple ] running concurrently on the same machine.{{r|intro dbus}}{{r|Cocagne 2012}} D-Bus was developed as part of the ] project, initiated by ] developer ] to standardize services provided by ] ]s such as ] and ].{{r|intro dbus q1}}{{r|Palmieri 2005}}{{dead link|date=November 2016}} | |||
The freedesktop.org project also developed a ] software library called libdbus, as a ] of the specification. This library should not be confused with D-Bus itself, as other implementations of the D-Bus specification also exist, such as GDBus (GNOME),{{r|gdbus}} QtDBus (]/KDE),{{r|qtdbus}} dbus-java{{r|dbus-java}} and sd-bus (part of ]).{{r|Poettering 2015}} | |||
* A library, ''libdbus'', that allows two applications to connect to each other and exchange messages. | |||
* A message bus daemon executable, built on libdbus, that multiple applications can connect to. The daemon can route messages from one application to zero or more other applications. | |||
* Wrapper libraries based on particular application frameworks. | |||
== Overview == | |||
D-BUS is designed for two specific cases: | |||
D-Bus is an ] (IPC) mechanism initially designed to replace the ] communications systems used by the ] and ] Linux ]s (] and ] respectively).{{r|dbus tut q1}}{{r|intro dbus q2}} The components of these desktop environments are normally distributed in many processes, each one providing only a few—usually one—''services''. These services may be used by regular client ] or by other components of the desktop environment to perform their tasks.<ref>{{Cite web |title=Desktop Environment - an overview {{!}} ScienceDirect Topics |url=https://www.sciencedirect.com/topics/computer-science/desktop-environment |access-date=2023-08-24 |website=www.sciencedirect.com}}</ref>{{multiple image | |||
| footer = Large groups of cooperating processes demand a dense mesh of individual communication channels (using one-to-one IPC methods) between them. D-Bus simplifies the IPC requirements with one single shared channel. | |||
| image1 = Processes without D-Bus.svg | |||
| alt1 = Processes without D-Bus | |||
| caption1 = Processes without D-Bus | |||
| image2 = Processes with D-Bus.svg | |||
| alt2 = Processes with D-Bus | |||
| caption2 = The same processes with D-Bus | |||
}} | |||
D-Bus provides a ] ] that gathers all the communications between a group of processes over a single shared virtual channel.{{r|Cocagne 2012}} Processes connected to a bus do not know how it is internally implemented, but D-Bus specification guarantees that all processes connected to the bus can communicate with each other through it. D-Bus incurs at least a 2.5x performance loss over one-to-one IPC.<ref>Answer 7. {{Cite web |title=D-Bus FAQ |url=https://dbus.freedesktop.org/doc/dbus-faq.html |access-date=2024-08-06}}</ref> | |||
* Communication between ] ] in the same desktop session; to allow integration of the desktop session as a whole, and address issues of process lifecycle. | |||
* Communication between the desktop session and the ], where the operating system would typically include the ] and any system ] or ]. | |||
Linux desktop environments take advantage of the D-Bus facilities by instantiating multiple buses, notably:{{r|dbus spec}}{{r|Cocagne 2012}}{{r|dbus tut}} | |||
== How D-BUS Works == | |||
* a single '''system bus''', available to all users and processes of the system, that provides access to system services (i.e. services provided by the ] and also by any system ]) | |||
Each application using D-BUS contains objects, which generally (but need not) map to GObject, QObject, ] objects, or ] objects. An object is an instance rather than a type. When messages are received over a D-BUS connection, they are sent to a specific object, not to the application as a whole. In this way, D-BUS resembles ], as it appears to the user as if an object is ] across the IPC connection, no matter if there is an object on the other side or not. | |||
* a '''session bus''' for each user login session, that provides desktop services to user applications in the same desktop session, and allows the integration of the desktop session as a whole | |||
A process can connect to any number of buses, provided that it has been granted access to them. In practice, this means that any user process can connect to the system bus and to its current session bus, but not to another user's session buses, or even to a different session bus owned by the same user. The latter restriction may change in the future if all user sessions are combined into a single user bus.{{r|Poettering 2015 q1}} | |||
To allow messages to specify their destination object, there has to be a way to refer to an object. In many programming languages, this is normally called a pointer or reference. However, these references are implemented as memory addresses relative to the address space of the application, and thus can't be passed from one application to another. | |||
D-Bus provides additional or simplifies existing functionality to the applications, including information-sharing, modularity and ]. For example, information on an incoming voice-call received through ] or ] can be propagated and interpreted by any currently-running music player, which can react by muting the volume or by pausing playback until the call is finished.{{r|Love 2005}} | |||
To solve this, D-BUS introduces a name for each object. The name looks like a filesystem path, for example an object could be named /org/kde/kspread/sheets/3/cells/4/5. Human-readable paths are preferred, but developers are free to create an object named /com/mycompany/c5yo817y0c1y1c5b if it makes sense for their application. | |||
D-Bus can also be used as a ] to integrate different components of a user application. For instance, an ] can communicate through the session bus to share data between a ] and a ]. | |||
The D-BUS objects' name is ] to ensure different code modules are kept separated. Namespaces are generally prefixed with the | |||
developers domain name components (eg /org/kde). | |||
== D-Bus specification == | |||
=== Bus model === | |||
Every connection to a bus is identified in the context of D-Bus by what is called a ''bus name''.{{r|intro dbus}} A bus name consists of two or more dot-separated strings of letters, digits, dashes, and underscores—a ]. An example of a valid bus name is {{code|org.freedesktop.NetworkManager}}.{{r|Cocagne 2012}} | |||
When a process sets up a connection to a bus, the bus assigns to the connection a special bus name called ''unique connection name''.{{r|dbus tut}}{{r|Cocagne 2012}} Bus names of this type are immutable—it is guaranteed they will not change as long as the connection exists—and, more importantly, they cannot be reused during the bus lifetime.{{r|intro dbus}}{{r|dbus tut}}{{r|Cocagne 2012}} This means that no other connection to that bus will ever have assigned such unique connection name, even if the same process closes down the connection to the bus and creates a new one. Unique connection names are easily recognizable because they start with the otherwise forbidden colon character.{{r|dbus tut}}{{r|Cocagne 2012}} An example of a unique connection name is {{code|:1.1553}} (the characters after the colon have no particular meaning{{r|dbus tut}}). | |||
A process can ask for additional bus names for its connection,{{r|dbus tut}} provided that any requested name is not already being used by another connection to the bus. In D-Bus parlance, when a bus name is assigned to a connection, it is said the connection ''owns'' the bus name.{{r|intro dbus}}{{r|dbus tut}} In that sense, a bus name cannot be owned by two connections at the same time, but, unlike unique connection names, these names can be reused if they are available: a process may reclaim a bus name released—purposely or not—by another process.{{r|intro dbus}}{{r|Cocagne 2012}} | |||
The idea behind these additional bus names, commonly called ''well-known names'', is to provide a way to refer to a service using a prearranged bus name.{{r|dbus tut}}{{r|Cocagne 2012}} For instance, the service that reports the current time and date in the system bus lies in the process whose connection owns the {{mono|org.freedesktop.timedate1}} bus name, regardless of which process it is. | |||
Bus names can be used as a simple way to implement single-instance applications (second instances detect that the bus name is already taken).{{r|dbus tut}} It can also be used to track a service process lifecycle, since the bus sends a notification when a bus name is released due to a process termination.{{r|dbus tut}} | |||
=== Object model === | |||
Because of its original conception as a replacement for several component oriented communications systems, D-Bus shares with its predecessors an object model in which to express the semantics of the communications between clients and services. The terms used in the D-Bus object model mimic those used by some ] ]s. That does not mean that D-Bus is somehow limited to OOP languages—in fact, the most used implementation ({{mono|libdbus}}) is written in ], a ] language. | |||
] | |||
In D-Bus, a process offers its services by exposing ''objects''. These objects have ''methods'' that can be invoked, and ''signals'' that the object can emit.{{r|dbus tut}} Methods and signals are collectively referred to as the ''members'' of the object.{{r|intro dbus}} Any client connected to the bus can interact with an object by using its methods, making requests or commanding the object to perform actions.{{r|dbus tut}} For instance, an object representing a time service can be queried by a client using a method that returns the current date and time. A client can also listen to signals that an object emits when its state changes due to certain events, usually related to the underlying service. An example would be when a service that manages hardware devices—such as USB or network drivers—signals a "new hardware device added" event. Clients should instruct the bus that they are interested in receiving certain signals from a particular object, since a D-Bus bus only passes signals to those processes with a registered interest in them.{{r|Cocagne 2012}} | |||
A process connected to a D-Bus bus can request it to ''export'' as many D-Bus objects as it wants. Each object is identified by an ''object path'', a string of numbers, letters and underscores separated and prefixed by the slash character, called that because of their resemblance to ].{{r|intro dbus}}{{r|dbus tut}} The object path is selected by the requesting process, and must be unique in the context of that bus connection. An example of a valid object path is {{code|/org/kde/kspread/sheets/3/cells/4/5}}.{{r|dbus tut}} However, it is not enforced—but also not discouraged—to form hierarchies within object paths.{{r|Cocagne 2012}} The particular naming convention for the objects of a service is entirely up to the developers of such service, but many developers choose to ] them using the reserved ] of the project as a prefix (e.g. {{mono|/org/kde}}).{{r|dbus tut}} | |||
Every object is inextricably associated to the particular bus connection where it was exported, and, from the D-Bus point of view, only lives in the context of such connection. Therefore, in order to be able to use a certain service, a client must indicate not only the object path providing the desired service, but also the bus name under which the service process is connected to the bus.{{r|intro dbus}} This in turn allows that several processes connected to the bus can export different objects with identical object paths unambiguously. | |||
An ''interface'' specifies members—methods and signals—that can be used with an object.{{r|dbus tut}} It is a set of declarations of methods (including its passing and returning parameters) and signals (including its parameters) identified by a dot-separated name resembling the ] interfaces notation.{{r|dbus tut}}{{r|Cocagne 2012}} An example of a valid interface name is {{code|org.freedesktop.Introspectable}}.{{r|Cocagne 2012}} Despite their similarity, interface names and bus names should not be mistaken. A D-Bus object can ''implement'' several interfaces, but at least must implement one, providing support for every method and signal defined by it. The combination of all interfaces implemented by an object is called the object ''type''.{{r|intro dbus}}{{r|dbus tut}} | |||
When using an object, it is a good practice for the client process to provide the member's interface name besides the member's name, but is only mandatory when there is an ambiguity caused by duplicated member names available from different interfaces implemented by the object{{r|intro dbus}}{{r|dbus tut}}—otherwise, the selected member is undefined or erroneous. An emitted signal, on the other hand, must always indicate to which interface it belongs. | |||
The D-Bus specification also defines several standard interfaces that objects may want to implement in addition to its own interfaces.{{r|dbus spec}} Although technically optional, most D-Bus service developers choose to support them in their exported objects since they offer important additional features to D-Bus clients, such as ].{{r|Cocagne 2012}} These standard interfaces are:{{r|dbus spec}}{{r|Cocagne 2012}} | |||
* {{mono|org.freedesktop.DBus.Peer}}: provides a way to test if a D-Bus connection is alive.{{r|Cocagne 2012}} | |||
* {{mono|org.freedesktop.DBus.Introspectable}}: provides an introspection mechanism by which a client process can, at run-time, get a description (in ] format) of the interfaces, methods and signals that the object implements.{{r|dbus tut}}{{r|dbus spec}} | |||
* {{mono|org.freedesktop.DBus.Properties}}: allows a D-Bus object to expose the underlying native object ] or attributes, or simulate them if it does not exist.{{r|dbus spec}} | |||
* {{mono|org.freedesktop.DBus.ObjectManager}}: when a D-Bus service arranges its objects hierarchically, this interface provides a way to query an object about all sub-objects under its path, as well as their interfaces and properties, using a single method call.{{r|dbus spec}} | |||
The D-Bus specification defines a number of administrative bus operations (called "bus services") to be performed using the {{mono|/org/freedesktop/DBus}} object that resides in the {{mono|org.freedesktop.DBus}} bus name.{{r|dbus spec}} Each bus reserves this special bus name for itself, and manages any requests made specifically to this combination of bus name and object path. The administrative operations provided by the bus are those defined by the object's interface {{mono|org.freedesktop.DBus}}. These operations are used for example to provide information about the status of the bus,{{r|intro dbus}} or to manage the request and release of additional ''well-known'' bus names.{{r|dbus spec}}{{r|Cocagne 2012}} | |||
=== Communications model === | |||
D-Bus was conceived as a generic, high-level inter-process communication system. To accomplish such goals, D-Bus communications are based on the exchange of ''messages'' between processes instead of "raw bytes".{{r|intro dbus}}{{r|dbus tut}} D-Bus messages are high-level discrete items that a process can send through the bus to another connected process. Messages have a well-defined structure (even the types of the data carried in their payload are defined), allowing the bus to validate them and to reject any ill-formed message. | |||
In this regard, D-Bus is closer to an ] mechanism than to a classic IPC mechanism, with its own type definition system and its own ].{{r|intro dbus}} | |||
] | |||
The bus supports two modes of interchanging messages between a client and a service process{{r|intro dbus}}: | |||
* One-to-one ]: This is the way for a client to invoke an object's method. The client sends a message to the service process exporting the object, and the service in turn replies with a message back to the client process.{{r|dbus tut}} The message sent by the client must contain the object path, the name of the invoked method (and optionally the name of its interface), and the values of the input parameters (if any) as defined by the object's selected interface. The reply message carries the result of the request, including the values of the output parameters returned by the object's method invocation, or ''exception'' information if there was an error.{{r|intro dbus}}{{r|dbus tut}} | |||
* ]: This is the way for an object to announce the occurrence of a signal to the interested parties. The object's service process broadcasts a message that the bus passes only to the connected clients subscribed to the object's signal.{{r|dbus tut}} The message carries the object path, the name of the signal, the interface to which the signal belongs, and also the values of the signal's parameters (if any). The communication is one-way: there are no response messages to the original message from any client process, since the sender knows neither the identities nor the number of the recipients.{{r|intro dbus}}{{r|dbus tut}} | |||
Every D-Bus message consists of a header and a body.{{r|dbus tut}} The header is formed by several fields that identify the type of message, the sender, as well as information required to deliver the message to its recipient (destination bus name, object path, method or signal name, interface name, etc.).{{r|dbus tut}}{{r|dbus spec}} The body contains the data payload that the receiver process interprets—for instance the input or output arguments. All the data is encoded in a well known binary format called the ''wire format'' which supports the ] of various types, such as integers and floating-point numbers, strings, compound types, and so on,{{r|dbus spec}} also referred to as ]. | |||
The D-Bus specification defines the ]: how to build the D-Bus messages to be exchanged between processes within a D-Bus connection. However, it does not define the underlying transport method for delivering these messages. | |||
== Internals == | |||
Most existing D-Bus implementations follow the architecture of the reference implementation. This architecture consists of two main components:{{r|intro dbus}} | |||
* a point-to-point communications ] that implements the D-Bus ] in order to exchange messages between two processes. In the reference implementation this library is '''{{mono|libdbus}}'''. In other implementations {{mono|libdbus}} may be wrapped by another higher-level library, language binding, or entirely replaced by a different standalone implementation that serves the same purpose.{{r|what is dbus q1}} This library only supports one-to-one communications between two processes.{{r|dbus tut}} | |||
* ]a special ] that plays the bus role and to which the rest of the processes connect using any D-Bus point-to-point communications library. This process is also known as the ''message bus daemon'',{{r|Love 2005}} since it is responsible for routing messages from any process connected to the bus to another. In the reference implementation this role is performed by '''{{mono|dbus-daemon}}''', which itself is built on top of {{mono|libdbus}}. Another implementation of the message bus daemon is '''{{mono|dbus-broker}}''', which is built on top of '''{{mono|sd-bus}}'''. | |||
{{multiple image | |||
| footer = | |||
| image1 = D-Bus communications architecture - simple.svg | |||
| alt1 = Process A and B have a one-to-one D-Bus connection between them over a Unix domain socket | |||
| caption1 = Process A and B have a one-to-one D-Bus connection using {{mono|libdbus}} over a Unix domain socket. They can use it to exchange messages directly.{{r|what is dbus q2}} In this scenario bus names are not required.{{r|dbus tut}} | |||
| image2 = D-Bus communications architecture - message bus.svg | |||
| alt2 = Process A and B have both a one-to-one D-Bus connection with a dbus-daemon process over a Unix domain socket | |||
| caption2 = Process A and B both connected to a {{mono|dbus-daemon}} using {{mono|libdbus}} over a Unix domain socket. They can exchange messages sending them to the message bus process, which in turn will deliver the messages to the appropriate process. In this scenario bus names are mandatory to identify the destination process. | |||
}} | |||
The {{mono|libdbus}} library (or its equivalent) internally uses a native lower-level IPC mechanism to transport the required D-Bus messages between the two processes in both ends of the D-Bus connection. D-Bus specification does not mandate which particular IPC transport mechanisms should be available to use, as it is the communications library that decides what transport methods it supports. For instance, in Unix-like operating systems such as Linux {{mono|libdbus}} typically uses ]s as the underlying transport method, but it also supports ].{{r|intro dbus}}{{r|dbus tut}} | |||
The communications libraries of both processes must agree on the selected transport method and also on the particular channel used for their communication. This information is defined by what D-Bus calls an ''address''.{{r|Cocagne 2012}}{{r|dbus tut}} Unix-domain sockets are ] objects, and therefore they can be identified by a filename, so a valid address would be <code>unix:path=/tmp/.hiddensocket</code>.{{r|intro dbus}}{{r|dbus spec}} Both processes must pass the same address to their respective communications libraries to establish the D-Bus connection between them. An address can also provide additional data to the communications library in the form of comma-separated <code>key=value</code> pairs.{{r|Cocagne 2012}}{{r|dbus spec}} This way, for example, it can provide authentication information to a specific type of connection that supports it. | |||
When a message bus daemon like {{mono|dbus-daemon}} is used to implement a D-Bus bus, all processes that want to connect to the bus must know the ''bus address'', the address by which a process can establish a D-Bus connection to the central message bus process.{{r|intro dbus}}{{r|dbus tut}} In this scenario, the message bus daemon selects the bus address and the remainder processes must pass that value to their corresponding {{mono|libdbus}} or equivalent libraries. {{mono|dbus-daemon}} defines a different bus address for every bus instance it provides. These addresses are defined in the daemon's configuration files. | |||
Two processes can use a D-Bus connection to exchange messages directly between them,{{r|what is dbus q2}} but this is not the way in which D-Bus is normally intended to be used. The usual way is to always use a message bus daemon (i.e. {{mono|dbus-daemon}}) as a communications central point to which each process should establish its point-to-point D-Bus connection. When a process—client or service—sends a D-Bus message, the message bus process receives it in the first instance and delivers it to the appropriate recipient. The message bus daemon may be seen as a hub or router in charge of getting each message to its destination by repeating it through the D-Bus connection to the recipient process.{{r|dbus tut}} The recipient process is determined by the destination bus name in the message's header field,{{r|dbus spec}} or by the subscription information to signals maintained by the message bus daemon in the case of signal propagation messages.{{r|Cocagne 2012}} The message bus daemon can also produce its own messages as a response to certain conditions, such as an error message to a process that sent a message to a nonexistent bus name.{{r|dbus tut}} | |||
{{mono|dbus-daemon}} improves the feature set already provided by D-Bus itself with additional functionality. For example, ''service activation'' allows automatic starting of services when needed—when the first request to any bus name of such service arrives at the message bus daemon.{{r|intro dbus}} This way, service processes neither need to be launched during the ] or user initialization stage nor need they consume memory or other resources when not being used. This feature was originally implemented using ] helpers,{{r|dbus service activation}} but nowadays it can also be provided by ]'s service activation framework.{{citation needed|date=February 2016}} Service activation is an important feature that facilitates the management of the process lifecycle of services (for example when a desktop component should start or stop).{{r|dbus tut}} | |||
== History and adoption == | |||
D-Bus was started in 2002 by Havoc Pennington, Alex Larsson (]) and Anders Carlsson.{{r|Palmieri 2005}} The version 1.0—considered ] stable—was released in November 2006.{{r|dbus 1.0}}{{r|Molkentin 2006}} | |||
]s.]] | |||
Heavily influenced by the ] system used by versions 2 and 3 of ], D-Bus has replaced DCOP in the ] release.{{r|Molkentin 2006}}{{r|KDE dbus intro}} An implementation of D-Bus supports most ] operating systems, and a port for ] exists. It is used by ] 4 and later by ]. In GNOME it has gradually replaced most parts of the earlier ] mechanism. It is also used by ]. | |||
One of the earlier adopters was the (nowadays deprecated) ]. HAL used D-Bus to export information about hardware that has been added to or removed from the computer.{{r|Palmieri 2005}} | |||
The usage of D-Bus is steadily expanding beyond the initial scope of desktop environments to cover an increasing amount of system services. For instance, the ] network daemon, ] bluetooth stack and ] sound server use D-Bus to provide part or all of their services. ] uses the D-Bus wire protocol for communication between ] and systemd, and is also promoting traditional system daemons to D-Bus services, such as ].{{r|Poettering 2015 q2}} Another heavy user of D-Bus is ], whose policy authority daemon is implemented as a service connected to the system bus.{{r|polkit doc}} | |||
== Implementations == | |||
=== {{Anchor|LIBDBUS}} libdbus === | |||
Although there are several implementations of D-Bus, the most widely used is the reference implementation ''libdbus'', developed by the same freedesktop.org project that designed the specification. However, libdbus is a low-level implementation that was never meant to be used directly by application developers, but as a reference guide for other reimplementations of D-Bus (such as those included in standard libraries of desktop environments, or in ] bindings). The freedesktop.org project itself recommends applications authors to "use one of the higher level bindings or implementations" instead.{{r|what is dbus q3}} The predominance of libdbus as the most used D-Bus implementation caused the terms "D-Bus" and "libdbus" to be often used interchangeably, leading to confusion.{{Citation needed|date=December 2022}} | |||
=== GDBus === | |||
GDBus{{r|gdbus}} is an implementation of D-Bus based on ] included in ], aiming to be used by ] and ]. GDBus is not a wrapper of libdbus, but a complete and independent reimplementation of the D-Bus specification and protocol.{{r|gdbus2}} ]<ref>{{cite web |title=MATE: Roadmap |url=http://wiki.mate-desktop.org/roadmap |access-date=31 January 2019 |archive-date=29 July 2019 |archive-url=https://web.archive.org/web/20190729232007/https://wiki.mate-desktop.org/roadmap |url-status=dead }}</ref> and ] (version 4.14), which are also based on GTK+ 3, also use GDBus.{{Citation needed|date=December 2022}} | |||
=== sd-bus === | |||
In 2013, the ] project rewrote libdbus in an effort to simplify the code,{{r|Poettering 2013}} but it also resulted in a significant increase of the overall D-Bus performance. In preliminary benchmarks, ] found that the systemd's D-Bus library increased performance by 360%.{{r|Edge 2013}} By version 221 of ], released in 2015, the sd-bus ] was declared stable.{{r|systemd 221}} | |||
=== {{Anchor|KDBUS}} kdbus === | |||
]}}</ref><ref>{{cite web |url=https://lwn.net/Articles/619069/ |title=Documentation/kdbus.txt (from the initial patch set) |date=2014-11-04 |publisher=]}}</ref> All communication between processes take place over special character device nodes in <code>/dev/kdbus</code> (cf. ]).]] ''kdbus'' was a project that aimed to reimplement D-Bus as a kernel-mediated peer-to-peer ] mechanism. Beside performance improvements, kdbus would have advantages arising from other ] features such as ] and auditing,{{r|Edge 2013}}{{r|Corbet 2014}} security from the kernel mediating, closing race conditions, and allowing D-Bus to be used during boot and shutdown (as needed by systemd).{{r|Kroah-Hartman 2015}} kdbus inclusion in the Linux kernel proved controversial,{{r|Corbet 2015}} and was dropped in favor of , as a more generic ].<ref>{{cite web |url=https://www.youtube.com/watch?v=s2I_7uCto5Q&t=20m34s |archive-url=https://ghostarchive.org/varchive/youtube/20211221/s2I_7uCto5Q |archive-date=2021-12-21 |url-status=live|title=Keynote: A Fireside Chat with Greg Kroah-Hartman, Linux Foundation Fellow |date=18 October 2016 |publisher=]}}{{cbignore}}</ref> | |||
=== Language bindings === | |||
Several programming language ] for D-Bus have been developed,{{r|dbus bindings}} such as those for ], ], ], ] and ].{{Citation needed|date=December 2022}} | |||
== See also == | |||
{{Portal|Free and open-source software}} | |||
{{Div col|colwidth=25em}} | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
* ] | |||
{{div col end}} | |||
== References == | |||
{{reflist|30em|refs= | |||
<!-- ------------ official documentation ------------ --> | |||
<ref name="intro dbus">{{cite web|last1=Vermeulen|first1=Jeroen|title=Introduction to D-Bus|url=http://www.freedesktop.org/IntroductionToDBus/|website=FreeDesktop.org|date=14 Jul 2013|access-date=22 October 2015}}</ref> | |||
<ref name="intro dbus q1">{{cite web|last1=Vermeulen|first1=Jeroen|title=Introduction to D-Bus|url=http://www.freedesktop.org/IntroductionToDBus/|website=FreeDesktop.org|date=14 Jul 2013|access-date=3 October 2015|quote="D-Bus is designed for use as a unified middleware layer underneath the main free desktop environments."}}</ref> | |||
<ref name="intro dbus q2">{{cite web|last1=Vermeulen|first1=Jeroen|title=Introduction to D-Bus|url=http://www.freedesktop.org/IntroductionToDBus/|website=FreeDesktop.org|date=14 Jul 2013|access-date=3 October 2015|quote=" D-Bus was first built to replace the CORBA-like component model underlying the GNOME desktop environment. Similar to DCOP (which is used by KDE), D-Bus is set to become a standard component of the major free desktop environments for GNU/Linux and other platforms."}}</ref> | |||
<ref name="dbus spec">{{cite web|last1=Pennington|first1=Havoc|last2=Carlsson|first2=Anders|last3=Larsson|first3=Alexander|last4=Herzberg|first4=Sven|last5=McVittie|first5=Simon|last6=Zeuthen|first6=David|title=D-Bus Specification|url=http://dbus.freedesktop.org/doc/dbus-specification.html|website=Freedesktop.org|access-date=22 October 2015}}</ref> | |||
<ref name="dbus tut">{{cite web|last1=Pennington|first1=Havoc|last2=Wheeler|first2=David|last3=Walters|first3=Colin|title=D-Bus Tutorial|url=http://dbus.freedesktop.org/doc/dbus-tutorial.html|access-date=21 October 2015}}</ref> | |||
<ref name="dbus tut q1">{{cite web|last1=Pennington|first1=Havoc|last2=Wheeler|first2=David|last3=Walters|first3=Colin|title=D-Bus Tutorial|url=http://dbus.freedesktop.org/doc/dbus-tutorial.html|access-date=21 October 2015|quote="For the within-desktop-session use case, the GNOME and KDE desktops have significant previous experience with different IPC solutions such as CORBA and DCOP. D-Bus is built on that experience and carefully tailored to meet the needs of these desktop projects in particular."}}</ref> | |||
<ref name="what is dbus q1">{{cite web|title=What is D-Bus?|url=http://www.freedesktop.org/Software/dbus/|website=FreeDesktop.org|access-date=29 October 2015|quote="There are also some reimplementations of the D-Bus protocol for languages such as C#, Java, and Ruby. These do not use the libdbus reference implementation"}}</ref> | |||
<ref name="what is dbus q2">{{cite web|title=What is D-Bus?|url=http://www.freedesktop.org/Software/dbus/|website=FreeDesktop.org|access-date=29 October 2015|quote="is built on top of a general one-to-one message passing framework, which can be used by any two apps to communicate directly (without going through the message bus daemon)"}}</ref> | |||
<ref name="what is dbus q3">{{cite web|title=What is D-Bus?|url=http://www.freedesktop.org/Software/dbus/#index1h1|website=FreeDesktop.org|access-date=5 January 2015|quote="The low-level implementation is not primarily designed for application authors to use. Rather, it is a basis for binding authors and a reference for reimplementations. If you are able to do so it is recommended that you use one of the higher level bindings or implementations."}}</ref> | |||
<ref name="KDE dbus intro">{{cite web|last1=Seigo|first1=Aaron|title=Introduction To D-BUS|url=https://techbase.kde.org/Development/Tutorials/D-Bus/Introduction|website=KDE TechBase|access-date=3 November 2015}}</ref> | |||
<ref name="dbus bindings">{{cite web|title=D-Bus Bindings|url=http://www.freedesktop.org/Software/DBusBindings/|website=FreeDesktop.org|access-date=5 January 2015}}</ref> | |||
<ref name="dbus service activation">{{cite web|title=D-BUS System Activation|url=https://dbus.freedesktop.org/doc/system-activation.txt|website=FreeDesktop.org|access-date=18 February 2016}}</ref> | |||
<!-- ------------ articles ------------ --> | |||
<ref name="Cocagne 2012">{{cite web|last1=Cocagne|first1=Tom|title=DBus Overview|url=https://pythonhosted.org/txdbus/dbus_overview.html|date=August 2012|website=pythonhosted.org|access-date=22 October 2015}}</ref> | |||
<ref name="Corbet 2014">{{cite web|last1=Corbet|first1=Jonathan|title=The unveiling of kdbus|url=https://lwn.net/Articles/580194/|date=13 January 2014|publisher=]|access-date=11 April 2014}}</ref> | |||
<ref name="Corbet 2015">{{cite web|last1=Corbet|first1=Jonathan|title=The kdbuswreck|url=https://lwn.net/Articles/641275/|date=22 April 2015|publisher=]|access-date=29 June 2015}}</ref> | |||
<ref name="Edge 2013">{{cite web|last1=Edge|first1=Jake|title=ALS: Linux inter-process communication and kdbus|url=https://lwn.net/Articles/551969/|date=30 May 2013|publisher=]|access-date=21 October 2015}}</ref> | |||
<ref name="Kroah-Hartman 2015">{{cite mailing list|mailing-list=linux-kernel|title= kdbus for 4.1-rc1|first=Greg|last=Kroah-Hartman|author-link=Greg Kroah-Hartman|date=13 Apr 2015|url=http://lkml.iu.edu/hypermail/linux/kernel/1504.1/03936.html}}</ref> | |||
<ref name="Love 2005">{{cite magazine|last1=Love|first1=Robert|title=Get on the D-BUS|url=http://www.linuxjournal.com/article/7744|date=5 January 2005|magazine=]|access-date=14 October 2014}}</ref> | |||
<ref name="Molkentin 2006">{{cite web|last1=Molkentin|first1=Daniel|title=D-Bus 1.0 "Blue Bird" Released|url=https://dot.kde.org/2006/11/12/d-bus-10-blue-bird-released|date=12 November 2006|website=KDE News|access-date=3 November 2015}}</ref> | |||
<ref name="Palmieri 2005">{{cite web|last1=Palmieri|first1=John|title=Get on D-BUS|url=https://www.redhat.com/magazine/003jan05/features/dbus/|date=January 2005|publisher=Red Hat Magazine|access-date=3 November 2015|url-status=dead|archive-url=https://web.archive.org/web/20151023072022/http://www.redhat.com/magazine/003jan05/features/dbus/|archive-date=23 October 2015}}</ref> | |||
<ref name="Poettering 2013">{{cite mailing list|mailing-list=systemd-devel|title= libsystemd-bus + kdbus plans|first=Lennart|last=Poettering|author-link=Lennart Poettering|date=20 Mar 2013|url=http://lists.freedesktop.org/archives/systemd-devel/2013-March/009797.html}}</ref> | |||
<ref name="Poettering 2015" >{{cite web|last1=Poettering|first1=Lennart|title=The new sd-bus API of systemd|url=http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html|date=19 June 2015|access-date=21 October 2015}}</ref> | |||
<ref name="Poettering 2015 q1">{{cite web|last1=Poettering|first1=Lennart|title=The new sd-bus API of systemd|url=http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html|date=19 June 2015|access-date=21 October 2015|quote="we are working on moving things to a true user bus, of which there is only one per user on a system, regardless how many times that user happens to log in"}}</ref> | |||
<ref name="Poettering 2015 q2">{{cite web|last1=Poettering|first1=Lennart|title=The new sd-bus API of systemd|url=http://0pointer.net/blog/the-new-sd-bus-api-of-systemd.html|date=19 June 2015|access-date=21 October 2015|quote="Since systemd's inception it has been the IPC system it exposes its interfaces on."}}</ref> | |||
<!-- ------------ other references ------------ --> | |||
<ref name="gdbus">{{cite web|title=gdbus|url=https://developer.gnome.org/gio/stable/gdbus.html|website=GNOME developer|access-date=4 January 2015}}</ref> | |||
<ref name="gdbus2">{{cite web|title=Migrating to GDBus|url=https://developer.gnome.org/gio/stable/ch35.html|website=GNOME Developer|access-date=21 October 2015|quote="dbus-glib uses the libdbus reference implementation, GDBus doesn't. Instead, it relies on GIO streams as transport layer, and has its own implementation for the D-Bus connection setup and authentication."}}</ref> | |||
<ref name="qtdbus">{{cite web|title=QtDBus module|url=http://doc.qt.io/qt-5/qtdbus-index.html|website=Qt Project|access-date=1 June 2015}}</ref> | |||
<ref name="dbus-java">{{cite web|title=DBus-Java Documentation|url=http://dbus.freedesktop.org/doc/dbus-java/|website=FreeDesktop.org|access-date=4 January 2015}}</ref> | |||
<ref name="polkit doc">{{cite web|title=Polkit reference manual|url=http://www.freedesktop.org/software/polkit/docs/latest/polkit.8.html|website=FreeDesktop.org|access-date=3 November 2015}}</ref> | |||
<ref name="dbus 1.0">{{cite mailing list|mailing-list=dbus|title= D-Bus 1.0.0 "Blue Bird" released|first=John|last=Palmieri|date=9 Nov 2006|url=http://lists.freedesktop.org/archives/dbus/2006-November/006337.html}}</ref> | |||
<ref name="systemd 221">{{cite mailing list|mailing-list=systemd-devel|title= systemd v221|first=Lennart|last=Poettering|author-link=Lennart Poettering|date=19 Jun 2015|url=http://lists.freedesktop.org/archives/systemd-devel/2015-June/033170.html}}</ref> | |||
}} | |||
== External links == | == External links == | ||
* | * home page at Freedesktop.org | ||
* | * | ||
* on the Freedesktop.org wiki | |||
* | |||
* | |||
{{Clear}} | |||
{{Freedesktop.org}} | |||
] | |||
{{Inter-process communication}} | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] | |||
] |
Latest revision as of 00:38, 22 October 2024
Linux middleware "DBus" redirects here. For the Tibetan province, see Dbus.Developer(s) | Red Hat |
---|---|
Initial release | November 2006; 18 years ago (2006-11) |
Stable release | 1.14.10 / September 1, 2023; 15 months ago (2023-09-01) |
Preview release | 1.15.8 / August 21, 2023; 15 months ago (2023-08-21) |
Repository | |
Written in | C |
Operating system | Cross-platform |
Predecessor | CORBA DCOP |
Type | |
License | GPLv2+ or AFL 2.1 |
Website | www |
D-Bus (short for "Desktop Bus") is a message-oriented middleware mechanism that allows communication between multiple processes running concurrently on the same machine. D-Bus was developed as part of the freedesktop.org project, initiated by GNOME developer Havoc Pennington to standardize services provided by Linux desktop environments such as GNOME and KDE.
The freedesktop.org project also developed a free and open-source software library called libdbus, as a reference implementation of the specification. This library should not be confused with D-Bus itself, as other implementations of the D-Bus specification also exist, such as GDBus (GNOME), QtDBus (Qt/KDE), dbus-java and sd-bus (part of systemd).
Overview
D-Bus is an inter-process communication (IPC) mechanism initially designed to replace the software component communications systems used by the GNOME and KDE Linux desktop environments (CORBA and DCOP respectively). The components of these desktop environments are normally distributed in many processes, each one providing only a few—usually one—services. These services may be used by regular client applications or by other components of the desktop environment to perform their tasks.
Processes without D-BusThe same processes with D-BusLarge groups of cooperating processes demand a dense mesh of individual communication channels (using one-to-one IPC methods) between them. D-Bus simplifies the IPC requirements with one single shared channel.D-Bus provides a software-bus abstraction that gathers all the communications between a group of processes over a single shared virtual channel. Processes connected to a bus do not know how it is internally implemented, but D-Bus specification guarantees that all processes connected to the bus can communicate with each other through it. D-Bus incurs at least a 2.5x performance loss over one-to-one IPC.
Linux desktop environments take advantage of the D-Bus facilities by instantiating multiple buses, notably:
- a single system bus, available to all users and processes of the system, that provides access to system services (i.e. services provided by the operating system and also by any system daemons)
- a session bus for each user login session, that provides desktop services to user applications in the same desktop session, and allows the integration of the desktop session as a whole
A process can connect to any number of buses, provided that it has been granted access to them. In practice, this means that any user process can connect to the system bus and to its current session bus, but not to another user's session buses, or even to a different session bus owned by the same user. The latter restriction may change in the future if all user sessions are combined into a single user bus.
D-Bus provides additional or simplifies existing functionality to the applications, including information-sharing, modularity and privilege separation. For example, information on an incoming voice-call received through Bluetooth or Skype can be propagated and interpreted by any currently-running music player, which can react by muting the volume or by pausing playback until the call is finished.
D-Bus can also be used as a framework to integrate different components of a user application. For instance, an office suite can communicate through the session bus to share data between a word processor and a spreadsheet.
D-Bus specification
Bus model
Every connection to a bus is identified in the context of D-Bus by what is called a bus name. A bus name consists of two or more dot-separated strings of letters, digits, dashes, and underscores—a reverse domain name. An example of a valid bus name is org.freedesktop.NetworkManager
.
When a process sets up a connection to a bus, the bus assigns to the connection a special bus name called unique connection name. Bus names of this type are immutable—it is guaranteed they will not change as long as the connection exists—and, more importantly, they cannot be reused during the bus lifetime. This means that no other connection to that bus will ever have assigned such unique connection name, even if the same process closes down the connection to the bus and creates a new one. Unique connection names are easily recognizable because they start with the otherwise forbidden colon character. An example of a unique connection name is :1.1553
(the characters after the colon have no particular meaning).
A process can ask for additional bus names for its connection, provided that any requested name is not already being used by another connection to the bus. In D-Bus parlance, when a bus name is assigned to a connection, it is said the connection owns the bus name. In that sense, a bus name cannot be owned by two connections at the same time, but, unlike unique connection names, these names can be reused if they are available: a process may reclaim a bus name released—purposely or not—by another process.
The idea behind these additional bus names, commonly called well-known names, is to provide a way to refer to a service using a prearranged bus name. For instance, the service that reports the current time and date in the system bus lies in the process whose connection owns the org.freedesktop.timedate1 bus name, regardless of which process it is.
Bus names can be used as a simple way to implement single-instance applications (second instances detect that the bus name is already taken). It can also be used to track a service process lifecycle, since the bus sends a notification when a bus name is released due to a process termination.
Object model
Because of its original conception as a replacement for several component oriented communications systems, D-Bus shares with its predecessors an object model in which to express the semantics of the communications between clients and services. The terms used in the D-Bus object model mimic those used by some object oriented programming languages. That does not mean that D-Bus is somehow limited to OOP languages—in fact, the most used implementation (libdbus) is written in C, a procedural programming language.
In D-Bus, a process offers its services by exposing objects. These objects have methods that can be invoked, and signals that the object can emit. Methods and signals are collectively referred to as the members of the object. Any client connected to the bus can interact with an object by using its methods, making requests or commanding the object to perform actions. For instance, an object representing a time service can be queried by a client using a method that returns the current date and time. A client can also listen to signals that an object emits when its state changes due to certain events, usually related to the underlying service. An example would be when a service that manages hardware devices—such as USB or network drivers—signals a "new hardware device added" event. Clients should instruct the bus that they are interested in receiving certain signals from a particular object, since a D-Bus bus only passes signals to those processes with a registered interest in them.
A process connected to a D-Bus bus can request it to export as many D-Bus objects as it wants. Each object is identified by an object path, a string of numbers, letters and underscores separated and prefixed by the slash character, called that because of their resemblance to Unix filesystem paths. The object path is selected by the requesting process, and must be unique in the context of that bus connection. An example of a valid object path is /org/kde/kspread/sheets/3/cells/4/5
. However, it is not enforced—but also not discouraged—to form hierarchies within object paths. The particular naming convention for the objects of a service is entirely up to the developers of such service, but many developers choose to namespace them using the reserved domain name of the project as a prefix (e.g. /org/kde).
Every object is inextricably associated to the particular bus connection where it was exported, and, from the D-Bus point of view, only lives in the context of such connection. Therefore, in order to be able to use a certain service, a client must indicate not only the object path providing the desired service, but also the bus name under which the service process is connected to the bus. This in turn allows that several processes connected to the bus can export different objects with identical object paths unambiguously.
An interface specifies members—methods and signals—that can be used with an object. It is a set of declarations of methods (including its passing and returning parameters) and signals (including its parameters) identified by a dot-separated name resembling the Java language interfaces notation. An example of a valid interface name is org.freedesktop.Introspectable
. Despite their similarity, interface names and bus names should not be mistaken. A D-Bus object can implement several interfaces, but at least must implement one, providing support for every method and signal defined by it. The combination of all interfaces implemented by an object is called the object type.
When using an object, it is a good practice for the client process to provide the member's interface name besides the member's name, but is only mandatory when there is an ambiguity caused by duplicated member names available from different interfaces implemented by the object—otherwise, the selected member is undefined or erroneous. An emitted signal, on the other hand, must always indicate to which interface it belongs.
The D-Bus specification also defines several standard interfaces that objects may want to implement in addition to its own interfaces. Although technically optional, most D-Bus service developers choose to support them in their exported objects since they offer important additional features to D-Bus clients, such as introspection. These standard interfaces are:
- org.freedesktop.DBus.Peer: provides a way to test if a D-Bus connection is alive.
- org.freedesktop.DBus.Introspectable: provides an introspection mechanism by which a client process can, at run-time, get a description (in XML format) of the interfaces, methods and signals that the object implements.
- org.freedesktop.DBus.Properties: allows a D-Bus object to expose the underlying native object properties or attributes, or simulate them if it does not exist.
- org.freedesktop.DBus.ObjectManager: when a D-Bus service arranges its objects hierarchically, this interface provides a way to query an object about all sub-objects under its path, as well as their interfaces and properties, using a single method call.
The D-Bus specification defines a number of administrative bus operations (called "bus services") to be performed using the /org/freedesktop/DBus object that resides in the org.freedesktop.DBus bus name. Each bus reserves this special bus name for itself, and manages any requests made specifically to this combination of bus name and object path. The administrative operations provided by the bus are those defined by the object's interface org.freedesktop.DBus. These operations are used for example to provide information about the status of the bus, or to manage the request and release of additional well-known bus names.
Communications model
D-Bus was conceived as a generic, high-level inter-process communication system. To accomplish such goals, D-Bus communications are based on the exchange of messages between processes instead of "raw bytes". D-Bus messages are high-level discrete items that a process can send through the bus to another connected process. Messages have a well-defined structure (even the types of the data carried in their payload are defined), allowing the bus to validate them and to reject any ill-formed message. In this regard, D-Bus is closer to an RPC mechanism than to a classic IPC mechanism, with its own type definition system and its own marshaling.
The bus supports two modes of interchanging messages between a client and a service process:
- One-to-one request-response: This is the way for a client to invoke an object's method. The client sends a message to the service process exporting the object, and the service in turn replies with a message back to the client process. The message sent by the client must contain the object path, the name of the invoked method (and optionally the name of its interface), and the values of the input parameters (if any) as defined by the object's selected interface. The reply message carries the result of the request, including the values of the output parameters returned by the object's method invocation, or exception information if there was an error.
- Publish/subscribe: This is the way for an object to announce the occurrence of a signal to the interested parties. The object's service process broadcasts a message that the bus passes only to the connected clients subscribed to the object's signal. The message carries the object path, the name of the signal, the interface to which the signal belongs, and also the values of the signal's parameters (if any). The communication is one-way: there are no response messages to the original message from any client process, since the sender knows neither the identities nor the number of the recipients.
Every D-Bus message consists of a header and a body. The header is formed by several fields that identify the type of message, the sender, as well as information required to deliver the message to its recipient (destination bus name, object path, method or signal name, interface name, etc.). The body contains the data payload that the receiver process interprets—for instance the input or output arguments. All the data is encoded in a well known binary format called the wire format which supports the serialization of various types, such as integers and floating-point numbers, strings, compound types, and so on, also referred to as marshaling.
The D-Bus specification defines the wire protocol: how to build the D-Bus messages to be exchanged between processes within a D-Bus connection. However, it does not define the underlying transport method for delivering these messages.
Internals
Most existing D-Bus implementations follow the architecture of the reference implementation. This architecture consists of two main components:
- a point-to-point communications library that implements the D-Bus wire protocol in order to exchange messages between two processes. In the reference implementation this library is libdbus. In other implementations libdbus may be wrapped by another higher-level library, language binding, or entirely replaced by a different standalone implementation that serves the same purpose. This library only supports one-to-one communications between two processes.
- a special daemon process that plays the bus role and to which the rest of the processes connect using any D-Bus point-to-point communications library. This process is also known as the message bus daemon, since it is responsible for routing messages from any process connected to the bus to another. In the reference implementation this role is performed by dbus-daemon, which itself is built on top of libdbus. Another implementation of the message bus daemon is dbus-broker, which is built on top of sd-bus.
The libdbus library (or its equivalent) internally uses a native lower-level IPC mechanism to transport the required D-Bus messages between the two processes in both ends of the D-Bus connection. D-Bus specification does not mandate which particular IPC transport mechanisms should be available to use, as it is the communications library that decides what transport methods it supports. For instance, in Unix-like operating systems such as Linux libdbus typically uses Unix domain sockets as the underlying transport method, but it also supports TCP sockets.
The communications libraries of both processes must agree on the selected transport method and also on the particular channel used for their communication. This information is defined by what D-Bus calls an address. Unix-domain sockets are filesystem objects, and therefore they can be identified by a filename, so a valid address would be unix:path=/tmp/.hiddensocket
. Both processes must pass the same address to their respective communications libraries to establish the D-Bus connection between them. An address can also provide additional data to the communications library in the form of comma-separated key=value
pairs. This way, for example, it can provide authentication information to a specific type of connection that supports it.
When a message bus daemon like dbus-daemon is used to implement a D-Bus bus, all processes that want to connect to the bus must know the bus address, the address by which a process can establish a D-Bus connection to the central message bus process. In this scenario, the message bus daemon selects the bus address and the remainder processes must pass that value to their corresponding libdbus or equivalent libraries. dbus-daemon defines a different bus address for every bus instance it provides. These addresses are defined in the daemon's configuration files.
Two processes can use a D-Bus connection to exchange messages directly between them, but this is not the way in which D-Bus is normally intended to be used. The usual way is to always use a message bus daemon (i.e. dbus-daemon) as a communications central point to which each process should establish its point-to-point D-Bus connection. When a process—client or service—sends a D-Bus message, the message bus process receives it in the first instance and delivers it to the appropriate recipient. The message bus daemon may be seen as a hub or router in charge of getting each message to its destination by repeating it through the D-Bus connection to the recipient process. The recipient process is determined by the destination bus name in the message's header field, or by the subscription information to signals maintained by the message bus daemon in the case of signal propagation messages. The message bus daemon can also produce its own messages as a response to certain conditions, such as an error message to a process that sent a message to a nonexistent bus name.
dbus-daemon improves the feature set already provided by D-Bus itself with additional functionality. For example, service activation allows automatic starting of services when needed—when the first request to any bus name of such service arrives at the message bus daemon. This way, service processes neither need to be launched during the system initialization or user initialization stage nor need they consume memory or other resources when not being used. This feature was originally implemented using setuid helpers, but nowadays it can also be provided by systemd's service activation framework. Service activation is an important feature that facilitates the management of the process lifecycle of services (for example when a desktop component should start or stop).
History and adoption
D-Bus was started in 2002 by Havoc Pennington, Alex Larsson (Red Hat) and Anders Carlsson. The version 1.0—considered API stable—was released in November 2006.
Heavily influenced by the DCOP system used by versions 2 and 3 of KDE, D-Bus has replaced DCOP in the KDE 4 release. An implementation of D-Bus supports most POSIX operating systems, and a port for Windows exists. It is used by Qt 4 and later by GNOME. In GNOME it has gradually replaced most parts of the earlier Bonobo mechanism. It is also used by Xfce.
One of the earlier adopters was the (nowadays deprecated) Hardware Abstraction Layer. HAL used D-Bus to export information about hardware that has been added to or removed from the computer.
The usage of D-Bus is steadily expanding beyond the initial scope of desktop environments to cover an increasing amount of system services. For instance, the NetworkManager network daemon, BlueZ bluetooth stack and PulseAudio sound server use D-Bus to provide part or all of their services. systemd uses the D-Bus wire protocol for communication between systemctl and systemd, and is also promoting traditional system daemons to D-Bus services, such as logind. Another heavy user of D-Bus is Polkit, whose policy authority daemon is implemented as a service connected to the system bus.
Implementations
libdbus
Although there are several implementations of D-Bus, the most widely used is the reference implementation libdbus, developed by the same freedesktop.org project that designed the specification. However, libdbus is a low-level implementation that was never meant to be used directly by application developers, but as a reference guide for other reimplementations of D-Bus (such as those included in standard libraries of desktop environments, or in programming language bindings). The freedesktop.org project itself recommends applications authors to "use one of the higher level bindings or implementations" instead. The predominance of libdbus as the most used D-Bus implementation caused the terms "D-Bus" and "libdbus" to be often used interchangeably, leading to confusion.
GDBus
GDBus is an implementation of D-Bus based on GIO streams included in GLib, aiming to be used by GTK+ and GNOME. GDBus is not a wrapper of libdbus, but a complete and independent reimplementation of the D-Bus specification and protocol. MATE Desktop and Xfce (version 4.14), which are also based on GTK+ 3, also use GDBus.
sd-bus
In 2013, the systemd project rewrote libdbus in an effort to simplify the code, but it also resulted in a significant increase of the overall D-Bus performance. In preliminary benchmarks, BMW found that the systemd's D-Bus library increased performance by 360%. By version 221 of systemd, released in 2015, the sd-bus API was declared stable.
kdbus
kdbus was a project that aimed to reimplement D-Bus as a kernel-mediated peer-to-peer inter-process communication mechanism. Beside performance improvements, kdbus would have advantages arising from other Linux kernel features such as namespaces and auditing, security from the kernel mediating, closing race conditions, and allowing D-Bus to be used during boot and shutdown (as needed by systemd). kdbus inclusion in the Linux kernel proved controversial, and was dropped in favor of BUS1, as a more generic inter-process communication.
Language bindings
Several programming language bindings for D-Bus have been developed, such as those for Java, C#, Ruby, Rust and Perl.
See also
- Linux on the desktop
- Common Language Infrastructure
- Common Object Request Broker Architecture
- Component Object Model
- Distributed Component Object Model
- Foreign function interface
- Java remote method invocation
- Remote procedure call
- XPCOM
References
- "D-Bus 1.14.x changelog". Retrieved 30 December 2023.
- "NEWS file for current branch". Retrieved 30 December 2023.
- Havoc's Blog July, 2007
-
Ward, Brian (2004). "14: A brief survey of the Linux desktop". How Linux Works: What Every Superuser Should Know (2 ed.). San Francisco: No Starch Press (published 2014). p. 305. ISBN 9781593275679. Retrieved 2016-11-07.
One of the most important developments to come out of the Linux desktop is the Desktop Bus (D-Bus), a message-passing system. D-Bus is important because it serves as an interprocess communication mechanism that allows desktop applications to talk to each other .
- ^ Vermeulen, Jeroen (14 Jul 2013). "Introduction to D-Bus". FreeDesktop.org. Retrieved 22 October 2015.
- ^ Cocagne, Tom (August 2012). "DBus Overview". pythonhosted.org. Retrieved 22 October 2015.
- Vermeulen, Jeroen (14 Jul 2013). "Introduction to D-Bus". FreeDesktop.org. Retrieved 3 October 2015.
D-Bus is designed for use as a unified middleware layer underneath the main free desktop environments.
- ^ Palmieri, John (January 2005). "Get on D-BUS". Red Hat Magazine. Archived from the original on 23 October 2015. Retrieved 3 November 2015.
- ^ "gdbus". GNOME developer. Retrieved 4 January 2015.
- "QtDBus module". Qt Project. Retrieved 1 June 2015.
- "DBus-Java Documentation". FreeDesktop.org. Retrieved 4 January 2015.
- Poettering, Lennart (19 June 2015). "The new sd-bus API of systemd". Retrieved 21 October 2015.
- Pennington, Havoc; Wheeler, David; Walters, Colin. "D-Bus Tutorial". Retrieved 21 October 2015.
For the within-desktop-session use case, the GNOME and KDE desktops have significant previous experience with different IPC solutions such as CORBA and DCOP. D-Bus is built on that experience and carefully tailored to meet the needs of these desktop projects in particular.
- Vermeulen, Jeroen (14 Jul 2013). "Introduction to D-Bus". FreeDesktop.org. Retrieved 3 October 2015.
D-Bus was first built to replace the CORBA-like component model underlying the GNOME desktop environment. Similar to DCOP (which is used by KDE), D-Bus is set to become a standard component of the major free desktop environments for GNU/Linux and other platforms.
- "Desktop Environment - an overview | ScienceDirect Topics". www.sciencedirect.com. Retrieved 2023-08-24.
- Answer 7. "D-Bus FAQ". Retrieved 2024-08-06.
- ^ Pennington, Havoc; Carlsson, Anders; Larsson, Alexander; Herzberg, Sven; McVittie, Simon; Zeuthen, David. "D-Bus Specification". Freedesktop.org. Retrieved 22 October 2015.
- ^ Pennington, Havoc; Wheeler, David; Walters, Colin. "D-Bus Tutorial". Retrieved 21 October 2015.
- Poettering, Lennart (19 June 2015). "The new sd-bus API of systemd". Retrieved 21 October 2015.
we are working on moving things to a true user bus, of which there is only one per user on a system, regardless how many times that user happens to log in
- ^ Love, Robert (5 January 2005). "Get on the D-BUS". Linux Journal. Retrieved 14 October 2014.
- "What is D-Bus?". FreeDesktop.org. Retrieved 29 October 2015.
There are also some reimplementations of the D-Bus protocol for languages such as C#, Java, and Ruby. These do not use the libdbus reference implementation
- ^ "What is D-Bus?". FreeDesktop.org. Retrieved 29 October 2015.
is built on top of a general one-to-one message passing framework, which can be used by any two apps to communicate directly (without going through the message bus daemon)
- "D-BUS System Activation". FreeDesktop.org. Retrieved 18 February 2016.
- Palmieri, John (9 Nov 2006). "[announce] D-Bus 1.0.0 "Blue Bird" released". dbus (Mailing list).
- ^ Molkentin, Daniel (12 November 2006). "D-Bus 1.0 "Blue Bird" Released". KDE News. Retrieved 3 November 2015.
- Seigo, Aaron. "Introduction To D-BUS". KDE TechBase. Retrieved 3 November 2015.
- Poettering, Lennart (19 June 2015). "The new sd-bus API of systemd". Retrieved 21 October 2015.
Since systemd's inception it has been the IPC system it exposes its interfaces on.
- "Polkit reference manual". FreeDesktop.org. Retrieved 3 November 2015.
- "What is D-Bus?". FreeDesktop.org. Retrieved 5 January 2015.
The low-level implementation is not primarily designed for application authors to use. Rather, it is a basis for binding authors and a reference for reimplementations. If you are able to do so it is recommended that you use one of the higher level bindings or implementations.
- "Migrating to GDBus". GNOME Developer. Retrieved 21 October 2015.
dbus-glib uses the libdbus reference implementation, GDBus doesn't. Instead, it relies on GIO streams as transport layer, and has its own implementation for the D-Bus connection setup and authentication.
- "MATE: Roadmap". Archived from the original on 29 July 2019. Retrieved 31 January 2019.
- Poettering, Lennart (20 Mar 2013). "[HEADSUP] libsystemd-bus + kdbus plans". systemd-devel (Mailing list).
- ^ Edge, Jake (30 May 2013). "ALS: Linux inter-process communication and kdbus". LWN.net. Retrieved 21 October 2015.
- Poettering, Lennart (19 Jun 2015). "[ANNOUNCE] systemd v221". systemd-devel (Mailing list).
- "The unveiling of kdbus". LWN.net. 2014-01-13.
- "Documentation/kdbus.txt (from the initial patch set)". LWN.net. 2014-11-04.
- Corbet, Jonathan (13 January 2014). "The unveiling of kdbus". LWN.net. Retrieved 11 April 2014.
- Kroah-Hartman, Greg (13 Apr 2015). "[GIT PULL] kdbus for 4.1-rc1". linux-kernel (Mailing list).
- Corbet, Jonathan (22 April 2015). "The kdbuswreck". LWN.net. Retrieved 29 June 2015.
- "Keynote: A Fireside Chat with Greg Kroah-Hartman, Linux Foundation Fellow". YouTube. 18 October 2016. Archived from the original on 2021-12-21.
- "D-Bus Bindings". FreeDesktop.org. Retrieved 5 January 2015.
External links
- D-Bus home page at Freedesktop.org
- D-Bus specification
- Introduction to D-Bus on the Freedesktop.org wiki
- D-Bus Tutorial
- DBus Overview
Free and open-source software projects hosted by freedesktop.org | ||||||||
---|---|---|---|---|---|---|---|---|
OS components |
| |||||||
Libraries | ||||||||
Frameworks | ||||||||
Meetings |
Inter-process communication | |
---|---|
Data exchange among threads in computer programs | |
Methods | |
Protocols and standards | |
Software libraries and frameworks |