summaryrefslogtreecommitdiffstats
path: root/tools/dbus-send.c
diff options
context:
space:
mode:
authorHavoc Pennington <hp@redhat.com>2003-05-16 20:09:25 +0000
committerHavoc Pennington <hp@redhat.com>2003-05-16 20:09:25 +0000
commit306eab3e3d998472ad111146a12b7697ea96c9b9 (patch)
tree613b5918113060fb66b7122307d8a6d2c2c2344f /tools/dbus-send.c
parentce53bbd7af4488b8374aeccc2e80fb2f7eff0683 (diff)
2003-05-16 Havoc Pennington <hp@redhat.com>
* dbus/dbus-connection.c: disable verbose lock spew * tools/dbus-send.c: add --print-reply command line option * tools/dbus-print-message.h (print_message): new util function shared by dbus-send and dbus-monitor * tools/dbus-monitor.c (handler_func): exit on disconnect * dbus/dbus-transport-unix.c (do_reading): if the transport is disconnected, don't try to use the read_watch * dbus/dbus-watch.c (dbus_watch_get_enabled): assert watch != NULL so we can find this bug more easily
Diffstat (limited to 'tools/dbus-send.c')
-rw-r--r--tools/dbus-send.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/tools/dbus-send.c b/tools/dbus-send.c
index a105f8b4..ea00a836 100644
--- a/tools/dbus-send.c
+++ b/tools/dbus-send.c
@@ -25,10 +25,12 @@
#include <dbus/dbus.h>
+#include "dbus-print-message.h"
+
static void
usage (char *name)
{
- fprintf (stderr, "Usage: %s [--session] [--dest=SERVICE] <message type> [contents ...]\n", name);
+ fprintf (stderr, "Usage: %s [--session] [--dest=SERVICE] [--print-reply] <message type> [contents ...]\n", name);
exit (1);
}
@@ -38,6 +40,7 @@ main (int argc, char *argv[])
DBusConnection *connection;
DBusError error;
DBusMessage *message;
+ int print_reply;
DBusMessageIter iter;
int i;
DBusBusType type = DBUS_BUS_SYSTEM;
@@ -47,12 +50,16 @@ main (int argc, char *argv[])
if (argc < 2)
usage (argv[0]);
+ print_reply = FALSE;
+
for (i = 1; i < argc && name == NULL; i++)
{
char *arg = argv[i];
- if (!strcmp (arg, "--session"))
+ if (strcmp (arg, "--session") == 0)
type = DBUS_BUS_SESSION;
+ else if (strcmp (arg, "--print-reply") == 0)
+ print_reply = TRUE;
else if (strstr (arg, "--dest=") == arg)
dest = strchr (arg, '=') + 1;
else if (arg[0] == '-')
@@ -156,9 +163,32 @@ main (int argc, char *argv[])
}
}
- dbus_connection_send (connection, message, NULL);
-
- dbus_connection_flush (connection);
+ if (print_reply)
+ {
+ DBusMessage *reply;
+
+ dbus_error_init (&error);
+ reply = dbus_connection_send_with_reply_and_block (connection,
+ message, -1,
+ &error);
+ if (dbus_error_is_set (&error))
+ {
+ fprintf (stderr, "Error: %s\n",
+ error.message);
+ exit (1);
+ }
+
+ if (reply)
+ {
+ print_message (reply);
+ dbus_message_unref (reply);
+ }
+ }
+ else
+ {
+ dbus_connection_send (connection, message, NULL);
+ dbus_connection_flush (connection);
+ }
dbus_message_unref (message);