this post was submitted on 28 Dec 2023
201 points (81.7% liked)

Linux

48256 readers
421 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?

top 50 comments
sorted by: hot top controversial new old
[–] cbarrick@lemmy.world 148 points 10 months ago (10 children)

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.

[–] Tiuku@sopuli.xyz 8 points 10 months ago

This reminds me of QT's signal/slot system. I.e. instead of calling functions directly, you just emit a signal and then any number of functions may have the receiving slot enabled.

Lot's of similar systems in other frameworks too I'm sure.

load more comments (9 replies)
[–] xia@lemmy.sdf.org 76 points 10 months ago (2 children)

Easy... decoupling. You hit the pause button on your keyboard, it does not need to "know" (in code or compile time or at runtime) what your music player is, and it can still pause it. Similarly, you can write a new media player, and not have to convince 1000 different projects to support or implement your custom api. https://en.m.wikipedia.org/wiki/Enterprise_service_bus

load more comments (2 replies)
[–] grue@lemmy.world 76 points 10 months ago (2 children)

Because this

potentially has a much larger average degree distribution than this

[–] Atemu@lemmy.ml 12 points 10 months ago (1 children)
load more comments (1 replies)
[–] AVincentInSpace@pawb.social 3 points 10 months ago* (last edited 10 months ago) (1 children)

...and why is that...better?

Programs still have to be written to accommodate the specific protocol that the program on the other end speaks, and dbus paths could translate pretty directly to subdirectories of /run. All adding dbus in the middle does is add a daemon where there doesn't need to be one and force the programs to talk to each other through that rather than directly to each other

load more comments (1 replies)
[–] nickwitha_k@lemmy.sdf.org 63 points 10 months ago* (last edited 10 months ago)

Sockets are effectively point-to-point communication. Dbus is a bus. Your question is similar to "what is the point of I2, or an ATA bus when directly wiring ICs gets the job done". Both have different strengths and weaknesses.

[–] fiohnah@lemmy.blahaj.zone 63 points 10 months ago (1 children)

My serious answer, not an argument: Use d-feet to inspect what's available on the system and session buses. That'll show the benefit of introspection and a common serialization mechanism.

About the security comments: Some access control mechanisms aren't just allow/deny, and many need more than socket permissions. Those benefit from DBus policies, and PolicyKit integration helps for more complex needs. You can always DIY it, that's Linux/FOSS life, but these are great tools to have in your toolbox. I'll avoid credential passing via sockets whenever I can and have something else do it.

[–] renzev@lemmy.world 21 points 10 months ago

Great point about policies! Setting permissions on sockets only gets you so far... I guess if you really wanted to, you could create an individual socket for every method of every resource, and have granular permissions that way. But that would be quite messy

[–] avidamoeba@lemmy.ca 62 points 10 months ago (1 children)

Some heavy schooling happening in this thread. Glad to see it. Learning is a good thing. 🙌

[–] teawrecks@sopuli.xyz 13 points 10 months ago (1 children)

I'm learning a lot, so I'm not a fan of the people flaming and downvoting OP for having genuine confusion. I want us to incentivize more posts like this.

[–] LemmyHead@lemmy.ml 3 points 10 months ago

Same here. I've always wondered what dbus actually was and I'm glad OP asked

[–] aberrate_junior_beatnik@lemmy.world 55 points 10 months ago (6 children)

Want to exchange information in json? plaintext? binary data? Sockets can do it.

This is exactly why you need something like dbus. If you just have a socket, you know nothing about how the data is structured, what the communication protocol is, etc. dbus defines all this.

load more comments (6 replies)
[–] troyunrau@lemmy.ca 43 points 10 months ago (1 children)

Look into history of object brokering in object oriented environments. I was around when KDE went from CORBA to DCOP to DBUS, but not involved in the decisions. Basically: object sharing between processes with security, type translation, and a few other things. In the Microsoft world, this was called "component object model" if my memory is correct.

DBUS is pretty nice for complex interactions.

[–] azimir@lemmy.ml 16 points 10 months ago

