Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

D-Bus Tutorial #543

Open
1 task
irthomasthomas opened this issue Feb 16, 2024 · 0 comments
Open
1 task

D-Bus Tutorial #543

irthomasthomas opened this issue Feb 16, 2024 · 0 comments
Labels
Algorithms Sorting, Learning or Classifying. All algorithms go here. linux Linux notes tools links man-pages linux man pages shell-tools Tools and utilities for shell scripting and command line operations

Comments

@irthomasthomas
Copy link
Owner

D-Bus Tutorial

Description

What is D-Bus?

D-Bus is a system for interprocess communication (IPC). Architecturally, it has several layers:

  • 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 or bindings based on particular application frameworks. For example, libdbus-glib and libdbus-qt. There are also bindings to languages such as Python. These wrapper libraries are the API most people should use, as they simplify the details of D-Bus programming. libdbus is intended to be a low-level backend for the higher level bindings. Much of the libdbus API is only useful for binding implementation.

libdbus only supports one-to-one connections, just like a raw network socket. However, rather than sending byte streams over the connection, you send messages. Messages have a header identifying the kind of message, and a body containing a data payload. libdbus also abstracts the exact transport used (sockets vs. whatever else), and handles details such as authentication.

The message bus daemon forms the hub of a wheel. Each spoke of the wheel is a one-to-one connection to an application using libdbus. An application sends a message to the bus daemon over its spoke, and the bus daemon forwards the message to other connected applications as appropriate. Think of the daemon as a router.

The bus daemon has multiple instances on a typical computer. The first instance is a machine-global singleton, that is, a system daemon similar to sendmail or Apache. This instance has heavy security restrictions on what messages it will accept, and is used for systemwide communication. The other instances are created one per user login session. These instances allow applications in the user's session to communicate with one another.

The systemwide and per-user daemons are separate. Normal within-session IPC does not involve the systemwide message bus process and vice versa.

D-Bus Applications

There are many, many technologies in the world that have "Inter-process communication" or "networking" in their stated purpose: CORBA, DCE, DCOM, DCOP, XML-RPC, SOAP, MBUS, Internet Communications Engine (ICE), and probably hundreds more. Each of these is tailored for particular kinds of application. D-Bus is designed for two specific cases:

  1. Communication between desktop applications in the same desktop session; to allow integration of the desktop session as a whole, and address issues of process lifecycle (when do desktop components start and stop running).
  2. Communication between the desktop session and the operating system, where the operating system would typically include the kernel and any system daemons or processes.

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. D-Bus may or may not be appropriate for other applications; the FAQ has some comparisons to other IPC systems.

The problem solved by the systemwide or communication-with-the-OS case is explained well by the following text from the Linux Hotplug project:

"A gap in current Linux support is that policies with any sort of dynamic 'interact with user' component aren't currently supported. For example, that's often needed the first time a network adapter or printer is connected, and to determine appropriate places to mount disk drives. It would seem that such actions could be supported for any case where a responsible human can be identified: single user workstations, or any system which is remotely administered.

This is a classic 'remote sysadmin' problem, where in this case hotplugging needs to deliver an event from one security domain (operating system kernel, in this case) to another (desktop for logged-in user, or remote sysadmin). Any effective response must go the other way: the remote domain taking some action that lets the kernel expose the desired device capabilities. (The action can often be taken asynchronously, for example letting new hardware be idle until a meeting finishes.) At this writing, Linux doesn't have widely adopted solutions to such problems. However, the new D-Bus work may begin to solve that problem."

D-Bus may happen to be useful for purposes other than the one it was designed for. Its general properties that distinguish it from other forms of IPC are:

  • Binary protocol designed to be used asynchronously (similar in spirit to the X Window System protocol).
  • Stateful, reliable connections held open over time.
  • The message bus is a daemon, not a "swarm" or distributed architecture.
  • Many implementation and deployment issues are specified rather than left ambiguous/configurable/pluggable.
  • Semantics are similar to the existing DCOP system, allowing KDE to adopt it more easily.
  • Security features to support the systemwide mode of the message bus.

For more information, visit the D-Bus Tutorial.

Suggested labels

{'label-name': 'inter-process communication', 'label-description': 'Focuses on communication between different applications or processes within a system.', 'confidence': 66.88}

@irthomasthomas irthomasthomas added Algorithms Sorting, Learning or Classifying. All algorithms go here. linux Linux notes tools links New-Label Choose this option if the existing labels are insufficient to describe the content accurately Software2.0 Software development driven by AI and neural networks. man-pages linux man pages KDE shell-tools Tools and utilities for shell scripting and command line operations and removed New-Label Choose this option if the existing labels are insufficient to describe the content accurately Software2.0 Software development driven by AI and neural networks. labels Feb 16, 2024
@irthomasthomas irthomasthomas removed the KDE label Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Algorithms Sorting, Learning or Classifying. All algorithms go here. linux Linux notes tools links man-pages linux man pages shell-tools Tools and utilities for shell scripting and command line operations
Projects
None yet
Development

No branches or pull requests

1 participant