diff options
author | Andrey Mazo <ahippo@yandex.ru> | 2013-10-08 15:54:11 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2013-10-09 11:18:20 +0100 |
commit | b994830c7f6e201e8e8c3e6d8eaeb67191b9338a (patch) | |
tree | c73a6fe443378ad6f7fa8626bb27509a411ba383 | |
parent | 39673b945ca809d24797d237d1e2abc6f59ebe77 (diff) | |
download | dbus-b994830c7f6e201e8e8c3e6d8eaeb67191b9338a.tar.gz |
dbus-send: replace --address with --peer and --bus.
--peer is a direct substitute for --address.
With --bus dbus-send registers on bus given by ADDRESS, thus allowing
messages to be sent to the bus.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=48816
[adjusted to apply to current master -smcv]
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
-rw-r--r-- | tools/dbus-send.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/tools/dbus-send.c b/tools/dbus-send.c index 2e37b089..d3ff2589 100644 --- a/tools/dbus-send.c +++ b/tools/dbus-send.c @@ -51,7 +51,7 @@ static const char *appname; static void usage (int ecode) { - fprintf (stderr, "Usage: %s [--help] [--system | --session | --address=ADDRESS] [--dest=NAME] [--type=TYPE] [--print-reply[=literal]] [--reply-timeout=MSEC] <destination object path> <message name> [contents ...]\n", appname); + fprintf (stderr, "Usage: %s [--help] [--system | --session | --bus=ADDRESS | --peer=ADDRESS] [--dest=NAME] [--type=TYPE] [--print-reply[=literal]] [--reply-timeout=MSEC] <destination object path> <message name> [contents ...]\n", appname); exit (ecode); } @@ -241,6 +241,7 @@ main (int argc, char *argv[]) int message_type = DBUS_MESSAGE_TYPE_SIGNAL; const char *type_str = NULL; const char *address = NULL; + int is_bus = FALSE; int session_or_system = FALSE; appname = argv[0]; @@ -266,14 +267,28 @@ main (int argc, char *argv[]) type = DBUS_BUS_SESSION; session_or_system = TRUE; } - else if (strstr (arg, "--address=") == arg) + else if ((strstr (arg, "--bus=") == arg) || (strstr (arg, "--peer=") == arg) || (strstr (arg, "--address=") == arg)) { - if (*(strchr (arg, '=') + 1) == '\0') + if (arg[2] == 'b') /* bus */ { - fprintf (stderr, "\"--address=\" requires an ADDRESS\n"); - usage (1); + is_bus = TRUE; + } + else if (arg[2] == 'p') /* peer */ + { + is_bus = FALSE; + } + else /* address; keeping backwards compatibility */ + { + is_bus = FALSE; } + address = strchr (arg, '=') + 1; + + if (address[0] == '\0') + { + fprintf (stderr, "\"--peer=\" and \"--bus=\" require an ADDRESS\n"); + usage (1); + } } else if (strncmp (arg, "--print-reply", 13) == 0) { @@ -330,7 +345,7 @@ main (int argc, char *argv[]) if (session_or_system && (address != NULL)) { - fprintf (stderr, "\"--address\" may not be used with \"--system\" or \"--session\"\n"); + fprintf (stderr, "\"--peer\" and \"--bus\" may not be used with \"--system\" or \"--session\"\n"); usage (1); } @@ -372,6 +387,16 @@ main (int argc, char *argv[]) dbus_error_free (&error); exit (1); } + else if ((address != NULL) && is_bus) + { + if (!dbus_bus_register (connection, &error)) + { + fprintf (stderr, "Failed to register on connection to \"%s\" message bus: %s\n", + address, error.message); + dbus_error_free (&error); + exit (1); + } + } if (message_type == DBUS_MESSAGE_TYPE_METHOD_CALL) { |