Based on the various other descriptions of the DBUS features, I kept thinking "this sounds like a message passing model with a bit of CORBA hiding in there". It's got a bit of SLP and AMQP/MQTT to it, just on a local machine instead of a distributed network. It's solving a lot of problems with service discovery, message passing structure, and separating transmission layer details from service API design. Raw sockets/pipes can always be used to pass data (it's how DBUS does it!), but there's additional problems of where to send the data and how to ensure data formatting that sockets/pipes do not have the capability of solving by design since they're simple and foundational to how interprocess communication works in the kernel.

[–] dave881@lemmy.world 35 points 10 months ago (1 children)

Dbus attempts to provide a standardized system for inter process communication (IPC) without the complexity of managing individual connections between each and every process that needs to share certain types of data.

https://en.m.wikipedia.org/wiki/D-Bus

load more comments (1 replies)
[–] UntouchedWagons@lemmy.ca 35 points 10 months ago (1 children)

I don't know but I'm interested in the answer.

[–] glibg10b@lemmy.ml 8 points 10 months ago

New comments have appeared

[–] NeoNachtwaechter@lemmy.world 32 points 10 months ago

Sometimes you want loose coupling.

[–] nous@programming.dev 28 points 10 months ago (7 children)

Sockets are just streams of bytes - no defined structure to them at all. Dbus is about defining a common interface that everything can talk. That means when writing a program you don't need to learn how every program you want to talk to talks over its own socket - just can just use a dbus library and query what is available on the system.

At least that is the idea - IMO its implementation has a lot to be desired but a central event bus IMO is a good idea. Just needs to be easy to integrate with which I think is what dbus fails at.

A great example is music player software - rather than every music player software creating its own socket and each having its own API to basically all do the same operations. So anything that want to just play/pause some music would need to understand all the differences between all the various different music applications. Instead with a central event bus system each music app could integrate with that and each application that wants to talk to a music app would just need to talk to the event bus and not need to understand every single music app out there.

[–] platypus_plumba@lemmy.world 3 points 10 months ago

But isn't this the reason why client libraries to talk to programs behind sockets exist? Kinda like an SDK library behind an HTTP protocol API?

load more comments (6 replies)
[–] mcepl@lemmy.world 26 points 10 months ago* (last edited 10 months ago) (1 children)

Yes, of course, the sockets are the answer to everything (and BTW, d-bus uses sockets as well, e.g. /run/dbus/system_bus_socket on my current system), but the problem is no standard for the communication over these sockets (or where is the socket located). For example, X11 developed one system of communicating over their socket, but it was used just by few X11 programs, and everybody else had their other system of communication. And even if an app found some socket, there was absolutely no standard how exactly should programs communicate over it. How to send more than just plain ASCII strings? Each program had to write their own serialization/deserialization code, their own format for marshalling binary data, etc. Now there is just one standard for those protocols, and even libraries with the standard (and well tested) code for it.

load more comments (1 replies)
[–] ipsirc@lemmy.ml 22 points 10 months ago (1 children)

dbus can also start a program. For example when one notification was generated and no notification daemon is running, then dbus launch one to handle the request.

[–] RedKrieg@lemmy.redkrieg.com 5 points 10 months ago (1 children)

Doesn't systemd have the ability to do this as well with unix sockets?

load more comments (1 replies)
[–] possiblylinux127@lemmy.zip 21 points 10 months ago (2 children)

Its so that your system can hold passengers

bus

[–] maryjayjay@lemmy.world 22 points 10 months ago

*can hold dpassengers

[–] norgur@discuss.tchncs.de 3 points 10 months ago

Get into de bus?

[–] Quazatron@lemmy.world 19 points 10 months ago (1 children)

It would not be created if existing plumbing covered all use cases.

Don't assume you know better and that developers are simply reinventing the wheel.

[–] turkalino@lemmy.yachts 12 points 10 months ago (2 children)

Reinventing the wheel? Making new systems which create more problems than they solve? Adding abstractions which actually make things more complex?

Nah, those things have never happened in software

[–] redcalcium@lemmy.institute 9 points 10 months ago

Every 10 years, a new abstraction layer will be added to the system. I wonder how an average linux desktop would look like under the hood in 100 years.

[–] Quazatron@lemmy.world 4 points 10 months ago

There is a lot of 'reinventing the wheel' in software, and I did not claim otherwise.

When new abstractions are beneficial, other programs take advantage of them and the whole ecosystem moves forward. When they are not, nobody cares and they are ignored and die. In that respect, open source software development is very much like evolution.

Judging by apps using it, looks like this abstraction is indeed useful.

[–] bizdelnick@lemmy.ml 19 points 10 months ago
[–] mvirts@lemmy.world 16 points 10 months ago (1 children)

What's the point of sockets?

[–] loopgru@slrpnk.net 19 points 10 months ago

WHY is Gamora?

[–] chitak166@lemmy.world 11 points 10 months ago (1 children)

I'm a firm believer that the vast majority of things we needed for software were implemented by the 2000s.

Usually, people who don't understand what they're doing will overcomplicate things to cover-up their misunderstandings. I think choosing a technology before you have a use-case is one of these examples.

[–] vsis@feddit.cl 14 points 10 months ago (1 children)

Those who don't understand Unix are condemned to reinvent it, poorly. ~HS

load more comments (1 replies)
[–] Aux@lemmy.world 10 points 10 months ago

What is the point of a steak when you can drink tea? Mmm...

[–] ninekeysdown@lemmy.world 8 points 10 months ago

I just came across this - https://fedoramagazine.org/d-bus-overview/ - and I think it explains it pretty well.

load more comments
view more: next ›