mas.to is one of the many independent Mastodon servers you can use to participate in the fediverse.
Hello! mas.to is a fast, up-to-date and fun Mastodon server.

Administered by:

Server stats:

12K
active users

5️⃣ Here's the 5th installment of posts highlighting key new features of the upcoming v257 release of systemd. #systemd257

Since its beginnings systemd has been a heavy user of the D-Bus IPC system. It provides D-Bus APIs, it calls D-Bus APIs, it schedules activation of the D-Bus broker, and even provides its own C D-Bus client library (sd-bus).

However, since early on our use of D-Bus was not without various major problems. One of the biggest goes something like this:

D-Bus' model is built around a central broker daemon, which is started during boot, but unfortunately relatively late (i.e. together with other, regular daemons instead of early boot or the initrd). However, systemd brings up the system as a whole and hence needs IPC from earliest moment on.

And then there are various components of systemd that the D-Bus broker relies on (i.e. consumes functionality of) and hence cannot themselves provide their services on D-Bus, …

…, in order to avoid a chicken/egg problem, a cyclic dependency, and deadlocks. (Example: journald provides logging to the D-Bus broker, and hence cannot provide APIs via D-Bus. Similar PID 1 itself, or systemd-userdb/systemd-homed which provide user record resolution which D-Bus needs for its policies, and so on and so on).

These problems are very hard to tackle. For example in PID 1 itself we provide our D-Bus APIs not just via the broker, but also via another local "direct" socket.

The latter sucks in major ways, since we basically had to reimplement a subset of the broker ourselves, with message multiplexing, subscription, signal matching and a lot of other stuff. Because this was so messy we never did the same for journald, userdbd or homed.

These two are just the biggest issues with D-Bus, but there are a lot more, in my eyes. Hence, quite some time ago we started to use a different type of IPC for these cases, initially just internally.

That alternative IPC is called Varlink (varlink.org/). It has been around for a while, and initially we only adopted it where D-Bus was just too bad to use, and only internally. Over the last couple of releases that changed however: we started to make heavier use of it and provide public interfaces via Varlink in addition or instead of D-Bus.

In many ways Varlink is much nicer to work with than D-Bus: it's a lot simpler, it's brokerless design make it a ton faster, …

VARLINKVARLINKThe Varlink Website

…, it's JSON use make it more conceptually compatible with the rest of the world and various other things.

It's also a lot easier to write Varlink services than D-Bus, because it allows you to handle each connection in a different process, thus being compatible with codebases that do not have event loops (D-Bus due to its multiplexing forces you to process all messages within the same process, and due to the global ordering within a single event loop).

To give one example, "bootctl" is a small tool that installs the systemd-boot boot loader into the ESP for you. It's a command line tool that synchronously copies a bunch of files into the target mount. We always had the plan to turn that into a D-Bus service, but never actually did it, because doing that is pain: we'd have to turn it into an event loop driven thing, which is just nasty for something so simple that just copies some files.

In a Varlink world, the problem goes away:

we just let systemd's socket activation logic listen on an AF_UNIX/SOCK_STREAM socket, and then let it fork off a new bootctl instance for each connection. That instance then just processes that connection and is done. And it's easy: it just does what it usually does, but instead of reading the commands to execute from the command line it just reads them from a small JSON object it gets from STDIN. And it just writes its output as JSON to STDOUT, done.

In fact, because bootctl already…

…supported JSON output anyway, the output side was done pretty much anyway.

Anyway, there are many other stories like that.

Suffice to say, in v257 there are now 19 Varlink interfaces/services, which we added in a short time, for various things that never had them before when D-Bus was our sole focus, because it was so nasty to add that.

(For comparison: we provide only 11 D-Bus API services at this time).

Steven Reed

@pid_eins
Would it be feasible at any point to rip out at least some of the pre-existing native dbus APIs and provide them via a small bridge which does translation to/from varlink?

@srtcd424 The semantics are too different. I see no advantage of that.

systemd will speak both IPC interfaces in the future.

I'd expect new APIs are probably going to show up more in Varlink than in D-Bus though.