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?

    • teawrecks@sopuli.xyz
      link
      fedilink
      arrow-up
      3
      arrow-down
      1
      ·
      1 year ago

      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.

  • nickwitha_k (he/him)@lemmy.sdf.org
    link
    fedilink
    arrow-up
    3
    ·
    edit-2
    1 year 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
    link
    fedilink
    arrow-up
    2
    ·
    1 year ago

    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.

  • nous@programming.dev
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    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.

  • MonkderZweite@feddit.ch
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    1 year ago

    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?

    • renzev@lemmy.worldOP
      link
      fedilink
      arrow-up
      1
      ·
      1 year 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.

  • xia@lemmy.sdf.org
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

    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

  • ipsirc@lemmy.ml
    link
    fedilink
    English
    arrow-up
    1
    ·
    1 year ago

    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.

    • Troy@lemmy.ca
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      No. DBUS has its roots in freedesktop.org and the KDE+Gnome projects. It’s basically a desktop agnostic reimplemented of KDE’s DCOP, which was itself a simplified CORBA (gnome was using ORBit at the time, if I recall correctly). DBUS was so useful that the domain spaces its been applied to soon rapidly outgrew the desktop space, and this is why it’s usually started earlier these days.

      It also works on Windows.

  • cbarrick@lemmy.world
    link
    fedilink
    English
    arrow-up
    0
    ·
    1 year ago

    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.

    • renzev@lemmy.worldOP
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      modular daemons

      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.

      It can even start the receiving daemon if it is not yet running.

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

      • aport@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        “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.