diff options
author | Simon McVittie <smcv@debian.org> | 2013-10-09 12:22:03 +0100 |
---|---|---|
committer | Simon McVittie <smcv@debian.org> | 2013-10-09 12:22:03 +0100 |
commit | 46d1ea6379112b52d81efa0eb264321a0471c808 (patch) | |
tree | 080addcb860d6b9344f9435de45e727556bbd5aa /tools | |
parent | 20c1496fee4c06a5f268585ba67bd3a6f105fa78 (diff) | |
parent | 9e4f0bf0e114c37e30acd78ade61d2f6e92c625f (diff) | |
download | dbus-46d1ea6379112b52d81efa0eb264321a0471c808.tar.gz |
Imported Upstream version 1.7.6upstream/1.7.6
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile.am | 4 | ||||
-rw-r--r-- | tools/Makefile.in | 15 | ||||
-rw-r--r-- | tools/dbus-launch-win.c | 4 | ||||
-rw-r--r-- | tools/dbus-launch.c | 125 | ||||
-rw-r--r-- | tools/dbus-monitor.c | 51 | ||||
-rw-r--r-- | tools/dbus-run-session.c | 31 | ||||
-rw-r--r-- | tools/dbus-send.c | 39 | ||||
-rwxr-xr-x | tools/run-with-tmp-session-bus.sh | 11 |
8 files changed, 179 insertions, 101 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index 464a8050..73d95fcf 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -47,6 +47,10 @@ dbus_launch_SOURCES= \ dbus_run_session_SOURCES = \ dbus-run-session.c + +dbus_run_session_LDADD = \ + $(top_builddir)/dbus/libdbus-1.la \ + $(NULL) endif dbus_cleanup_sockets_SOURCES= \ diff --git a/tools/Makefile.in b/tools/Makefile.in index a166a49c..2c220696 100644 --- a/tools/Makefile.in +++ b/tools/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated by automake 1.13.3 from Makefile.am. +# Makefile.in generated by automake 1.14 from Makefile.am. # @configure_input@ # Copyright (C) 1994-2013 Free Software Foundation, Inc. @@ -132,7 +132,8 @@ am__dbus_run_session_SOURCES_DIST = dbus-run-session.c @DBUS_WIN_FALSE@am_dbus_run_session_OBJECTS = \ @DBUS_WIN_FALSE@ dbus-run-session.$(OBJEXT) dbus_run_session_OBJECTS = $(am_dbus_run_session_OBJECTS) -dbus_run_session_LDADD = $(LDADD) +@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_OBJECTS = $(am_dbus_send_OBJECTS) @@ -234,7 +235,6 @@ DBUS_DAEMONDIR = @DBUS_DAEMONDIR@ DBUS_DATADIR = @DBUS_DATADIR@ DBUS_GLIB_CFLAGS = @DBUS_GLIB_CFLAGS@ DBUS_GLIB_LIBS = @DBUS_GLIB_LIBS@ -DBUS_HAVE_INT64 = @DBUS_HAVE_INT64@ DBUS_INT16_TYPE = @DBUS_INT16_TYPE@ DBUS_INT32_TYPE = @DBUS_INT32_TYPE@ DBUS_INT64_CONSTANT = @DBUS_INT64_CONSTANT@ @@ -337,7 +337,6 @@ SHELL = @SHELL@ STRIP = @STRIP@ SYSTEMD_CFLAGS = @SYSTEMD_CFLAGS@ SYSTEMD_LIBS = @SYSTEMD_LIBS@ -TEST_BUS_BINARY = @TEST_BUS_BINARY@ TEST_LAUNCH_HELPER_BINARY = @TEST_LAUNCH_HELPER_BINARY@ TEST_LISTEN = @TEST_LISTEN@ TEST_SOCKET_DIR = @TEST_SOCKET_DIR@ @@ -447,6 +446,10 @@ dbus_monitor_SOURCES = \ @DBUS_WIN_FALSE@dbus_run_session_SOURCES = \ @DBUS_WIN_FALSE@ dbus-run-session.c +@DBUS_WIN_FALSE@dbus_run_session_LDADD = \ +@DBUS_WIN_FALSE@ $(top_builddir)/dbus/libdbus-1.la \ +@DBUS_WIN_FALSE@ $(NULL) + dbus_cleanup_sockets_SOURCES = \ dbus-cleanup-sockets.c @@ -603,14 +606,14 @@ distclean-compile: @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c $< +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< .c.obj: @am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c `$(CYGPATH_W) '$<'` +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` .c.lo: @am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< diff --git a/tools/dbus-launch-win.c b/tools/dbus-launch-win.c index 215fac3f..d899010a 100644 --- a/tools/dbus-launch-win.c +++ b/tools/dbus-launch-win.c @@ -159,8 +159,8 @@ main (int argc, char **argv) if (result == 0) { if (verbose) - fprintf (stderr, "Could not start " DBUS_DAEMON_NAME ". error=%d\n", - GetLastError ()); + fprintf (stderr, "Could not start " DBUS_DAEMON_NAME ". error=%u\n", + (unsigned)GetLastError ()); return 4; } diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c index b2ffe41d..7ecee63e 100644 --- a/tools/dbus-launch.c +++ b/tools/dbus-launch.c @@ -105,6 +105,7 @@ save_machine_uuid (const char *uuid_arg) machine_uuid = xstrdup (uuid_arg); } +#ifdef DBUS_BUILD_X11 #define UUID_MAXLEN 40 /* Read the machine uuid from file if needed. Returns TRUE if machine_uuid is * set after this function */ @@ -131,7 +132,7 @@ read_machine_uuid_if_needed (void) goto out; /* rstrip the read uuid */ - while (len > 31 && isspace(uuid[len - 1])) + while (len > 31 && isspace((int) uuid[len - 1])) len--; if (len != 32) @@ -146,12 +147,13 @@ out: fclose(f); return ret; } - +#endif /* DBUS_BUILD_X11 */ void verbose (const char *format, ...) { +#ifdef DBUS_ENABLE_VERBOSE_MODE va_list args; static int verbose = TRUE; static int verbose_initted = FALSE; @@ -176,12 +178,16 @@ verbose (const char *format, va_start (args, format); vfprintf (stderr, format, args); va_end (args); +#endif /* DBUS_ENABLE_VERBOSE_MODE */ } static void usage (int ecode) { - fprintf (stderr, "dbus-launch [--version] [--help] [--sh-syntax] [--csh-syntax] [--auto-syntax] [--exit-with-session]\n"); + fprintf (stderr, "dbus-launch [--version] [--help] [--sh-syntax]" + " [--csh-syntax] [--auto-syntax] [--binary-syntax] [--close-stderr]" + " [--exit-with-session] [--autolaunch=MACHINEID]" + " [--config-file=FILENAME] [PROGRAM] [ARGS...]\n"); exit (ecode); } @@ -216,6 +222,26 @@ xstrdup (const char *str) return copy; } +static char * +concat2 (const char *a, + const char *b) +{ + size_t la, lb; + char *ret; + + la = strlen (a); + lb = strlen (b); + + ret = malloc (la + lb + 1); + + if (ret == NULL) + return NULL; + + memcpy (ret, a, la); + memcpy (ret + la, b, lb + 1); + return ret; +} + typedef enum { READ_STATUS_OK, /**< Read succeeded */ @@ -445,9 +471,7 @@ signal_handler (int sig) { switch (sig) { -#ifdef SIGHUP case SIGHUP: -#endif case SIGINT: case SIGTERM: got_sighup = TRUE; @@ -755,31 +779,35 @@ pass_info (const char *runprog, const char *bus_address, pid_t bus_pid, if (envvar == NULL || args == NULL) goto oom; - args[0] = xstrdup (runprog); + args[0] = xstrdup (runprog); if (!args[0]) goto oom; - for (i = 1; i <= (argc-remaining_args); i++) - { - size_t len = strlen (argv[remaining_args+i-1])+1; - args[i] = malloc (len); - if (!args[i]) - goto oom; - strncpy (args[i], argv[remaining_args+i-1], len); - } - args[i] = NULL; + for (i = 1; i <= (argc-remaining_args); i++) + { + size_t len = strlen (argv[remaining_args+i-1])+1; + args[i] = malloc (len); + if (!args[i]) + { + while (i > 1) + free (args[--i]); + goto oom; + } + strncpy (args[i], argv[remaining_args+i-1], len); + } + args[i] = NULL; - strcpy (envvar, "DBUS_SESSION_BUS_ADDRESS="); - strcat (envvar, bus_address); - putenv (envvar); + strcpy (envvar, "DBUS_SESSION_BUS_ADDRESS="); + strcat (envvar, bus_address); + putenv (envvar); - execvp (runprog, args); - fprintf (stderr, "Couldn't exec %s: %s\n", runprog, strerror (errno)); - exit (1); + execvp (runprog, args); + fprintf (stderr, "Couldn't exec %s: %s\n", runprog, strerror (errno)); + exit (1); } else { print_variables (bus_address, bus_pid, bus_wid, c_shell_syntax, - bourne_shell_syntax, binary_syntax); + bourne_shell_syntax, binary_syntax); } verbose ("dbus-launch exiting\n"); @@ -1100,24 +1128,41 @@ main (int argc, char **argv) verbose ("Calling exec()\n"); -#ifdef DBUS_BUILD_TESTS - /* exec from testdir */ - if (getenv("DBUS_USE_TEST_BINARY") != NULL) - { - execl (TEST_BUS_BINARY, - TEST_BUS_BINARY, - "--fork", - "--print-pid", write_pid_fd_as_string, - "--print-address", write_address_fd_as_string, - config_file ? "--config-file" : "--session", - config_file, /* has to be last in this varargs list */ - NULL); - - fprintf (stderr, - "Failed to execute test message bus daemon %s: %s. Will try again with the system path.\n", - TEST_BUS_BINARY, strerror (errno)); - } - #endif /* DBUS_BUILD_TESTS */ +#ifdef DBUS_ENABLE_EMBEDDED_TESTS + { + const char *test_daemon; + /* exec from testdir */ + if (getenv ("DBUS_USE_TEST_BINARY") != NULL && + (test_daemon = getenv ("DBUS_TEST_DAEMON")) != NULL) + { + if (config_file == NULL && getenv ("DBUS_TEST_DATA") != NULL) + { + config_file = concat2 (getenv ("DBUS_TEST_DATA"), + "/valid-config-files/session.conf"); + + if (config_file == NULL) + { + fprintf (stderr, "Out of memory\n"); + exit (1); + } + } + + execl (test_daemon, + test_daemon, + "--fork", + "--print-pid", write_pid_fd_as_string, + "--print-address", write_address_fd_as_string, + config_file ? "--config-file" : "--session", + config_file, /* has to be last in this varargs list */ + NULL); + + fprintf (stderr, + "Failed to execute test message bus daemon %s: %s.\n", + test_daemon, strerror (errno)); + exit (1); + } + } + #endif /* DBUS_ENABLE_EMBEDDED_TESTS */ execl (DBUS_DAEMONDIR"/dbus-daemon", DBUS_DAEMONDIR"/dbus-daemon", diff --git a/tools/dbus-monitor.c b/tools/dbus-monitor.c index a4b54782..ff8390d7 100644 --- a/tools/dbus-monitor.c +++ b/tools/dbus-monitor.c @@ -106,6 +106,9 @@ monitor_filter_func (DBusConnection *connection, #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 @@ -310,7 +313,7 @@ main (int argc, char *argv[]) filters = (char **) realloc (filters, numFilters * sizeof (char *)); if (filters == NULL) oom ("adding a new filter slot"); - filters[j] = (char *) malloc (filter_len * sizeof (char *)); + filters[j] = (char *) malloc (filter_len); if (filters[j] == NULL) oom ("adding a new filter"); snprintf (filters[j], filter_len, "%s,%s", EAVESDROPPING_RULE, arg); @@ -364,41 +367,45 @@ main (int argc, char *argv[]) if (numFilters) { + size_t offset = 0; for (i = 0; i < j; i++) { - dbus_bus_add_match (connection, filters[i], &error); - if (dbus_error_is_set (&error)) + dbus_bus_add_match (connection, filters[i] + offset, &error); + if (dbus_error_is_set (&error) && i == 0 && offset == 0) + { + /* We might be talking to a pre-1.5.6 dbus-daemon + * which wouldn't understand eavesdrop=true. + * If this works, carry on with offset > 0 + * on the remaining iterations. */ + offset = strlen (EAVESDROPPING_RULE) + 1; + dbus_error_free (&error); + dbus_bus_add_match (connection, filters[i] + offset, &error); + } + + if (dbus_error_is_set (&error)) { fprintf (stderr, "Failed to setup match \"%s\": %s\n", filters[i], error.message); dbus_error_free (&error); exit (1); } - free(filters[i]); + free(filters[i]); } } else { dbus_bus_add_match (connection, - EAVESDROPPING_RULE ",type='signal'", - &error); - if (dbus_error_is_set (&error)) - goto lose; - dbus_bus_add_match (connection, - EAVESDROPPING_RULE ",type='method_call'", - &error); + EAVESDROPPING_RULE, + &error); if (dbus_error_is_set (&error)) - goto lose; - dbus_bus_add_match (connection, - EAVESDROPPING_RULE ",type='method_return'", - &error); - if (dbus_error_is_set (&error)) - goto lose; - dbus_bus_add_match (connection, - EAVESDROPPING_RULE ",type='error'", - &error); - if (dbus_error_is_set (&error)) - goto lose; + { + dbus_error_free (&error); + dbus_bus_add_match (connection, + "", + &error); + if (dbus_error_is_set (&error)) + goto lose; + } } if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL)) { diff --git a/tools/dbus-run-session.c b/tools/dbus-run-session.c index 4f0b32b5..105ab3b4 100644 --- a/tools/dbus-run-session.c +++ b/tools/dbus-run-session.c @@ -34,6 +34,9 @@ #include <sys/types.h> #include <sys/wait.h> +#include <signal.h> + +#include "dbus/dbus.h" #define MAX_ADDR_LEN 512 #define PIPE_READ_END 0 @@ -99,22 +102,6 @@ oom (void) exit (1); } -static void * -xmalloc (size_t bytes) -{ - void *ret; - - if (bytes == 0) - bytes = 1; - - ret = malloc (bytes); - - if (ret == NULL) - oom (); - - return ret; -} - typedef enum { READ_STATUS_OK, /**< Read succeeded */ @@ -227,7 +214,6 @@ main (int argc, char **argv) int requires_arg = 0; pid_t bus_pid; pid_t app_pid; - char *envvar; while (i < argc) { @@ -396,11 +382,12 @@ main (int argc, char **argv) close (bus_address_pipe[PIPE_READ_END]); - envvar = xmalloc (strlen ("DBUS_SESSION_BUS_ADDRESS=") + - strlen (bus_address) + 1); - strcpy (envvar, "DBUS_SESSION_BUS_ADDRESS="); - strcat (envvar, bus_address); - putenv (envvar); + if (!dbus_setenv ("DBUS_SESSION_BUS_ADDRESS", bus_address) || + !dbus_setenv ("DBUS_SESSION_BUS_PID", NULL) || + !dbus_setenv ("DBUS_SESSION_BUS_WINDOWID", NULL) || + !dbus_setenv ("DBUS_STARTER_ADDRESS", NULL) || + !dbus_setenv ("DBUS_STARTER_BUS_TYPE", NULL)) + oom (); app_pid = fork (); diff --git a/tools/dbus-send.c b/tools/dbus-send.c index ca5dd5c6..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); } @@ -348,7 +363,7 @@ main (int argc, char *argv[]) dbus_error_init (&error); - if (!dbus_validate_bus_name (dest, &error)) + if (dest && !dbus_validate_bus_name (dest, &error)) { fprintf (stderr, "invalid value (%s) of \"--dest\"\n", dest); 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) { diff --git a/tools/run-with-tmp-session-bus.sh b/tools/run-with-tmp-session-bus.sh index 3245652e..94ae8fc8 100755 --- a/tools/run-with-tmp-session-bus.sh +++ b/tools/run-with-tmp-session-bus.sh @@ -4,9 +4,12 @@ SCRIPTNAME="$0" WRAPPED_SCRIPT="$1" shift +CONFIG_FILE=./tmp-session-bus.$$.conf + die () { echo "$SCRIPTNAME: $*" >&2 + rm -f "$CONFIG_FILE" exit 1 } @@ -14,7 +17,6 @@ if test -z "$DBUS_TOP_BUILDDIR" ; then die "Must set DBUS_TOP_BUILDDIR" fi -CONFIG_FILE=./run-with-tmp-session-bus.conf SERVICE_DIR="$DBUS_TOP_BUILDDIR/test/data/valid-service-files" ESCAPED_SERVICE_DIR=`echo $SERVICE_DIR | sed -e 's/\//\\\\\\//g'` echo "escaped service dir is: $ESCAPED_SERVICE_DIR" >&2 @@ -48,8 +50,13 @@ unset DBUS_SESSION_BUS_PID DBUS_USE_TEST_BINARY=1 export DBUS_USE_TEST_BINARY -exec $DBUS_TOP_BUILDDIR/tools/dbus-run-session \ +$DBUS_TOP_BUILDDIR/tools/dbus-run-session \ --config-file="$CONFIG_FILE" \ --dbus-daemon="$DBUS_TOP_BUILDDIR/bus/dbus-daemon" \ -- \ "$WRAPPED_SCRIPT" "$@" +error=$? + +# clean up +rm -f "$CONFIG_FILE" +exit $error |