D-Bus Specification

Havoc Pennington

Red Hat, Inc.


<hp@pobox.com>

Anders Carlsson

CodeFactory AB


<andersca@codefactory.se>

Alexander Larsson

Red Hat, Inc.


<alexl@redhat.com>

Sven Herzberg

Imendio AB


<sven@imendio.com>

Simon McVittie

Collabora Ltd.


<simon.mcvittie@collabora.co.uk>

David Zeuthen

Red Hat, Inc.


<davidz@redhat.com>

Version 0.19

Revision History
Revision currentcommit log
Revision 0.1920 February 2012smcv/lp
formally define unique connection names and well-known bus names; document best practices for interface, bus, member and error names, and object paths; document the search path for session and system services on Unix; document the systemd transport
Revision 0.1829 July 2011smcv
define eavesdropping, unicast, broadcast; add eavesdrop match keyword; promote type system to a top-level section
Revision 0.171 June 2011smcv/davidz
define ObjectManager; reserve extra pseudo-type-codes used by GVariant
Revision 0.1611 April 2011
add path_namespace, arg0namespace; argNpath matches object paths
Revision 0.153 November 2010
Revision 0.1412 May 2010
Revision 0.1323 Dezember 2009
Revision 0.127 November, 2006
Revision 0.116 February 2005
Revision 0.1028 January 2005
Revision 0.97 Januar 2005
Revision 0.806 September 2003
First released document.

Table of Contents

Introduction
Protocol and Specification Stability
Type System
Type Signatures
Marshaling (Wire Format)
Message Protocol
Message Format
Valid Names
Message Types
Invalid Protocol and Spec Extensions
Authentication Protocol
Protocol Overview
Special credentials-passing nul byte
AUTH command
CANCEL Command
DATA Command
BEGIN Command
REJECTED Command
OK Command
ERROR Command
NEGOTIATE_UNIX_FD Command
AGREE_UNIX_FD Command
Future Extensions
Authentication examples
Authentication state diagrams
Authentication mechanisms
Server Addresses
Transports
Unix Domain Sockets
launchd
systemd
TCP Sockets
Nonce-secured TCP Sockets
Executed Subprocesses on Unix
Meta Transports
Autolaunch
UUIDs
Standard Interfaces
org.freedesktop.DBus.Peer
org.freedesktop.DBus.Introspectable
org.freedesktop.DBus.Properties
org.freedesktop.DBus.ObjectManager
Introspection Data Format
Message Bus Specification
Message Bus Overview
Message Bus Names
Message Bus Message Routing
Message Bus Starting Services
Well-known Message Bus Instances
Message Bus Messages
Glossary

Introduction

D-Bus is a system for low-latency, low-overhead, easy to use interprocess communication (IPC). In more detail:

  • D-Bus is low-latency because it is designed to avoid round trips and allow asynchronous operation, much like the X protocol.

  • D-Bus is low-overhead because it uses a binary protocol, and does not have to convert to and from a text format such as XML. Because D-Bus is intended for potentially high-resolution same-machine IPC, not primarily for Internet IPC, this is an interesting optimization.

  • D-Bus is easy to use because it works in terms of messages rather than byte streams, and automatically handles a lot of the hard IPC issues. Also, the D-Bus library is designed to be wrapped in a way that lets developers use their framework's existing object/type system, rather than learning a new one specifically for IPC.

The base D-Bus protocol is a one-to-one (peer-to-peer or client-server) protocol, specified in the section called “Message Protocol”. That is, it is a system for one application to talk to a single other application. However, the primary intended application of the protocol is the D-Bus message bus, specified in the section called “Message Bus Specification”. The message bus is a special application that accepts connections from multiple other applications, and forwards messages among them.

Uses of D-Bus include notification of system changes (notification of when a camera is plugged in to a computer, or a new version of some software has been installed), or desktop interoperability, for example a file monitoring service or a configuration service.

D-Bus is designed for two specific use cases:

  • A "system bus" for notifications from the system to user sessions, and to allow the system to request input from user sessions.

  • A "session bus" used to implement desktop environments such as GNOME and KDE.

D-Bus is not intended to be a generic IPC system for any possible application, and intentionally omits many features found in other IPC systems for this reason.

