summaryrefslogtreecommitdiff
path: root/src/stdio-bridge
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-12-14 13:23:31 +0100
committerLennart Poettering <lennart@poettering.net>2020-12-15 18:01:20 +0100
commitcedfd142dea105b37223ad24d784494bfae83dc5 (patch)
treeba6794acfc4da11f486fb87c1bf40d6b14a170b5 /src/stdio-bridge
parentba4a31b7a61cc730b7cbc10948d4f1d6d78d93c7 (diff)
downloadsystemd-cedfd142dea105b37223ad24d784494bfae83dc5.tar.gz
stdio-bridge: add support for --system and --user
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.
Diffstat (limited to 'src/stdio-bridge')
-rw-r--r--src/stdio-bridge/stdio-bridge.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/stdio-bridge/stdio-bridge.c b/src/stdio-bridge/stdio-bridge.c
index 1b7c3feaea..5d8b514874 100644
--- a/src/stdio-bridge/stdio-bridge.c
+++ b/src/stdio-bridge/stdio-bridge.c
@@ -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)