]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
varlink: also honour new env var $SYSTEMD_VARLINK_LISTEN in varlink_server_listen_auto() 30959/head
authorLennart Poettering <lennart@poettering.net>
Tue, 16 Jan 2024 10:01:28 +0000 (11:01 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 16 Jan 2024 12:45:35 +0000 (13:45 +0100)
varlink_server_listen_auto() is supposed to be the one-stop solution for
turning simple command line tools into IPC services. They aren't easy to
test/debug however, since you have to invoke them through a service
manager.

Let's make this easier: if the SYSTEMD_VARLINK_LISTEN env var is set,
let's listen on the socket specified therein. This makes things easier
to gdb: just run the service from the cmdline.

docs/ENVIRONMENT.md
src/shared/varlink.c

index c96e6db85eaaf551db46bb0ae002c41855c20f0c..454a02991d948e5167576ee3694643a6647c0a14 100644 (file)
@@ -616,3 +616,8 @@ Tools using the Varlink protocol (such as `varlinkctl`) or sd-bus (such as
 
 * `$SYSTEMD_SSH` – the ssh binary to invoke when the `ssh:` transport is
   used. May be a filename (which is searched for in `$PATH`) or absolute path.
+
+* `$SYSTEMD_VARLINK_LISTEN` – interpreted by some tools that provide a Varlink
+  service. Takes a file system path: if specified the tool will listen on an
+  `AF_UNIX` stream socket on the specified path in addition to whatever else it
+  would listen on.
index 67ed7652336e5d344b80faee04977b963e895c30..699d21745f187eb652a638086b347aa73853a76c 100644 (file)
@@ -3477,6 +3477,14 @@ int varlink_server_listen_auto(VarlinkServer *s) {
                 n++;
         }
 
+        /* For debug purposes let's listen on an explicitly specified address */
+        const char *e = secure_getenv("SYSTEMD_VARLINK_LISTEN");
+        if (e) {
+                r = varlink_server_listen_address(s, e, FLAGS_SET(s->flags, VARLINK_SERVER_ROOT_ONLY) ? 0600 : 0666);
+                if (r < 0)
+                        return r;
+        }
+
         return n;
 }
 
@@ -3922,6 +3930,10 @@ int varlink_invocation(VarlinkInvocationFlags flags) {
 
         /* Returns true if this is a "pure" varlink server invocation, i.e. with one fd passed. */
 
+        const char *e = secure_getenv("SYSTEMD_VARLINK_LISTEN"); /* Permit a manual override for testing purposes */
+        if (e)
+                return true;
+
         r = sd_listen_fds_with_names(/* unset_environment= */ false, &names);
         if (r < 0)
                 return r;