At the same time, the bus daemons offer a number of features not found in other IPC systems, such as single-owner "bus names" (similar to X selections), on-demand startup of services, and security policies. In many ways, these features are the primary motivation for developing D-Bus; other systems would have sufficed if IPC were the only goal.

D-Bus may turn out to be useful in unanticipated applications, but future versions of this spec and the reference implementation probably will not incorporate features that interfere with the core use cases.

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119. However, the document could use a serious audit to be sure it makes sense to do so. Also, they are not capitalized.

Protocol and Specification Stability

The D-Bus protocol is frozen (only compatible extensions are allowed) as of November 8, 2006. However, this specification could still use a fair bit of work to make interoperable reimplementation possible without reference to the D-Bus reference implementation. Thus, this specification is not marked 1.0. To mark it 1.0, we'd like to see someone invest significant effort in clarifying the specification language, and growing the specification to cover more aspects of the reference implementation's behavior.

Until this work is complete, any attempt to reimplement D-Bus will probably require looking at the reference implementation and/or asking questions on the D-Bus mailing list about intended behavior. Questions on the list are very welcome.

Nonetheless, this document should be a useful starting point and is to our knowledge accurate, though incomplete.

Type System

D-Bus has a type system, in which values of various types can be serialized into a sequence of bytes referred to as the wire format in a standard way. Converting a value from some other representation into the wire format is called marshaling and converting it back from the wire format is unmarshaling.

Type Signatures

The D-Bus protocol does not include type tags in the marshaled data; a block of marshaled values must have a known type signature. The type signature is made up of type codes. A type code is an ASCII character representing the type of a value. Because ASCII characters are used, the type signature will always form a valid ASCII string. A simple string compare determines whether two type signatures are equivalent.

As a simple example, the type code for 32-bit integer (INT32) is the ASCII character 'i'. So the signature for a block of values containing a single INT32 would be:

          "i"
        

A block of values containing two INT32 would have this signature:

          "ii"
        

All basic types work like INT32 in this example. To marshal and unmarshal basic types, you simply read one value from the data block corresponding to each type code in the signature. In addition to basic types, there are four container types: STRUCT, ARRAY, VARIANT, and DICT_ENTRY.

STRUCT has a type code, ASCII character 'r', but this type code does not appear in signatures. Instead, ASCII characters '(' and ')' are used to mark the beginning and end of the struct. So for example, a struct containing two integers would have this signature:

          "(ii)"
        

Structs can be nested, so for example a struct containing an integer and another struct:

          "(i(ii))"
        

The value block storing that struct would contain three integers; the type signature allows you to distinguish "(i(ii))" from "((ii)i)" or "(iii)" or "iii".

The STRUCT type code 'r' is not currently used in the D-Bus protocol, but is useful in code that implements the protocol. This type code is specified to allow such code to interoperate in non-protocol contexts.

Empty structures are not allowed; there must be at least one type code between the parentheses.

ARRAY has ASCII character 'a' as type code. The array type code must be followed by a single complete type. The single complete type following the array is the type of each array element. So the simple example is:

          "ai"
        

which is an array of 32-bit integers. But an array can be of any type, such as this array-of-struct-with-two-int32-fields:

          "a(ii)"
        

Or this array of array of integer:

          "aai"
        

The phrase single complete type deserves some definition. A single complete type is a basic type code, a variant type code, an array with its element type, or a struct with its fields. So the following signatures are not single complete types:

          "aa"
        

          "(ii"
        

          "ii)"
        

And the following signatures contain multiple complete types:

          "ii"
        

          "aiai"
        

          "(ii)(ii)"
        

Note however that a single complete type may contain multiple other single complete types.

VARIANT has ASCII character 'v' as its type code. A marshaled value of type VARIANT will have the signature of a single complete type as part of the value. This signature will be followed by a marshaled value of that type.

A DICT_ENTRY works exactly like a struct, but rather than parentheses it uses curly braces, and it has more restrictions. The restrictions are: it occurs only as an array element type; it has exactly two single complete types inside the curly braces; the first single complete type (the "key") must be a basic type rather than a container type. Implementations must not accept dict entries outside of arrays, must not accept dict entries with zero, one, or more than two fields, and must not accept dict entries with non-basic-typed keys. A dict entry is always a key-value pair.

