]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
stdio-bridge: add support for --system and --user
authorLennart Poettering <lennart@poettering.net>
Mon, 14 Dec 2020 12:23:31 +0000 (13:23 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 15 Dec 2020 17:01:20 +0000 (18:01 +0100)
So far, the bridge always acted as if "--system" was used, i.e. would
unconditionally connect to the system bus. Let's add "--user" too, to
connect to the users session bus.

This is mostly for completeness' sake.

I wanted to use this when making sd-bus's ability to connect to other
user's D-Bus busses work, but it didn't exist so far. In the interest of
keeping things compatible the implementation in sd-bus will not use the
new "--user" switch, and instead manually construct the right bus path
via "--path=", but we still should add the proper switches, as
preparation for a brighter future, one day.

src/stdio-bridge/stdio-bridge.c

index 1b7c3feaeace91f66bded4d7da05e38f454f0b63..5d8b514874b7ca7895d652be8f77c5b005b71a56 100644 (file)
@@ -23,6 +23,7 @@
 
 static const char *arg_bus_path = DEFAULT_BUS_PATH;
 static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
+static bool arg_user = false;
 
 static int help(void) {
 
@@ -30,8 +31,10 @@ static int help(void) {
                "STDIO or socket-activatable proxy to a given DBus endpoint.\n\n"
                "  -h --help              Show this help\n"
                "     --version           Show package version\n"
-               "  -p --bus-path=PATH     Path to the kernel bus (default: %s)\n"
-               "  -M --machine=MACHINE   Name of machine to connect to\n",
+               "  -p --bus-path=PATH     Path to the bus address (default: %s)\n"
+               "     --system            Connect to system bus\n"
+               "     --user              Connect to user bus\n"
+               "  -M --machine=CONTAINER Name of local container to connect to\n",
                program_invocation_short_name, DEFAULT_BUS_PATH);
 
         return 0;
@@ -42,12 +45,16 @@ static int parse_argv(int argc, char *argv[]) {
         enum {
                 ARG_VERSION = 0x100,
                 ARG_MACHINE,
+                ARG_USER,
+                ARG_SYSTEM,
         };
 
         static const struct option options[] = {
                 { "help",            no_argument,       NULL, 'h'         },
                 { "version",         no_argument,       NULL, ARG_VERSION },
                 { "bus-path",        required_argument, NULL, 'p'         },
+                { "user",            no_argument,       NULL, ARG_USER    },
+                { "system",          no_argument,       NULL, ARG_SYSTEM  },
                 { "machine",         required_argument, NULL, 'M'         },
                 {},
         };
@@ -67,6 +74,14 @@ static int parse_argv(int argc, char *argv[]) {
                 case ARG_VERSION:
                         return version();
 
+                case ARG_USER:
+                        arg_user = true;
+                        break;
+
+                case ARG_SYSTEM:
+                        arg_user = false;
+                        break;
+
                 case 'p':
                         arg_bus_path = optarg;
                         break;
@@ -121,7 +136,7 @@ static int run(int argc, char *argv[]) {
                 return log_error_errno(r, "Failed to allocate bus: %m");
 
         if (arg_transport == BUS_TRANSPORT_MACHINE)
-                r = bus_set_address_machine(a, false, arg_bus_path);
+                r = bus_set_address_machine(a, arg_user, arg_bus_path);
         else
                 r = sd_bus_set_address(a, arg_bus_path);
         if (r < 0)