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

Linux

47232 readers
782 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?

(page 2) 26 comments
sorted by: hot top controversial new old
[–] [email protected] 2 points 8 months ago

I will conveniently avoid any dbus talk, because the why is not so interesting as the how and direct you to this path /var/run/wpa_supplicant. You would probably send SCAN_RESULTS on the socket, you could also initiate a SCAN first to include the strength of stations you're not connected to. If you want deeper access to wireless, you use netlink to communicate with the kernel (see /usr/include/linux/nl80211.h) and poke some NL80211_STA_INFOs.. or the other direction (everything is a file) you just parse /proc/net/wireless without any special permissions for the current signal strength.

Oh.. and btw dbus has a simple binary protocol underneath all the XML/interface fluff and uses a UNIX socket.

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

Btw, why do i need to start xfce/xfwm with dbus for automount in thunar to work, instead of just running dbus as a service on the side?

[–] [email protected] 2 points 8 months ago

By "start with dbus" do you mean with the dbus-launch utility? I think it's needed because it sets some environment variables that thunar uses to actually find and connect to the bus. If you run just the daemon "on the side", thunar won't know how to connect to it. Kind of how you need $DISPLAY to be set correctly for X11 applications to work.

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

Dbus is a better name

load more comments
view more: ‹ prev next ›