The first field in the DICT_ENTRY is always the key. A message is considered corrupt if the same key occurs twice in the same array of DICT_ENTRY. However, for performance reasons implementations are not required to reject dicts with duplicate keys.

In most languages, an array of dict entry would be represented as a map, hash table, or dict object.

The following table summarizes the D-Bus types.

Conventional NameCodeDescription
INVALID0 (ASCII NUL)Not a valid type code, used to terminate signatures
BYTE121 (ASCII 'y')8-bit unsigned integer
BOOLEAN98 (ASCII 'b')Boolean value, 0 is FALSE and 1 is TRUE. Everything else is invalid.
INT16110 (ASCII 'n')16-bit signed integer
UINT16113 (ASCII 'q')16-bit unsigned integer
INT32105 (ASCII 'i')32-bit signed integer
UINT32117 (ASCII 'u')32-bit unsigned integer
INT64120 (ASCII 'x')64-bit signed integer
UINT64116 (ASCII 't')64-bit unsigned integer
DOUBLE100 (ASCII 'd')IEEE 754 double
STRING115 (ASCII 's')UTF-8 string (must be valid UTF-8). Must be nul terminated and contain no other nul bytes.
OBJECT_PATH111 (ASCII 'o')Name of an object instance
SIGNATURE103 (ASCII 'g')A type signature
ARRAY97 (ASCII 'a')Array
STRUCT114 (ASCII 'r'), 40 (ASCII '('), 41 (ASCII ')')Struct; type code 114 'r' is reserved for use in bindings and implementations to represent the general concept of a struct, and must not appear in signatures used on D-Bus.
VARIANT118 (ASCII 'v') Variant type (the type of the value is part of the value itself)
DICT_ENTRY101 (ASCII 'e'), 123 (ASCII '{'), 125 (ASCII '}') Entry in a dict or map (array of key-value pairs). Type code 101 'e' is reserved for use in bindings and implementations to represent the general concept of a dict or dict-entry, and must not appear in signatures used on D-Bus.
UNIX_FD104 (ASCII 'h')Unix file descriptor
(reserved)109 (ASCII 'm')Reserved for a 'maybe' type compatible with the one in GVariant, and must not appear in signatures used on D-Bus until specified here
(reserved)42 (ASCII '*')Reserved for use in bindings/implementations to represent any single complete type, and must not appear in signatures used on D-Bus.
(reserved)63 (ASCII '?')Reserved for use in bindings/implementations to represent any basic type, and must not appear in signatures used on D-Bus.
(reserved)64 (ASCII '@'), 38 (ASCII '&'), 94 (ASCII '^')Reserved for internal use by bindings/implementations, and must not appear in signatures used on D-Bus. GVariant uses these type-codes to encode calling conventions.

Marshaling (Wire Format)

Given a type signature, a block of bytes can be converted into typed values. This section describes the format of the block of bytes. Byte order and alignment issues are handled uniformly for all D-Bus types.

A block of bytes has an associated byte order. The byte order has to be discovered in some way; for D-Bus messages, the byte order is part of the message header as described in the section called “Message Format”. For now, assume that the byte order is known to be either little endian or big endian.

