203
What is the point of dbus?
(lemmy.world)
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
With pipes/sockets, each program has to coordinate the establishment of the connection with the other program. This is especially problematic if you want to have modular daemons, e.g. to support drop-in replacements with alternative implementations, or if you have multiple programs that you need to communicate with (each with a potentially different protocol).
To solve this problem, you want to standardize the connection establishment and message delivery, which is what dbus does.
With dbus, you just write your message to the bus. Dbus will handle delivering the message to the right program. It can even start the receiving daemon if it is not yet running.
It's a bit similar to the role of an intermediate representation in compilers.
A message bus won't magically remove the need for developers to sit down together and agree on how some API would work. And not having a message bus also doesn't magically prevent you from allowing for alternative implementations. Pipewire is an alternative implementation of pulseaudio, and neither of those rely on dbus (pulse can optionally use dbus, but not for its core features). When using dbus, developers have to agree on which path the service owns and which methods it exposes. When using unix sockets, they have to agree where the socket lives and what data format it uses. It's all the same.
We have a tool for that, it's called an init system. Init systems offer a large degree of control over daemons (centralized logging? making sure things are started in the correct order? letting the user disable and enable different daemons?). Dbus' autostart mechanism is a poor substitute. Want to run daemons per-user instead of as root? Many init systems let you do that too (I know systemd and runit do).
"Bro just use sockets lol" completely misses the point. When you decide you want message based IPC, you need to then design and implement:
And before you know it you've reimplemented dbus, but your solution is undocumented, full of bugs, has no library, no introspection, no debugging tools, can only be used from one language, and in general is most likely pure and complete garbage.
Well said. There are so many details to making code work that can so often be avoided by using the right tooling. OP said it was harder to get started, which implies they did not handle the details and have code not actually robust to all kinds of edge cases. Maybe they don't need it but they probably do.
You still have to do this with dbus
still have to do that with dbus
They're Unix sockets, dude, they're file paths in /run
Still have to do that with dbus, also that's the same thing as message formatting
Again, sockets. One application binds and many can connect (how often do you really need more than one application to respond to a method call? That's a valid reason to use dbus in lieu of sockets, but how often do you need it?)
They're called "unix doors", and that's the third time you've said marshalling. As for that, language agnostic data marshalling is kind of a solved problem. I'm personally a fan of msgpack but JSON works too if you want to maximize compatibility. Or XML if you really want to piss off the people who interact with your API.
Sockets and doors can only do 1:1, and that's true enough, but it occurs to me that 99% of use cases don't need that and thus don't need dbus. dbus can still be used for those cases, but less load on dbus daemon = less load on system. Also you said that already with pubsub.
As for that blob at the bottom, again, who said anything about there not being a language agnostic library? It'd be a lot of work to make one, sure, but that doesn't mean it's impossible. Besides, most of the work has been done for you in the form of language agnostic marshalling libraries which as you said are like 50% of the problem. The rest is just syscalls and minor protocol standardization (how to reference FDs passed through the door in the msgpack data etc.)
And what I've just described isn't a reimplementation of dbus without any of the good parts, it's a reimplementation of dbus on top of the kernel instead of on top of a daemon that doesn't need to be there.