DBus daemon: unix:abstract=/tmp/dbus-0VtToFD3ii,guid=e808a39ebca09ce3d68fed7f5c3d0865
cat1: Started with PID: 30887
cat2: Started with PID: 30903
cat1: /*
cat1: Copyright 2010 Canonical Ltd.
cat1: 
cat1: Authors:
cat1:     Ted Gould <ted@canonical.com>
cat1: 
cat1: This program is free software: you can redistribute it and/or modify it 
cat1: under the terms of the GNU General Public License version 3, as published 
cat1: by the Free Software Foundation.
cat1: 
cat1: This program is distributed in the hope that it will be useful, but 
cat1: WITHOUT ANY WARRANTY; without even the implied warranties of 
cat1: MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
cat1: PURPOSE.  See the GNU General Public License for more details.
cat1: 
cat1: You should have received a copy of the GNU General Public License along 
cat1: with this program.  If not, see <http://www.gnu.org/licenses/>.
cat1: */
cat1: 
cat1: 
cat1: #include <glib.h>
cat1: #include <gio/gio.h>
cat1: 
cat1: #include <libdbustest/dbus-test.h>
cat1: 
cat1: static DbusTestServiceBus bus_type = DBUS_TEST_SERVICE_BUS_SESSION;
cat1: static gint max_wait = 60;
cat1: static gboolean keep_env = FALSE;
cat1: static DbusTestProcess * last_task = NULL;
cat1: static DbusTestService * service = NULL;
cat1: static gboolean timeout = FALSE;
cat1: 
cat1: #define NAME_SET "dbus-test-runner-name-set"
cat1: 
cat1: static gboolean
cat1: option_bus_type (G_GNUC_UNUSED const gchar * arg, const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat1: {
cat1: 	if (bus_type != DBUS_TEST_SERVICE_BUS_SESSION) {
cat1: 		g_set_error_literal(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Bus type set more than once");
cat1: 		return TRUE;
cat1: 	}
cat1: 
cat1: 	if (g_strcmp0(value, "session") == 0) {
cat1: 		bus_type = DBUS_TEST_SERVICE_BUS_SESSION;
cat1: 	} else if (g_strcmp0(value, "system") == 0) {
cat1: 		bus_type = DBUS_TEST_SERVICE_BUS_SYSTEM;
cat1: 	} else if (g_strcmp0(value, "both") == 0) {
cat1: 		bus_type = DBUS_TEST_SERVICE_BUS_BOTH;
cat1: 	} else {
cat1: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Bus type '%s' unknown", value);
cat1: 	}
cat1: 
cat1: 	return TRUE;
cat1: }
cat1: 
cat1: static gboolean
cat1: option_task (G_GNUC_UNUSED const gchar * arg, const gchar * value, G_GNUC_UNUSED gpointer data, G_GNUC_UNUSED GError ** error)
cat1: {
cat1: 	if (last_task != NULL) {
cat1: 		g_object_unref(last_task);
cat1: 		last_task = NULL;
cat1: 	}
cat1: 
cat1: 	last_task = dbus_test_process_new(value);
cat1: 	dbus_test_service_add_task(service, DBUS_TEST_TASK(last_task));
cat1: 	return TRUE;
cat1: }
cat1: 
cat1: static gboolean
cat1: option_taskname (G_GNUC_UNUSED const gchar * arg, const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat1: {
cat1: 	if (last_task == NULL) {
cat1: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "No task to put the name %s on.", value);
cat1: 		return FALSE;
cat1: 	}
cat1: 
cat1: 	if (g_object_get_data(G_OBJECT(last_task), NAME_SET)) {
cat1: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Task already has the name %s.  Asked to put %s on it.", dbus_test_task_get_name(DBUS_TEST_TASK(last_task)), value);
cat1: 		return FALSE;
cat1: 	}
cat1: 
cat1: 	g_object_set_data(G_OBJECT(last_task), NAME_SET, GINT_TO_POINTER(TRUE));
cat1: 	dbus_test_task_set_name(DBUS_TEST_TASK(last_task), value);
cat1: 	return TRUE;
cat1: }
cat1: 
cat1: static gboolean
cat1: option_taskbus (G_GNUC_UNUSED const gchar * arg, const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat1: {
cat1: 	if (last_task == NULL) {
cat1: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "No task to put the name %s on.", value);
cat1: 		return FALSE;
cat1: 	}
cat1: 
cat1: 	if (g_strcmp0(value, "session") == 0) {
cat1: 		dbus_test_task_set_bus(DBUS_TEST_TASK(last_task), DBUS_TEST_SERVICE_BUS_SESSION);
cat1: 	} else if (g_strcmp0(value, "system") == 0) {
cat1: 		dbus_test_task_set_bus(DBUS_TEST_TASK(last_task), DBUS_TEST_SERVICE_BUS_SYSTEM);
cat1: 	} else if (g_strcmp0(value, "both") == 0) {
cat1: 		dbus_test_task_set_bus(DBUS_TEST_TASK(last_task), DBUS_TEST_SERVICE_BUS_BOTH);
cat1: 	} else {
cat1: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Bus type '%s' unknown", value);
cat1: 	}
cat1: 
cat1: 	return TRUE;
cat1: }
cat1: 
cat1: static gboolean
cat1: option_complete (G_GNUC_UNUSED const gchar * arg, G_GNUC_UNUSED const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat1: {
cat1: 	if (last_task == NULL) {
cat1: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "No task to put adjust return on.");
cat1: 		return FALSE;
cat1: 	}
cat1: 
cat1: 	if (dbus_test_task_get_wait_finished(DBUS_TEST_TASK(last_task))) {
cat1: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Task has already be setup to wait until finished.");
cat1: 		return FALSE;
cat1: 	}
cat1: 
cat1: 	dbus_test_task_set_wait_finished(DBUS_TEST_TASK(last_task), TRUE);
cat1: 	return TRUE;
cat1: }
cat1: 
cat1: static gboolean
cat1: option_noreturn (G_GNUC_UNUSED const gchar * arg, G_GNUC_UNUSED const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat1: {
cat1: 	if (last_task == NULL) {
cat1: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "No task to put adjust return on.");
cat1: 		return FALSE;
cat1: 	}
cat1: 
cat1: 	if (dbus_test_task_get_return(DBUS_TEST_TASK(last_task)) != DBUS_TEST_TASK_RETURN_NORMAL) {
cat1: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Task return type has already been modified.");
cat1: 		return FALSE;
cat1: 	}
cat1: 
cat1: 	dbus_test_task_set_return(DBUS_TEST_TASK(last_task), DBUS_TEST_TASK_RETURN_IGNORE);
cat1: 	return TRUE;
cat1: }
cat1: 
cat1: static gboolean
cat1: option_invert (G_GNUC_UNUSED const gchar * arg, G_GNUC_UNUSED const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat1: {
cat1: 	if (last_task == NULL) {
cat1: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "No task to put adjust return on.");
cat1: 		return FALSE;
cat1: 	}
cat1: 
cat1: 	if (dbus_test_task_get_return(DBUS_TEST_TASK(last_task)) != DBUS_TEST_TASK_RETURN_NORMAL) {
cat1: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Task return type has already been modified.");
cat1: 		return FALSE;
cat1: 	}
cat1: 
cat1: 	dbus_test_task_set_return(DBUS_TEST_TASK(last_task), DBUS_TEST_TASK_RETURN_INVERT);
cat1: 	return TRUE;
cat1: }
cat1: 
cat1: static gboolean
cat1: option_param (G_GNUC_UNUSED const gchar * arg, const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat1: {
cat1: 	if (last_task == NULL) {
cat1: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "No task to put adjust return on.");
cat1: 		return FALSE;
cat1: 	}
cat1: 
cat1: 	dbus_test_process_append_param(last_task, value);
cat1: 	return TRUE;
cat1: }
cat1: 
cat1: static gboolean
cat1: option_wait (G_GNUC_UNUSED const gchar * arg, const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat1: {
cat1: 	if (last_task == NULL) {
cat1: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "No task to add a wait on %s for.", value);
cat1: 		return FALSE;
cat1: 	}
cat1: 
cat1: 	if (dbus_test_task_get_wait_for(DBUS_TEST_TASK(last_task)) != NULL) {
cat1: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Task is already waiting for %s.  Asked to wait for %s", dbus_test_task_get_wait_for(DBUS_TEST_TASK(last_task)), value);
cat1: 		return FALSE;
cat1: 	}
cat1: 
cat1: 	dbus_test_task_set_wait_for(DBUS_TEST_TASK(last_task), value);
cat1: 	return TRUE;
cat1: }
cat1: 
cat1: static gboolean
cat1: max_wait_hit (G_GNUC_UNUSED gpointer user_data)
cat1: {
cat1: 	g_warning("Timing out at maximum wait of %d seconds.", max_wait);
cat1: 	dbus_test_service_stop(service);
cat1: 	timeout = TRUE;
cat1: 	return FALSE;
cat1: }
cat1: 
cat1: static gchar * dbus_configfile = NULL;
cat1: static gchar * dbus_daemon = NULL;
cat1: static gchar * bustle_cmd = NULL;
cat1: static gchar * bustle_datafile = NULL;
cat1: 
cat1: static GOptionEntry general_options[] = {
cat1: 	{"dbus-daemon",  0,     0,                       G_OPTION_ARG_FILENAME,  &dbus_daemon,     "Path to the DBus deamon to use.  Defaults to 'dbus-daemon'.", "executable"},
cat1: 	{"dbus-config",  'd',   0,                       G_OPTION_ARG_FILENAME,  &dbus_configfile, "Configuration file for newly created DBus server.  Defaults to '" DEFAULT_SESSION_CONF "'.", "config_file"},
cat1: 	{"bustle-monitor", 0,   0,                       G_OPTION_ARG_FILENAME,  &bustle_cmd,      "Path to the Bustle DBus Monitor to use.  Defaults to 'bustle-dbus-monitor'.", "executable"},
cat1: 	{"bustle-data",  'b',   0,                       G_OPTION_ARG_FILENAME,  &bustle_datafile, "A file to write out data from the bustle logger to.", "data_file"},
cat1: 	{"max-wait",     'm',   0,                       G_OPTION_ARG_INT,       &max_wait,        "The maximum amount of time the test runner will wait for the test to complete.  Default is 30 seconds.", "seconds"},
cat1: 	{"keep-env",     0,     0,                       G_OPTION_ARG_NONE,      &keep_env,        "Whether to propagate the execution environment to the dbus-server and all the services activated by it.  By default the environment is cleared.", NULL },
cat1: 	{"bus-type",     0,     0,                       G_OPTION_ARG_CALLBACK,  option_bus_type,  "Configures which buses are represented by the tool to the tasks. Default: session", "{session|system|both}" },
cat1: 	{ NULL, 0, 0, 0, NULL, NULL, NULL }
cat1: };
cat1: 
cat1: static GOptionEntry task_options[] = {
cat1: 	{"task",          't',  G_OPTION_FLAG_FILENAME,   G_OPTION_ARG_CALLBACK,  option_task,     "Defines a new task to run under our private DBus session.", "executable"},
cat1: 	{"task-name",     'n',  0,                        G_OPTION_ARG_CALLBACK,  option_taskname, "A string to label output from the previously defined task.  Defaults to taskN.", "name"},
cat1: 	{"task-bus",      0,    0,                        G_OPTION_ARG_CALLBACK,  option_taskbus,  "Configures which bus the task expects to connect to. Default: both", "{session|system|both}"},
cat1: 	{"ignore-return", 'r',  G_OPTION_FLAG_NO_ARG,     G_OPTION_ARG_CALLBACK,  option_noreturn, "Do not use the return value of the task to calculate whether the test passes or fails.", NULL},
cat1: 	{"invert-return", 'i',  G_OPTION_FLAG_NO_ARG,     G_OPTION_ARG_CALLBACK,  option_invert,   "Invert the return value of the task before calculating whether the test passes or fails.", NULL},
cat1: 	{"parameter",     'p',  0,                        G_OPTION_ARG_CALLBACK,  option_param,    "Add a parameter to the call of this utility.  May be called as many times as you'd like.", NULL},
cat1: 	{"wait-for",      'f',  0,                        G_OPTION_ARG_CALLBACK,  option_wait,     "A dbus-name that should appear on the bus before this task is started", "dbus-name"},
cat1: 	{"wait-until-complete", 'c', G_OPTION_FLAG_NO_ARG,G_OPTION_ARG_CALLBACK,  option_complete, "Signal that we should wait until this task exits even if we don't need the return value", NULL},
cat1: 	{ NULL, 0, 0, 0, NULL, NULL, NULL }
cat1: };
cat1: 
cat1: int
cat1: main (int argc, char * argv[])
cat1: {
cat1: 	GError * error = NULL;
cat1: 	GOptionContext * context;
cat1: 
cat1: #ifndef GLIB_VERSION_2_36
cat1: 	g_type_init();
cat1: #endif
cat1: 
cat1: 	service = dbus_test_service_new(NULL);
cat1: 
cat1: 	context = g_option_context_new("- run multiple tasks under an independent DBus session bus");
cat1: 
cat1: 	g_option_context_add_main_entries(context, general_options, "dbus-runner");
cat1: 
cat1: 	GOptionGroup * taskgroup = g_option_group_new("task-control", "Task control options", "Options that are used to control how the task is handled by the test runner.", NULL, NULL);
cat1: 	g_option_group_add_entries(taskgroup, task_options);
cat1: 	g_option_context_add_group(context, taskgroup);
cat1: 
cat1: 	if (!g_option_context_parse(context, &argc, &argv, &error)) {
cat1: 		g_print("option parsing failed: %s\n", error->message);
cat1: 		g_error_free(error);
cat1: 		return 1;
cat1: 	}
cat1: 
cat1: 	dbus_test_service_set_bus(service, bus_type);
cat1: 
cat1: 	if (dbus_daemon != NULL) {
cat1: 		dbus_test_service_set_daemon(service, dbus_daemon);
cat1: 	}
cat1: 
cat1: 	if (dbus_configfile != NULL) {
cat1: 		dbus_test_service_set_conf_file(service, dbus_configfile);
cat1: 	}
cat1: 
cat1: 	if (bustle_datafile != NULL) {
cat1: 		DbusTestBustle * bustler = dbus_test_bustle_new(bustle_datafile);
cat1: 		/* We want to ensure that bustle captures all the data so start it first */
cat1: 		dbus_test_service_add_task_with_priority(service, DBUS_TEST_TASK(bustler), DBUS_TEST_SERVICE_PRIORITY_FIRST);
cat1: 
cat1: 		if (bustle_cmd != NULL) {
cat1: 			dbus_test_bustle_set_executable(bustler, bustle_cmd);
cat1: 		}
cat1: 
cat1: 		g_object_unref(bustler);
cat1: 	}
cat1: 
cat1: 	if (max_wait > 0) {
cat1: 		g_timeout_add_seconds(max_wait, max_wait_hit, NULL);
cat1: 	}
cat1: 
cat1: 	dbus_test_service_set_keep_environment(service, keep_env);
cat1: 
cat1: 	/* These should all be in the service now */
cat1: 	if (last_task != NULL) {
cat1: 		g_object_unref(last_task);
cat1: 		last_task = NULL;
cat1: 	} else {
cat1: 		g_critical("No tasks assigned");
cat1: 		g_object_unref(service);
cat1: 		return -1;
cat1: 	}
cat1: 
cat1: 	gint service_status = dbus_test_service_run(service);
cat1: 	g_object_unref(service);
cat1: 
cat1: 	if (timeout) {
cat1: 		return -1;
cat1: 	} else {
cat1: 		return service_status;
cat1: 	}
cat1: }
cat2: /*
cat2: Copyright 2010 Canonical Ltd.
cat2: 
cat2: Authors:
cat2:     Ted Gould <ted@canonical.com>
cat2: 
cat2: This program is free software: you can redistribute it and/or modify it 
cat2: under the terms of the GNU General Public License version 3, as published 
cat2: by the Free Software Foundation.
cat2: 
cat2: This program is distributed in the hope that it will be useful, but 
cat2: WITHOUT ANY WARRANTY; without even the implied warranties of 
cat2: MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
cat2: PURPOSE.  See the GNU General Public License for more details.
cat2: 
cat2: You should have received a copy of the GNU General Public License along 
cat2: with this program.  If not, see <http://www.gnu.org/licenses/>.
cat2: */
cat2: 
cat2: 
cat2: #include <glib.h>
cat2: #include <gio/gio.h>
cat2: 
cat2: #include <libdbustest/dbus-test.h>
cat2: 
cat2: static DbusTestServiceBus bus_type = DBUS_TEST_SERVICE_BUS_SESSION;
cat2: static gint max_wait = 60;
cat2: static gboolean keep_env = FALSE;
cat2: static DbusTestProcess * last_task = NULL;
cat2: static DbusTestService * service = NULL;
cat2: static gboolean timeout = FALSE;
cat2: 
cat2: #define NAME_SET "dbus-test-runner-name-set"
cat2: 
cat2: static gboolean
cat2: option_bus_type (G_GNUC_UNUSED const gchar * arg, const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat2: {
cat2: 	if (bus_type != DBUS_TEST_SERVICE_BUS_SESSION) {
cat2: 		g_set_error_literal(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Bus type set more than once");
cat2: 		return TRUE;
cat2: 	}
cat2: 
cat2: 	if (g_strcmp0(value, "session") == 0) {
cat2: 		bus_type = DBUS_TEST_SERVICE_BUS_SESSION;
cat2: 	} else if (g_strcmp0(value, "system") == 0) {
cat2: 		bus_type = DBUS_TEST_SERVICE_BUS_SYSTEM;
cat2: 	} else if (g_strcmp0(value, "both") == 0) {
cat2: 		bus_type = DBUS_TEST_SERVICE_BUS_BOTH;
cat2: 	} else {
cat2: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Bus type '%s' unknown", value);
cat2: 	}
cat2: 
cat2: 	return TRUE;
cat2: }
cat2: 
cat2: static gboolean
cat2: option_task (G_GNUC_UNUSED const gchar * arg, const gchar * value, G_GNUC_UNUSED gpointer data, G_GNUC_UNUSED GError ** error)
cat2: {
cat2: 	if (last_task != NULL) {
cat2: 		g_object_unref(last_task);
cat2: 		last_task = NULL;
cat2: 	}
cat2: 
cat2: 	last_task = dbus_test_process_new(value);
cat2: 	dbus_test_service_add_task(service, DBUS_TEST_TASK(last_task));
cat2: 	return TRUE;
cat2: }
cat2: 
cat2: static gboolean
cat2: option_taskname (G_GNUC_UNUSED const gchar * arg, const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat2: {
cat2: 	if (last_task == NULL) {
cat2: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "No task to put the name %s on.", value);
cat2: 		return FALSE;
cat2: 	}
cat2: 
cat2: 	if (g_object_get_data(G_OBJECT(last_task), NAME_SET)) {
cat2: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Task already has the name %s.  Asked to put %s on it.", dbus_test_task_get_name(DBUS_TEST_TASK(last_task)), value);
cat2: 		return FALSE;
cat2: 	}
cat2: 
cat2: 	g_object_set_data(G_OBJECT(last_task), NAME_SET, GINT_TO_POINTER(TRUE));
cat2: 	dbus_test_task_set_name(DBUS_TEST_TASK(last_task), value);
cat2: 	return TRUE;
cat2: }
cat2: 
cat2: static gboolean
cat2: option_taskbus (G_GNUC_UNUSED const gchar * arg, const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat2: {
cat2: 	if (last_task == NULL) {
cat2: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "No task to put the name %s on.", value);
cat2: 		return FALSE;
cat2: 	}
cat2: 
cat2: 	if (g_strcmp0(value, "session") == 0) {
cat2: 		dbus_test_task_set_bus(DBUS_TEST_TASK(last_task), DBUS_TEST_SERVICE_BUS_SESSION);
cat2: 	} else if (g_strcmp0(value, "system") == 0) {
cat2: 		dbus_test_task_set_bus(DBUS_TEST_TASK(last_task), DBUS_TEST_SERVICE_BUS_SYSTEM);
cat2: 	} else if (g_strcmp0(value, "both") == 0) {
cat2: 		dbus_test_task_set_bus(DBUS_TEST_TASK(last_task), DBUS_TEST_SERVICE_BUS_BOTH);
cat2: 	} else {
cat2: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Bus type '%s' unknown", value);
cat2: 	}
cat2: 
cat2: 	return TRUE;
cat2: }
cat2: 
cat2: static gboolean
cat2: option_complete (G_GNUC_UNUSED const gchar * arg, G_GNUC_UNUSED const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat2: {
cat2: 	if (last_task == NULL) {
cat2: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "No task to put adjust return on.");
cat2: 		return FALSE;
cat2: 	}
cat2: 
cat2: 	if (dbus_test_task_get_wait_finished(DBUS_TEST_TASK(last_task))) {
cat2: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Task has already be setup to wait until finished.");
cat2: 		return FALSE;
cat2: 	}
cat2: 
cat2: 	dbus_test_task_set_wait_finished(DBUS_TEST_TASK(last_task), TRUE);
cat2: 	return TRUE;
cat2: }
cat2: 
cat2: static gboolean
cat2: option_noreturn (G_GNUC_UNUSED const gchar * arg, G_GNUC_UNUSED const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat2: {
cat2: 	if (last_task == NULL) {
cat2: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "No task to put adjust return on.");
cat2: 		return FALSE;
cat2: 	}
cat2: 
cat2: 	if (dbus_test_task_get_return(DBUS_TEST_TASK(last_task)) != DBUS_TEST_TASK_RETURN_NORMAL) {
cat2: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Task return type has already been modified.");
cat2: 		return FALSE;
cat2: 	}
cat2: 
cat2: 	dbus_test_task_set_return(DBUS_TEST_TASK(last_task), DBUS_TEST_TASK_RETURN_IGNORE);
cat2: 	return TRUE;
cat2: }
cat2: 
cat2: static gboolean
cat2: option_invert (G_GNUC_UNUSED const gchar * arg, G_GNUC_UNUSED const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat2: {
cat2: 	if (last_task == NULL) {
cat2: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "No task to put adjust return on.");
cat2: 		return FALSE;
cat2: 	}
cat2: 
cat2: 	if (dbus_test_task_get_return(DBUS_TEST_TASK(last_task)) != DBUS_TEST_TASK_RETURN_NORMAL) {
cat2: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Task return type has already been modified.");
cat2: 		return FALSE;
cat2: 	}
cat2: 
cat2: 	dbus_test_task_set_return(DBUS_TEST_TASK(last_task), DBUS_TEST_TASK_RETURN_INVERT);
cat2: 	return TRUE;
cat2: }
cat2: 
cat2: static gboolean
cat2: option_param (G_GNUC_UNUSED const gchar * arg, const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat2: {
cat2: 	if (last_task == NULL) {
cat2: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "No task to put adjust return on.");
cat2: 		return FALSE;
cat2: 	}
cat2: 
cat2: 	dbus_test_process_append_param(last_task, value);
cat2: 	return TRUE;
cat2: }
cat2: 
cat2: static gboolean
cat2: option_wait (G_GNUC_UNUSED const gchar * arg, const gchar * value, G_GNUC_UNUSED gpointer data, GError ** error)
cat2: {
cat2: 	if (last_task == NULL) {
cat2: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "No task to add a wait on %s for.", value);
cat2: 		return FALSE;
cat2: 	}
cat2: 
cat2: 	if (dbus_test_task_get_wait_for(DBUS_TEST_TASK(last_task)) != NULL) {
cat2: 		g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_BAD_VALUE, "Task is already waiting for %s.  Asked to wait for %s", dbus_test_task_get_wait_for(DBUS_TEST_TASK(last_task)), value);
cat2: 		return FALSE;
cat2: 	}
cat2: 
cat2: 	dbus_test_task_set_wait_for(DBUS_TEST_TASK(last_task), value);
cat2: 	return TRUE;
cat2: }
cat2: 
cat2: static gboolean
cat2: max_wait_hit (G_GNUC_UNUSED gpointer user_data)
cat2: {
cat2: 	g_warning("Timing out at maximum wait of %d seconds.", max_wait);
cat2: 	dbus_test_service_stop(service);
cat2: 	timeout = TRUE;
cat2: 	return FALSE;
cat2: }
cat2: 
cat2: static gchar * dbus_configfile = NULL;
cat2: static gchar * dbus_daemon = NULL;
cat2: static gchar * bustle_cmd = NULL;
cat2: static gchar * bustle_datafile = NULL;
cat2: 
cat2: static GOptionEntry general_options[] = {
cat2: 	{"dbus-daemon",  0,     0,                       G_OPTION_ARG_FILENAME,  &dbus_daemon,     "Path to the DBus deamon to use.  Defaults to 'dbus-daemon'.", "executable"},
cat2: 	{"dbus-config",  'd',   0,                       G_OPTION_ARG_FILENAME,  &dbus_configfile, "Configuration file for newly created DBus server.  Defaults to '" DEFAULT_SESSION_CONF "'.", "config_file"},
cat2: 	{"bustle-monitor", 0,   0,                       G_OPTION_ARG_FILENAME,  &bustle_cmd,      "Path to the Bustle DBus Monitor to use.  Defaults to 'bustle-dbus-monitor'.", "executable"},
cat2: 	{"bustle-data",  'b',   0,                       G_OPTION_ARG_FILENAME,  &bustle_datafile, "A file to write out data from the bustle logger to.", "data_file"},
cat2: 	{"max-wait",     'm',   0,                       G_OPTION_ARG_INT,       &max_wait,        "The maximum amount of time the test runner will wait for the test to complete.  Default is 30 seconds.", "seconds"},
cat2: 	{"keep-env",     0,     0,                       G_OPTION_ARG_NONE,      &keep_env,        "Whether to propagate the execution environment to the dbus-server and all the services activated by it.  By default the environment is cleared.", NULL },
cat2: 	{"bus-type",     0,     0,                       G_OPTION_ARG_CALLBACK,  option_bus_type,  "Configures which buses are represented by the tool to the tasks. Default: session", "{session|system|both}" },
cat2: 	{ NULL, 0, 0, 0, NULL, NULL, NULL }
cat2: };
cat2: 
cat2: static GOptionEntry task_options[] = {
cat2: 	{"task",          't',  G_OPTION_FLAG_FILENAME,   G_OPTION_ARG_CALLBACK,  option_task,     "Defines a new task to run under our private DBus session.", "executable"},
cat2: 	{"task-name",     'n',  0,                        G_OPTION_ARG_CALLBACK,  option_taskname, "A string to label output from the previously defined task.  Defaults to taskN.", "name"},
cat2: 	{"task-bus",      0,    0,                        G_OPTION_ARG_CALLBACK,  option_taskbus,  "Configures which bus the task expects to connect to. Default: both", "{session|system|both}"},
cat2: 	{"ignore-return", 'r',  G_OPTION_FLAG_NO_ARG,     G_OPTION_ARG_CALLBACK,  option_noreturn, "Do not use the return value of the task to calculate whether the test passes or fails.", NULL},
cat2: 	{"invert-return", 'i',  G_OPTION_FLAG_NO_ARG,     G_OPTION_ARG_CALLBACK,  option_invert,   "Invert the return value of the task before calculating whether the test passes or fails.", NULL},
cat2: 	{"parameter",     'p',  0,                        G_OPTION_ARG_CALLBACK,  option_param,    "Add a parameter to the call of this utility.  May be called as many times as you'd like.", NULL},
cat2: 	{"wait-for",      'f',  0,                        G_OPTION_ARG_CALLBACK,  option_wait,     "A dbus-name that should appear on the bus before this task is started", "dbus-name"},
cat2: 	{"wait-until-complete", 'c', G_OPTION_FLAG_NO_ARG,G_OPTION_ARG_CALLBACK,  option_complete, "Signal that we should wait until this task exits even if we don't need the return value", NULL},
cat2: 	{ NULL, 0, 0, 0, NULL, NULL, NULL }
cat2: };
cat2: 
cat2: int
cat2: main (int argc, char * argv[])
cat2: {
cat2: 	GError * error = NULL;
cat2: 	GOptionContext * context;
cat2: 
cat2: #ifndef GLIB_VERSION_2_36
cat2: 	g_type_init();
cat2: #endif
cat2: 
cat2: 	service = dbus_test_service_new(NULL);
cat2: 
cat2: 	context = g_option_context_new("- run multiple tasks under an independent DBus session bus");
cat2: 
cat2: 	g_option_context_add_main_entries(context, general_options, "dbus-runner");
cat2: 
cat2: 	GOptionGroup * taskgroup = g_option_group_new("task-control", "Task control options", "Options that are used to control how the task is handled by the test runner.", NULL, NULL);
cat2: 	g_option_group_add_entries(taskgroup, task_options);
cat2: 	g_option_context_add_group(context, taskgroup);
cat2: 
cat2: 	if (!g_option_context_parse(context, &argc, &argv, &error)) {
cat2: 		g_print("option parsing failed: %s\n", error->message);
cat2: 		g_error_free(error);
cat2: 		return 1;
cat2: 	}
cat2: 
cat2: 	dbus_test_service_set_bus(service, bus_type);
cat2: 
cat2: 	if (dbus_daemon != NULL) {
cat2: 		dbus_test_service_set_daemon(service, dbus_daemon);
cat2: 	}
cat2: 
cat2: 	if (dbus_configfile != NULL) {
cat2: 		dbus_test_service_set_conf_file(service, dbus_configfile);
cat2: 	}
cat2: 
cat2: 	if (bustle_datafile != NULL) {
cat2: 		DbusTestBustle * bustler = dbus_test_bustle_new(bustle_datafile);
cat2: 		/* We want to ensure that bustle captures all the data so start it first */
cat2: 		dbus_test_service_add_task_with_priority(service, DBUS_TEST_TASK(bustler), DBUS_TEST_SERVICE_PRIORITY_FIRST);
cat2: 
cat2: 		if (bustle_cmd != NULL) {
cat2: 			dbus_test_bustle_set_executable(bustler, bustle_cmd);
cat2: 		}
cat2: 
cat2: 		g_object_unref(bustler);
cat2: 	}
cat2: 
cat2: 	if (max_wait > 0) {
cat2: 		g_timeout_add_seconds(max_wait, max_wait_hit, NULL);
cat2: 	}
cat2: 
cat2: 	dbus_test_service_set_keep_environment(service, keep_env);
cat2: 
cat2: 	/* These should all be in the service now */
cat2: 	if (last_task != NULL) {
cat2: 		g_object_unref(last_task);
cat2: 		last_task = NULL;
cat2: 	} else {
cat2: 		g_critical("No tasks assigned");
cat2: 		g_object_unref(service);
cat2: 		return -1;
cat2: 	}
cat2: 
cat2: 	gint service_status = dbus_test_service_run(service);
cat2: 	g_object_unref(service);
cat2: 
cat2: 	if (timeout) {
cat2: 		return -1;
cat2: 	} else {
cat2: 		return service_status;
cat2: 	}
cat2: }
cat1: Shutting down
cat2: Shutting down
DBus daemon: Shutdown
