summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorSimon McVittie <smcv@debian.org>2015-02-19 13:35:29 +0000
committerSimon McVittie <smcv@debian.org>2015-02-19 13:35:29 +0000
commit5a676818770d64c5508f5cf28e22228f68b325aa (patch)
treeacfbf8e52304dce6a8450ad3c390cdf874a6fd3e /tools
parent8fd2c8098849695fce037fa3731a916ac5354e91 (diff)
parent87fe648a5c883d1f790a5d40abfd4a68aff0784c (diff)
downloaddbus-upstream/1.9.12.tar.gz
Imported Upstream version 1.9.12upstream/1.9.12
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile.am5
-rw-r--r--tools/Makefile.in11
-rw-r--r--tools/dbus-monitor.c111
-rw-r--r--tools/dbus-print-message.c60
4 files changed, 105 insertions, 82 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 294bbc63..80025b82 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -29,7 +29,10 @@ endif
dbus_send_SOURCES= \
dbus-print-message.c \
dbus-print-message.h \
- dbus-send.c
+ dbus-send.c \
+ tool-common.c \
+ tool-common.h \
+ $(NULL)
dbus_monitor_SOURCES = \
dbus-monitor.c \
diff --git a/tools/Makefile.in b/tools/Makefile.in
index 2d8a1ea6..054d17a1 100644
--- a/tools/Makefile.in
+++ b/tools/Makefile.in
@@ -136,7 +136,7 @@ dbus_run_session_OBJECTS = $(am_dbus_run_session_OBJECTS)
@DBUS_WIN_FALSE@dbus_run_session_DEPENDENCIES = \
@DBUS_WIN_FALSE@ $(top_builddir)/dbus/libdbus-1.la
am_dbus_send_OBJECTS = dbus-print-message.$(OBJEXT) \
- dbus-send.$(OBJEXT)
+ dbus-send.$(OBJEXT) tool-common.$(OBJEXT)
dbus_send_OBJECTS = $(am_dbus_send_OBJECTS)
dbus_send_DEPENDENCIES = $(top_builddir)/dbus/libdbus-1.la
am_dbus_test_tool_OBJECTS = dbus-echo.$(OBJEXT) dbus-spam.$(OBJEXT) \
@@ -245,6 +245,8 @@ ACLOCAL = @ACLOCAL@
ADT_LIBS = @ADT_LIBS@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
+APPARMOR_CFLAGS = @APPARMOR_CFLAGS@
+APPARMOR_LIBS = @APPARMOR_LIBS@
AR = @AR@
AUTOCONF = @AUTOCONF@
AUTOHEADER = @AUTOHEADER@
@@ -299,6 +301,7 @@ DEPDIR = @DEPDIR@
DLLTOOL = @DLLTOOL@
DOXYGEN = @DOXYGEN@
DSYMUTIL = @DSYMUTIL@
+DUCKTYPE = @DUCKTYPE@
DUMPBIN = @DUMPBIN@
ECHO_C = @ECHO_C@
ECHO_N = @ECHO_N@
@@ -388,6 +391,7 @@ X_CFLAGS = @X_CFLAGS@
X_EXTRA_LIBS = @X_EXTRA_LIBS@
X_LIBS = @X_LIBS@
X_PRE_LIBS = @X_PRE_LIBS@
+YELP_BUILD = @YELP_BUILD@
abs_builddir = @abs_builddir@
abs_srcdir = @abs_srcdir@
abs_top_builddir = @abs_top_builddir@
@@ -462,7 +466,10 @@ AM_LDFLAGS = @R_DYNAMIC_LDFLAG@
dbus_send_SOURCES = \
dbus-print-message.c \
dbus-print-message.h \
- dbus-send.c
+ dbus-send.c \
+ tool-common.c \
+ tool-common.h \
+ $(NULL)
dbus_monitor_SOURCES = \
dbus-monitor.c \
diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c
index ad776904..14ceae90 100644
--- a/tools/dbus-monitor.c
+++ b/tools/dbus-monitor.c
@@ -74,7 +74,7 @@ GetSystemTimeAsFileTime (LPFILETIME ftp)
static int
gettimeofday (struct timeval *__p,
- void *__t)
+ void *__t)
{
union {
unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */
@@ -91,8 +91,8 @@ gettimeofday (struct timeval *__p,
static DBusHandlerResult
monitor_filter_func (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
+ DBusMessage *message,
+ void *user_data)
{
print_message (message, FALSE);
@@ -107,14 +107,6 @@ monitor_filter_func (DBusConnection *connection,
return DBUS_HANDLER_RESULT_HANDLED;
}
-#ifdef __APPLE__
-#define PROFILE_TIMED_FORMAT "%s\t%lu\t%d"
-#elif defined(__NetBSD__)
-#include <inttypes.h>
-#define PROFILE_TIMED_FORMAT "%s\t%" PRId64 "\t%d"
-#else
-#define PROFILE_TIMED_FORMAT "%s\t%lu\t%lu"
-#endif
#define TRAP_NULL_STRING(str) ((str) ? (str) : "<none>")
typedef enum
@@ -130,23 +122,30 @@ typedef enum
} ProfileAttributeFlags;
static void
+profile_print_headers (void)
+{
+ printf ("#type\ttimestamp\tserial\tsender\tdestination\tpath\tinterface\tmember\n");
+ printf ("#\t\t\t\t\tin_reply_to\n");
+}
+
+static void
profile_print_with_attrs (const char *type, DBusMessage *message,
struct timeval *t, ProfileAttributeFlags attrs)
{
- printf (PROFILE_TIMED_FORMAT, type, t->tv_sec, t->tv_usec);
+ printf ("%s\t%lu.%06lu", type, (unsigned long) t->tv_sec, (unsigned long) t->tv_usec);
if (attrs & PROFILE_ATTRIBUTE_FLAG_SERIAL)
printf ("\t%u", dbus_message_get_serial (message));
- if (attrs & PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL)
- printf ("\t%u", dbus_message_get_reply_serial (message));
-
if (attrs & PROFILE_ATTRIBUTE_FLAG_SENDER)
printf ("\t%s", TRAP_NULL_STRING (dbus_message_get_sender (message)));
if (attrs & PROFILE_ATTRIBUTE_FLAG_DESTINATION)
printf ("\t%s", TRAP_NULL_STRING (dbus_message_get_destination (message)));
+ if (attrs & PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL)
+ printf ("\t%u", dbus_message_get_reply_serial (message));
+
if (attrs & PROFILE_ATTRIBUTE_FLAG_PATH)
printf ("\t%s", TRAP_NULL_STRING (dbus_message_get_path (message)));
@@ -165,6 +164,7 @@ profile_print_with_attrs (const char *type, DBusMessage *message,
static void
print_message_profile (DBusMessage *message)
{
+ static dbus_bool_t first = TRUE;
struct timeval t;
if (gettimeofday (&t, NULL) < 0)
@@ -173,45 +173,56 @@ print_message_profile (DBusMessage *message)
return;
}
+ if (first)
+ {
+ profile_print_headers ();
+ first = FALSE;
+ }
+
switch (dbus_message_get_type (message))
{
case DBUS_MESSAGE_TYPE_METHOD_CALL:
- profile_print_with_attrs ("mc", message, &t,
- PROFILE_ATTRIBUTE_FLAG_SERIAL |
- PROFILE_ATTRIBUTE_FLAG_SENDER |
- PROFILE_ATTRIBUTE_FLAG_PATH |
- PROFILE_ATTRIBUTE_FLAG_INTERFACE |
- PROFILE_ATTRIBUTE_FLAG_MEMBER);
- break;
+ profile_print_with_attrs ("mc", message, &t,
+ PROFILE_ATTRIBUTE_FLAG_SERIAL |
+ PROFILE_ATTRIBUTE_FLAG_SENDER |
+ PROFILE_ATTRIBUTE_FLAG_DESTINATION |
+ PROFILE_ATTRIBUTE_FLAG_PATH |
+ PROFILE_ATTRIBUTE_FLAG_INTERFACE |
+ PROFILE_ATTRIBUTE_FLAG_MEMBER);
+ break;
case DBUS_MESSAGE_TYPE_METHOD_RETURN:
- profile_print_with_attrs ("mr", message, &t,
- PROFILE_ATTRIBUTE_FLAG_SERIAL |
- PROFILE_ATTRIBUTE_FLAG_DESTINATION |
- PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL);
- break;
+ profile_print_with_attrs ("mr", message, &t,
+ PROFILE_ATTRIBUTE_FLAG_SERIAL |
+ PROFILE_ATTRIBUTE_FLAG_SENDER |
+ PROFILE_ATTRIBUTE_FLAG_DESTINATION |
+ PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL);
+ break;
case DBUS_MESSAGE_TYPE_ERROR:
- profile_print_with_attrs ("err", message, &t,
- PROFILE_ATTRIBUTE_FLAG_SERIAL |
- PROFILE_ATTRIBUTE_FLAG_DESTINATION |
- PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL);
- break;
+ profile_print_with_attrs ("err", message, &t,
+ PROFILE_ATTRIBUTE_FLAG_SERIAL |
+ PROFILE_ATTRIBUTE_FLAG_SENDER |
+ PROFILE_ATTRIBUTE_FLAG_DESTINATION |
+ PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL);
+ break;
case DBUS_MESSAGE_TYPE_SIGNAL:
- profile_print_with_attrs ("sig", message, &t,
- PROFILE_ATTRIBUTE_FLAG_SERIAL |
- PROFILE_ATTRIBUTE_FLAG_PATH |
- PROFILE_ATTRIBUTE_FLAG_INTERFACE |
- PROFILE_ATTRIBUTE_FLAG_MEMBER);
- break;
+ profile_print_with_attrs ("sig", message, &t,
+ PROFILE_ATTRIBUTE_FLAG_SERIAL |
+ PROFILE_ATTRIBUTE_FLAG_SENDER |
+ PROFILE_ATTRIBUTE_FLAG_DESTINATION |
+ PROFILE_ATTRIBUTE_FLAG_PATH |
+ PROFILE_ATTRIBUTE_FLAG_INTERFACE |
+ PROFILE_ATTRIBUTE_FLAG_MEMBER);
+ break;
default:
- printf (PROFILE_TIMED_FORMAT "\n", "tun", t.tv_sec, t.tv_usec);
- break;
+ printf ("%s\t%lu.%06lu", "tun", (unsigned long) t.tv_sec, (unsigned long) t.tv_usec);
+ break;
}
}
static DBusHandlerResult
-profile_filter_func (DBusConnection *connection,
- DBusMessage *message,
- void *user_data)
+profile_filter_func (DBusConnection *connection,
+ DBusMessage *message,
+ void *user_data)
{
print_message_profile (message);
@@ -431,7 +442,7 @@ main (int argc, char *argv[])
usage (argv[0], 1);
}
else if (!strcmp (arg, "--help"))
- usage (argv[0], 0);
+ usage (argv[0], 0);
else if (!strcmp (arg, "--monitor"))
{
filter_func = monitor_filter_func;
@@ -453,9 +464,9 @@ main (int argc, char *argv[])
binary_mode = BINARY_MODE_PCAP;
}
else if (!strcmp (arg, "--"))
- continue;
+ continue;
else if (arg[0] == '-')
- usage (argv[0], 1);
+ usage (argv[0], 1);
else {
unsigned int filter_len;
numFilters++;
@@ -483,12 +494,12 @@ main (int argc, char *argv[])
if (connection)
{
if (!dbus_bus_register (connection, &error))
- {
+ {
fprintf (stderr, "Failed to register connection to bus at %s: %s\n",
- address, error.message);
+ address, error.message);
dbus_error_free (&error);
exit (1);
- }
+ }
}
}
else
@@ -548,7 +559,7 @@ main (int argc, char *argv[])
dbus_bus_add_match (connection, filters[i] + offset, &error);
}
- if (dbus_error_is_set (&error))
+ if (dbus_error_is_set (&error))
{
fprintf (stderr, "Failed to setup match \"%s\": %s\n",
filters[i], error.message);
diff --git a/tools/dbus-print-message.c b/tools/dbus-print-message.c
index 6f02ea38..216ebaeb 100644
--- a/tools/dbus-print-message.c
+++ b/tools/dbus-print-message.c
@@ -37,6 +37,8 @@
#include <stdlib.h>
#include "config.h"
+#include "tool-common.h"
+
static const char*
type_to_name (int message_type)
{
@@ -65,7 +67,9 @@ indent (int depth)
}
static void
-print_hex (unsigned char *bytes, unsigned int len, int depth)
+print_hex (const unsigned char *bytes,
+ int len,
+ int depth)
{
unsigned int i, columns;
@@ -110,47 +114,45 @@ print_hex (unsigned char *bytes, unsigned int len, int depth)
static void
print_ay (DBusMessageIter *iter, int depth)
{
- /* Not using DBusString because it's not public API. It's 2009, and I'm
- * manually growing a string chunk by chunk.
- */
- unsigned char *bytes = malloc (DEFAULT_SIZE + 1);
- unsigned int len = 0;
- unsigned int max = DEFAULT_SIZE;
+ /* True if every byte in the bytestring (so far) is printable
+ * ASCII, with one exception: the last byte is also allowed to be \0. */
dbus_bool_t all_ascii = TRUE;
- int current_type;
-
- while ((current_type = dbus_message_iter_get_arg_type (iter))
- != DBUS_TYPE_INVALID)
- {
- unsigned char val;
-
- dbus_message_iter_get_basic (iter, &val);
- bytes[len] = val;
- len++;
+ const unsigned char *bytes;
+ int len;
+ int i;
- if (val < 32 || val > 126)
- all_ascii = FALSE;
+ dbus_message_iter_get_fixed_array (iter, &bytes, &len);
- if (len == max)
+ for (i = 0; i < len; i++)
+ {
+ if ((bytes[i] < 32 || bytes[i] > 126) &&
+ (i < len - 1 || bytes[i] != '\0'))
{
- max *= 2;
- bytes = realloc (bytes, max + 1);
+ all_ascii = FALSE;
+ break;
}
-
- dbus_message_iter_next (iter);
}
- if (all_ascii)
+ if (all_ascii && len > 0 && bytes[len - 1] == '\0')
+ {
+ printf ("array of bytes \"%s\" + \\0\n", bytes);
+ }
+ else if (all_ascii)
{
- bytes[len] = '\0';
- printf ("array of bytes \"%s\"\n", bytes);
+ unsigned char *copy = dbus_malloc (len + 1);
+
+ if (copy == NULL)
+ tool_oom ("copying bytestring");
+
+ memcpy (copy, bytes, len);
+ copy[len] = '\0';
+ printf ("array of bytes \"%s\"\n", copy);
+ dbus_free (copy);
}
else
{
print_hex (bytes, len, depth);
}
-
- free (bytes);
}
static void