From 21a18cc2504bce3bccbf1eb84cedfdb8f370dc9c Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 18 Mar 2009 18:26:58 -0400 Subject: [PATCH] Bug 896 - Have dbus-send always wait until message is processed For method calls, we simply wait for the reply, even if we don't print it. For signals, we send an org.freedesktop.DBus.Peer.Ping message to the destination. Note as a side effect of this, the dbus-send exit code will now be nonzero if the remote side replies with an error, even if it's not printed. This is a desirable change, but could in theory break a script. I am of the opinion the script is buggy. --- tools/dbus-send.c | 29 +++++++++++++++++++++++++---- 1 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tools/dbus-send.c b/tools/dbus-send.c index 81a9c37..8151a8a 100644 --- a/tools/dbus-send.c +++ b/tools/dbus-send.c @@ -211,6 +211,8 @@ main (int argc, char *argv[]) DBusConnection *connection; DBusError error; DBusMessage *message; + int block_for_reply; + int closing_ping; int print_reply; int print_reply_literal; int reply_timeout; @@ -490,7 +492,7 @@ main (int argc, char *argv[]) } } - if (print_reply) + if (message_type == DBUS_MESSAGE_TYPE_METHOD_CALL) { DBusMessage *reply; @@ -508,18 +510,37 @@ main (int argc, char *argv[]) if (reply) { - print_message (reply, print_reply_literal); + if (print_reply) + print_message (reply, print_reply_literal); dbus_message_unref (reply); } } - else + else if (message_type == DBUS_MESSAGE_TYPE_SIGNAL) { + DBusMessage *ping_reply; dbus_connection_send (connection, message, NULL); - dbus_connection_flush (connection); + + dbus_message_unref (message); + + /* We round-trip a ping message to ensure that the signal has been processed. + * See https://bugs.freedesktop.org/show_bug.cgi?id=896 + * http://lists.freedesktop.org/archives/dbus/2008-March/009526.html + */ + message = dbus_message_new_method_call (dest, path, DBUS_INTERFACE_PEER, "Ping"); + + dbus_error_init (&error); + ping_reply = dbus_connection_send_with_reply_and_block (connection, + message, reply_timeout, + &error); + if (ping_reply) + dbus_message_unref (ping_reply); } + else + abort (); dbus_message_unref (message); + dbus_connection_flush (connection); dbus_connection_unref (connection); exit (0); -- 1.6.0.6