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.
This commit is contained in:
parent
ba4a31b7a6
commit
cedfd142de
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
static const char *arg_bus_path = DEFAULT_BUS_PATH;
|
static const char *arg_bus_path = DEFAULT_BUS_PATH;
|
||||||
static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
|
static BusTransport arg_transport = BUS_TRANSPORT_LOCAL;
|
||||||
|
static bool arg_user = false;
|
||||||
|
|
||||||
static int help(void) {
|
static int help(void) {
|
||||||
|
|
||||||
|
@ -30,8 +31,10 @@ static int help(void) {
|
||||||
"STDIO or socket-activatable proxy to a given DBus endpoint.\n\n"
|
"STDIO or socket-activatable proxy to a given DBus endpoint.\n\n"
|
||||||
" -h --help Show this help\n"
|
" -h --help Show this help\n"
|
||||||
" --version Show package version\n"
|
" --version Show package version\n"
|
||||||
" -p --bus-path=PATH Path to the kernel bus (default: %s)\n"
|
" -p --bus-path=PATH Path to the bus address (default: %s)\n"
|
||||||
" -M --machine=MACHINE Name of machine to connect to\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);
|
program_invocation_short_name, DEFAULT_BUS_PATH);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -42,12 +45,16 @@ static int parse_argv(int argc, char *argv[]) {
|
||||||
enum {
|
enum {
|
||||||
ARG_VERSION = 0x100,
|
ARG_VERSION = 0x100,
|
||||||
ARG_MACHINE,
|
ARG_MACHINE,
|
||||||
|
ARG_USER,
|
||||||
|
ARG_SYSTEM,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct option options[] = {
|
static const struct option options[] = {
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ "version", no_argument, NULL, ARG_VERSION },
|
{ "version", no_argument, NULL, ARG_VERSION },
|
||||||
{ "bus-path", required_argument, NULL, 'p' },
|
{ "bus-path", required_argument, NULL, 'p' },
|
||||||
|
{ "user", no_argument, NULL, ARG_USER },
|
||||||
|
{ "system", no_argument, NULL, ARG_SYSTEM },
|
||||||
{ "machine", required_argument, NULL, 'M' },
|
{ "machine", required_argument, NULL, 'M' },
|
||||||
{},
|
{},
|
||||||
};
|
};
|
||||||
|
@ -67,6 +74,14 @@ static int parse_argv(int argc, char *argv[]) {
|
||||||
case ARG_VERSION:
|
case ARG_VERSION:
|
||||||
return version();
|
return version();
|
||||||
|
|
||||||
|
case ARG_USER:
|
||||||
|
arg_user = true;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ARG_SYSTEM:
|
||||||
|
arg_user = false;
|
||||||
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
arg_bus_path = optarg;
|
arg_bus_path = optarg;
|
||||||
break;
|
break;
|
||||||
|
@ -121,7 +136,7 @@ static int run(int argc, char *argv[]) {
|
||||||
return log_error_errno(r, "Failed to allocate bus: %m");
|
return log_error_errno(r, "Failed to allocate bus: %m");
|
||||||
|
|
||||||
if (arg_transport == BUS_TRANSPORT_MACHINE)
|
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
|
else
|
||||||
r = sd_bus_set_address(a, arg_bus_path);
|
r = sd_bus_set_address(a, arg_bus_path);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
|
Loading…
Reference in New Issue