From 3ac0c045e6f312d8dbc052d2bfd4d7c0b1d89cef Mon Sep 17 00:00:00 2001 From: Andrey Mazo Date: Mon, 16 Apr 2012 21:27:17 +0400 Subject: [PATCH] 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. See bug #48816 [1] for more details. [1] https://bugs.freedesktop.org/show_bug.cgi?id=48816 --- tools/dbus-send.c | 32 ++++++++++++++++++++++++++++---- 1 files changed, 28 insertions(+), 4 deletions(-) diff --git a/tools/dbus-send.c b/tools/dbus-send.c index e403a58..826255e 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] [contents ...]\n", appname); + fprintf (stderr, "Usage: %s [--help] [--system | --session | --bus=ADDRESS | --peer=ADDRESS] [--dest=NAME] [--type=TYPE] [--print-reply[=literal]] [--reply-timeout=MSEC] [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,13 +267,26 @@ 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 (arg[2] == 'b') /* bus */ + { + is_bus = TRUE; + } + else if (arg[2] == 'p') /* peer */ + { + is_bus = FALSE; + } + else /* address; keeping backwards compatibility */ + { + is_bus = FALSE; + } + address = strchr (arg, '='); if (address == NULL) { - fprintf (stderr, "\"--address=\" requires an ADDRESS\n"); + fprintf (stderr, "\"--peer=\" and \"--bus=\" require an ADDRESS\n"); usage (1); } else @@ -312,7 +326,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); } @@ -348,6 +362,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) { -- 1.7.3.4