Each value in a block of bytes is aligned "naturally," for example 4-byte values are aligned to a 4-byte boundary, and 8-byte values to an 8-byte boundary. To properly align a value, alignment padding may be necessary. The alignment padding must always be the minimum required padding to properly align the following value; and it must always be made up of nul bytes. The alignment padding must not be left uninitialized (it can't contain garbage), and more padding than required must not be used.

Given all this, the types are marshaled on the wire as follows:

Conventional NameEncodingAlignment
INVALIDNot applicable; cannot be marshaled.N/A
BYTEA single 8-bit byte.1
BOOLEANAs for UINT32, but only 0 and 1 are valid values.4
INT1616-bit signed integer in the message's byte order.2
UINT1616-bit unsigned integer in the message's byte order.2
INT3232-bit signed integer in the message's byte order.4
UINT3232-bit unsigned integer in the message's byte order.4
INT6464-bit signed integer in the message's byte order.8
UINT6464-bit unsigned integer in the message's byte order.8
DOUBLE64-bit IEEE 754 double in the message's byte order.8
STRINGA UINT32 indicating the string's length in bytes excluding its terminating nul, followed by non-nul string data of the given length, followed by a terminating nul byte. 4 (for the length)
OBJECT_PATHExactly the same as STRING except the content must be a valid object path (see below). 4 (for the length)
SIGNATUREThe same as STRING except the length is a single byte (thus signatures have a maximum length of 255) and the content must be a valid signature (see below). 1
ARRAY A UINT32 giving the length of the array data in bytes, followed by alignment padding to the alignment boundary of the array element type, followed by each array element. The array length is from the end of the alignment padding to the end of the last element, i.e. it does not include the padding after the length, or any padding after the last element. Arrays have a maximum length defined to be 2 to the 26th power or 67108864. Implementations must not send or accept arrays exceeding this length. 4 (for the length)
STRUCT A struct must start on an 8-byte boundary regardless of the type of the struct fields. The struct value consists of each field marshaled in sequence starting from that 8-byte alignment boundary. 8
VARIANT A variant type has a marshaled SIGNATURE followed by a marshaled value with the type given in the signature. Unlike a message signature, the variant signature can contain only a single complete type. So "i", "ai" or "(ii)" is OK, but "ii" is not. Use of variants may not cause a total message depth to be larger than 64, including other container types such as structures. 1 (alignment of the signature)
DICT_ENTRY Identical to STRUCT. 8
UNIX_FD32-bit unsigned integer in the message's byte order. The actual file descriptors need to be transferred out-of-band via some platform specific mechanism. On the wire, values of this type store the index to the file descriptor in the array of file descriptors that accompany the message.4

Valid Object Paths

An object path is a name used to refer to an object instance. Conceptually, each participant in a D-Bus message exchange may have any number of object instances (think of C++ or Java objects) and each such instance will have a path. Like a filesystem, the object instances in an application form a hierarchical tree.

The following rules define a valid object path. Implementations must not send or accept messages with invalid object paths.

  • The path may be of any length.

  • The path must begin with an ASCII '/' (integer 47) character, and must consist of elements separated by slash characters.

  • Each element must only contain the ASCII characters "[A-Z][a-z][0-9]_"

  • No element may be the empty string.

  • Multiple '/' characters cannot occur in sequence.

  • A trailing '/' character is not allowed unless the path is the root path (a single '/' character).

Object paths are often namespaced by starting with a reversed domain name and containing an interface version number, in the same way as interface names and well-known bus names. This makes it possible to implement more than one service, or more than one version of a service, in the same process, even if the services share a connection but cannot otherwise co-operate (for instance, if they are implemented by different plugins).

For instance, if the owner of example.com is developing a D-Bus API for a music player, they might use the hierarchy of object paths that start with /com/example/MusicPlayer1 for its objects.

Valid Signatures

An implementation must not send or accept invalid signatures. Valid signatures will conform to the following rules:

  • The signature ends with a nul byte.

  • The signature is a list of single complete types. Arrays must have element types, and structs must have both open and close parentheses.

  • Only type codes and open and close parentheses are allowed in the signature. The STRUCT type code is not allowed in signatures, because parentheses are used instead.

  • The maximum depth of container type nesting is 32 array type codes and 32 open parentheses. This implies that the maximum total depth of recursion is 64, for an "array of array of array of ... struct of struct of struct of ..." where there are 32 array and 32 struct.

  • The maximum length of a signature is 255.

  • Signatures must be nul-terminated.

Message Protocol

A message consists of a header and a body. If you think of a message as a package, the header is the address, and the body contains the package contents. The message delivery system uses the header information to figure out where to send the message and how to interpret it; the recipient interprets the body of the message.

The body of the message is made up of zero or more arguments, which are typed values, such as an integer or a byte array.

Both header and body use the D-Bus type system and format for serializing data.

Message Format

A message consists of a header and a body. The header is a block of values with a fixed signature and meaning. The body is a separate block of values, with a signature specified in the header.

The length of the header must be a multiple of 8, allowing the body to begin on an 8-byte boundary when storing the entire message in a single buffer. If the header does not naturally end on an 8-byte boundary up to 7 bytes of nul-initialized alignment padding must be added.

The message body need not end on an 8-byte boundary.

The maximum length of a message, including header, header alignment padding, and body is 2 to the 27th power or 134217728. Implementations must not send or accept messages exceeding this size.

The signature of the header is:

          "yyyyuua(yv)"
        

Written out more readably, this is:

          BYTE, BYTE, BYTE, BYTE, UINT32, UINT32, ARRAY of STRUCT of (BYTE,VARIANT)
        

These values have the following meanings:

ValueDescription
1st BYTEEndianness flag; ASCII 'l' for little-endian or ASCII 'B' for big-endian. Both header and body are in this endianness.
2nd BYTEMessage type. Unknown types must be ignored. Currently-defined types are described below.
3rd BYTEBitwise OR of flags. Unknown flags must be ignored. Currently-defined flags are described below.
4th BYTEMajor protocol version of the sending application. If the major protocol version of the receiving application does not match, the applications will not be able to communicate and the D-Bus connection must be disconnected. The major protocol version for this version of the specification is 1.
1st UINT32Length in bytes of the message body, starting from the end of the header. The header ends after its alignment padding to an 8-boundary.
2nd UINT32The serial of this message, used as a cookie by the sender to identify the reply corresponding to this request. This must not be zero.
ARRAY of STRUCT of (BYTE,VARIANT)An array of zero or more header fields where the byte is the field code, and the variant is the field value. The message type determines which fields are required.

Message types that can appear in the second byte of the header are:

Conventional nameDecimal valueDescription
INVALID0This is an invalid type.
METHOD_CALL1Method call.
METHOD_RETURN2Method reply with returned data.
ERROR3Error reply. If the first argument exists and is a string, it is an error message.
SIGNAL4Signal emission.

Flags that can appear in the third byte of the header:

Conventional nameHex valueDescription
NO_REPLY_EXPECTED0x1This message does not expect method return replies or error replies; the reply can be omitted as an optimization. However, it is compliant with this specification to return the reply despite this flag and the only harm from doing so is extra network traffic.
NO_AUTO_START0x2The bus must not launch an owner for the destination name in response to this message.

Header Fields

The array at the end of the header contains header fields, where each field is a 1-byte field code followed by a field value. A header must contain the required header fields for its message type, and zero or more of any optional header fields. Future versions of this protocol specification may add new fields. Implementations must ignore fields they do not understand. Implementations must not invent their own header fields; only changes to this specification may introduce new header fields.

Again, if an implementation sees a header field code that it does not expect, it must ignore that field, as it will be part of a new (but compatible) version of this specification. This also applies to known header fields appearing in unexpected messages, for example: if a signal has a reply serial it must be ignored even though it has no meaning as of this version of the spec.

However, implementations must not send or accept known header fields with the wrong type stored in the field value. So for example a message with an INTERFACE field of type UINT32 would be considered corrupt.

Here are the currently-defined header fields:

Conventional NameDecimal CodeTypeRequired InDescription
INVALID0N/Anot allowedNot a valid field name (error if it appears in a message)
PATH1OBJECT_PATHMETHOD_CALL, SIGNALThe object to send a call to, or the object a signal is emitted from. The special path /org/freedesktop/DBus/Local is reserved; implementations should not send messages with this path, and the reference implementation of the bus daemon will disconnect any application that attempts to do so.
INTERFACE2STRINGSIGNAL The interface to invoke a method call on, or that a signal is emitted from. Optional for method calls, required for signals. The special interface org.freedesktop.DBus.Local is reserved; implementations should not send messages with this interface, and the reference implementation of the bus daemon will disconnect any application that attempts to do so.
MEMBER3STRINGMETHOD_CALL, SIGNALThe member, either the method name or signal name.
ERROR_NAME4STRINGERRORThe name of the error that occurred, for errors
REPLY_SERIAL5UINT32ERROR, METHOD_RETURNThe serial number of the message this message is a reply to. (The serial number is the second UINT32 in the header.)
DESTINATION6STRINGoptionalThe name of the connection this message is intended for. Only used in combination with the message bus, see the section called “Message Bus Specification”.
SENDER7STRINGoptionalUnique name of the sending connection. The message bus fills in this field so it is reliable; the field is only meaningful in combination with the message bus.
SIGNATURE8SIGNATUREoptionalThe signature of the message body. If omitted, it is assumed to be the empty signature "" (i.e. the body must be 0-length).
UNIX_FDS9UINT32optionalThe number of Unix file descriptors that accompany the message. If omitted
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.