…, it's JSON use make it more conceptually compatible with the rest of the world and various other things.
-
…, 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).
-
Lennart Poetteringreplied to Lennart Poettering last edited by
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:
-
Lennart Poetteringreplied to Lennart Poettering last edited by
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…
-
Lennart Poetteringreplied to Lennart Poettering last edited by
…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).
-
Lennart Poetteringreplied to Lennart Poettering last edited by
There are various bindings for Varlink available from the Varlink project, but with systemd v257 we now make systemd's own C implementation available publically too: sd-varlink.
sd-varlink has been around for quite a while, and is quite well tested (including fuzzed) by now hence. It's already driving your systemd installations, except mostly internally so far.
Since Varlink uses JSON for marshalling its messages, sd-varlink comes with a companion API: sd-json. It's another C library for JSON.
-
Lennart Poetteringreplied to Lennart Poettering last edited by
You are of course right if you say that there are already so many of those, why another? And you'd be right. My answer to that is that sd-json is much nicer to use than most, since it doesn't just allow you deal with JSON objects, it also helps you with building them from C data structures, and to map JSON objects back to C data structures. It also helps you with higher level operations that the low-level JSON datatypes leave you in the cold with:
-
Lennart Poetteringreplied to Lennart Poettering last edited by
i.e. for example handles base64 encoding/decoding for handling binary blobs within JSON automatically, or it helps you with dealing with JSON's >53bit integer problem, and various other things.
Right now, documentation for sd-varlink and sd-json is scarce (one could even say "barely existing"), but there are plenty of real-life examples in the systemd source tree, of course.
-
Lennart Poetteringreplied to Lennart Poettering last edited by
At Linux' best conference, All Systems Go! 2024 in Berlin this year I gave a (brief) talk about Varlink, and why you should consider it. If you want to know more about the concept, this might be a good starting point:
https://media.ccc.de/v/all-systems-go-2024-276-varlink-now-
And that's all for now, enjoy!