]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
varlink: if $SYSTEMD_VARLINK_LISTEN is set to "-", listen on stdio
authorLennart Poettering <lennart@poettering.net>
Thu, 25 Apr 2024 08:57:56 +0000 (10:57 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 27 Jun 2024 08:52:23 +0000 (10:52 +0200)
docs/ENVIRONMENT.md
src/shared/varlink.c

index d44e91b9739e761c2cecb8aa66e599d97c0b5cc0..7d712c09900babba77364ae557adaee695c6b8e1 100644 (file)
@@ -686,7 +686,8 @@ Tools using the Varlink protocol (such as `varlinkctl`) or sd-bus (such as
 * `$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.
+  would listen on. If set to "-" the tool will turn stdin/stdout into a Varlink
+  connection.
 
 `systemd-mountfsd`:
 
index 6826e3eb9bd22718f5bc320ee53dc25af30b929c..8814c98f2e6c218590bccc288305623f03ac193c 100644 (file)
@@ -3803,12 +3803,17 @@ int varlink_server_listen_auto(VarlinkServer *s) {
                 n++;
         }
 
-        /* For debug purposes let's listen on an explicitly specified address */
+        /* 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 (streq(e, "-"))
+                        r = varlink_server_add_connection_stdio(s, /* ret= */ NULL);
+                else
+                        r = varlink_server_listen_address(s, e, FLAGS_SET(s->flags, VARLINK_SERVER_ROOT_ONLY) ? 0600 : 0666);
                 if (r < 0)
                         return r;
+
+                n++;
         }
 
         return n;
@@ -4258,7 +4263,7 @@ 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 */
+        const char *e = secure_getenv("SYSTEMD_VARLINK_LISTEN"); /* Permit an explicit override */
         if (e)
                 return true;