this post was submitted on 28 Dec 2023
203 points (81.4% liked)

Linux

48149 readers
752 users here now

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.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

Does anybody know why dbus exists? I've been wracking my brain trying to come up with a usecase for dbus that isn't already covered by Unix sockets.

You want to remotely control a daemon? Use sockets. You want the daemon to respond to the client? Sockets. Want to exchange information in json? plaintext? binary data? Sockets can do it. Want to restrict access to a socket? Go ahead, change the socket's permissions. Want to prevent unauthorized programs from pretending to be someone they're not? Change the permissions of the directory containing the socket. Want network transparency? That's why we have abstract sockets.

Plenty of well-established software uses sockets. Music player daemon uses sockets. BSPWM uses sockets. Tmux uses sockets. Pipewire uses sockets. Dhcpcd uses sockets. Heck, dbus itself relies on sockets!

For developers, using sockets is easy. I once wrote a program that interfaced with BSPWM, and it was a breeze. Dbus, on the other hand, not so much. I tried writing a Python script that would contact Network Manager and check the WiFi signal strength. Right off the bat I'm using some obscure undocumented package for interfacing with dbus. What is an introspection? What is a proxy object? What is an interface? Why do I need 60 lines of (Python!) code for a seemingly trivial operation?

So why do some developers decide to use dbus when they could just use unix sockets and save a lot of hassle for themselves and others?

you are viewing a single comment's thread
view the rest of the comments
[–] aport 110 points 10 months ago (3 children)

"Bro just use sockets lol" completely misses the point. When you decide you want message based IPC, you need to then design and implement:

  • Message formatting
  • Service addressing
  • Data marshalling
  • Subscriptions and publishing
  • Method calling, marshalling of arguments and responses
  • Broadcast and 1:1 messaging

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.

[–] [email protected] 7 points 10 months ago

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.

[–] [email protected] 1 points 10 months ago* (last edited 10 months ago)

Message formatting

still have to do that with dbus

Service addressing

They're Unix sockets, dude, they're file paths in /run

Data marshalling

Still have to do that with dbus, also that's the same thing as message formatting

Pubsub

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?)

Method calling, marshalling of arguments and responses

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.

Broadcast and 1:1 messaging

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.

[–] [email protected] 1 points 10 months ago

You still have to do this with dbus