コード例 #1
0
static void
test_getservers_slmock_two (void)
{
	DbusTestService * service = dbus_test_service_new(NULL);

	/* RLS */
	DbusTestProcess * rls = dbus_test_process_new(REMOTE_LOGON_SERVICE);
	dbus_test_process_append_param(rls, "--config-file=" SLMOCK_CONFIG_FILE);
	dbus_test_service_add_task(service, DBUS_TEST_TASK(rls));

	/* Dummy */
	DbusTestTask * dummy = dbus_test_task_new();
	dbus_test_task_set_wait_for(dummy, "org.ArcticaProject.RemoteLogon");
	dbus_test_service_add_task(service, dummy);

	/* Get RLS up and running and us on that bus */
	dbus_test_service_start_tasks(service);

	GDBusConnection * session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
	g_dbus_connection_set_exit_on_close(session, FALSE);

	g_assert(slmock_check_login(session, &slmock_table[0], TRUE));
	g_assert(slmock_check_login(session, &slmock_table[1], TRUE));

	g_object_unref(session);
	g_object_unref(rls);
	g_object_unref(service);

	return;
}
コード例 #2
0
static void
new_connection_cb (GDBusServer *server,
		   GDBusConnection *connection,
		   ServiceData *svc)
{
	GError *error = NULL;
	rb_debug ("new connection to metadata service");

	/* don't allow more than one connection at a time */
	if (svc->connection) {
		rb_debug ("metadata service already has a client.  go away.");
		return;
	}
	g_dbus_connection_register_object (connection,
					   RB_METADATA_DBUS_OBJECT_PATH,
					   g_dbus_node_info_lookup_interface (svc->node_info, RB_METADATA_DBUS_INTERFACE),
					   &metadata_vtable,
					   svc,
					   NULL,
					   &error);
	if (error != NULL) {
		rb_debug ("unable to register metadata object: %s", error->message);
		g_clear_error (&error);
	} else {
		svc->connection = g_object_ref (connection);
		g_signal_connect (connection, "closed", G_CALLBACK (connection_closed_cb), svc);

		g_dbus_connection_set_exit_on_close (connection, (svc->external == FALSE));
	}
}
コード例 #3
0
ファイル: dbus.c プロジェクト: GNOME/evolution-rss
gboolean
init_gdbus (void)
{
	GError *error = NULL;

	connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
	if (error) {
		g_warning ("could not get system bus: %s\n", error->message);
		g_error_free (error);
		return FALSE;
	}

	g_dbus_connection_set_exit_on_close (connection, FALSE);
	g_signal_connect (connection, "closed",
		G_CALLBACK (connection_closed_cb), NULL);

	g_bus_own_name (G_BUS_TYPE_SESSION,
		RSS_DBUS_SERVICE,
		G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT,
		on_bus_acquired,
		on_name_acquired,
		on_name_lost,
		NULL,
		NULL);

	return FALSE;
}
コード例 #4
0
static void
test_getdomains_basic (void)
{
	DbusTestService * service = dbus_test_service_new(NULL);

	/* RLS */
	DbusTestProcess * rls = dbus_test_process_new(REMOTE_LOGON_SERVICE);
	dbus_test_process_append_param(rls, "--config-file=" SLMOCK_CONFIG_FILE);
	dbus_test_service_add_task(service, DBUS_TEST_TASK(rls));

	/* Dummy */
	DbusTestTask * dummy = dbus_test_task_new();
	dbus_test_task_set_wait_for(dummy, "org.ArcticaProject.RemoteLogon");
	dbus_test_service_add_task(service, dummy);

	/* Get RLS up and running and us on that bus */
	dbus_test_service_start_tasks(service);

	GDBusConnection * session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
	g_dbus_connection_set_exit_on_close(session, FALSE);

	GError * error = NULL;
	GVariant * retval = g_dbus_connection_call_sync(session,
	                                                "org.ArcticaProject.RemoteLogon",
	                                                "/org/ArcticaProject/RemoteLogon",
	                                                "org.ArcticaProject.RemoteLogon",
	                                                "GetCachedDomainsForServer",
	                                                g_variant_new("(s)", "https://slmock.com/"), /* params */
	                                                G_VARIANT_TYPE("(as)"), /* ret type */
	                                                G_DBUS_CALL_FLAGS_NONE,
	                                                -1,
	                                                NULL,
	                                                &error);

	if (error != NULL) {
		g_debug("Error from GetCachedDomainsForServer: %s", error->message);
		g_error_free(error);
		error = NULL;
	}

	g_assert(retval != NULL);
	g_assert(g_variant_n_children(retval) == 1);

	GVariant * child = g_variant_get_child_value(retval, 0);
	g_assert(g_variant_is_of_type(child, G_VARIANT_TYPE_ARRAY));
	g_variant_unref(child);

	g_variant_unref(retval);

	g_object_unref(session);
	g_object_unref(rls);
	g_object_unref(service);

	return;
}
コード例 #5
0
static void
test_getservers_slmock_none (void)
{
	DbusTestService * service = dbus_test_service_new(NULL);

	/* RLS */
	DbusTestProcess * rls = dbus_test_process_new(REMOTE_LOGON_SERVICE);
	dbus_test_process_append_param(rls, "--config-file=" SLMOCK_CONFIG_FILE);
	dbus_test_service_add_task(service, DBUS_TEST_TASK(rls));

	/* Dummy */
	DbusTestTask * dummy = dbus_test_task_new();
	dbus_test_task_set_wait_for(dummy, "org.ArcticaProject.RemoteLogon");
	dbus_test_service_add_task(service, dummy);

	/* Get RLS up and running and us on that bus */
	dbus_test_service_start_tasks(service);

	GDBusConnection * session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
	g_dbus_connection_set_exit_on_close(session, FALSE);

	GVariant * retval = g_dbus_connection_call_sync(session,
	                                                "org.ArcticaProject.RemoteLogon",
	                                                "/org/ArcticaProject/RemoteLogon",
	                                                "org.ArcticaProject.RemoteLogon",
	                                                "GetServersForLogin",
	                                                g_variant_new("(sssb)",
	                                                              "https://slmock.com/",
	                                                              "Baduser",
	                                                              "Badpass",
	                                                              TRUE), /* params */
	                                                G_VARIANT_TYPE("(bsa(sssba(sbva{sv})a(si)))"), /* ret type */
	                                                G_DBUS_CALL_FLAGS_NONE,
	                                                -1,
	                                                NULL,
	                                                NULL);

	g_assert(retval != NULL);
	g_assert(g_variant_n_children(retval) == 3);

	GVariant * loggedin = g_variant_get_child_value(retval, 0);
	g_assert(!g_variant_get_boolean(loggedin));
	g_variant_unref(loggedin); loggedin = NULL;

	GVariant * array = g_variant_get_child_value(retval, 2);
	g_assert(g_variant_n_children(array) == 0);
	g_variant_unref(array);
	g_variant_unref(retval);

	g_object_unref(session);
	g_object_unref(rls);
	g_object_unref(service);

	return;
}
コード例 #6
0
static void
test_setlastused_basic (void)
{
	DbusTestService * service = dbus_test_service_new(NULL);

	/* RLS */
	DbusTestProcess * rls = dbus_test_process_new(REMOTE_LOGON_SERVICE);
	dbus_test_process_append_param(rls, "--config-file=" SLMOCK_CONFIG_FILE);
	dbus_test_service_add_task(service, DBUS_TEST_TASK(rls));

	/* Dummy */
	DbusTestTask * dummy = dbus_test_task_new();
	dbus_test_task_set_wait_for(dummy, "org.ArcticaProject.RemoteLogon");
	dbus_test_service_add_task(service, dummy);

	/* Get RLS up and running and us on that bus */
	dbus_test_service_start_tasks(service);

	GDBusConnection * session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
	g_dbus_connection_set_exit_on_close(session, FALSE);
	
	g_assert(slmock_check_login(session, &slmock_table[1], TRUE));

	GError * error = NULL;
	GVariant * retval = g_dbus_connection_call_sync(session,
	                                                "org.ArcticaProject.RemoteLogon",
	                                                "/org/ArcticaProject/RemoteLogon",
	                                                "org.ArcticaProject.RemoteLogon",
	                                                "SetLastUsedServer",
	                                                g_variant_new("(ss)", "Landscape", freerdp_server_table[1].uri), /* params */
	                                                NULL, /* ret type */
	                                                G_DBUS_CALL_FLAGS_NONE,
	                                                -1,
	                                                NULL,
	                                                &error);

	if (error != NULL) {
		g_debug("Error from SetLastUsedServer: %s", error->message);
		g_error_free(error);
		error = NULL;
	}

	g_assert(retval != NULL);
	g_assert(g_variant_n_children(retval) == 0);
	g_variant_unref(retval);
	
	g_assert(slmock_check_login(session, &slmock_table[3], FALSE));

	g_object_unref(session);
	g_object_unref(rls);
	g_object_unref(service);
	
	return;
}
コード例 #7
0
static void
test_connection_loss (void)
{
  GDBusProxy *proxy;
  GError *error;

  error = NULL;
  proxy = g_dbus_proxy_new_sync (c,
                                 G_DBUS_PROXY_FLAGS_NONE,
                                 NULL,                      /* GDBusInterfaceInfo */
                                 "com.example.TestService", /* name */
                                 "/com/example/TestObject", /* object path */
                                 "com.example.Frob",        /* interface */
                                 NULL, /* GCancellable */
                                 &error);
  g_assert_no_error (error);

  error = NULL;
  g_dbus_proxy_call (proxy,
                     "Sleep",
                     g_variant_new ("(i)", 100 * 1000 /* msec */),
                     G_DBUS_CALL_FLAGS_NONE,
                     10 * 1000 /* msec */,
                     NULL, /* GCancellable */
                     sleep_cb,
                     &error);

  /* Make sure we don't exit when the bus goes away */
  g_dbus_connection_set_exit_on_close (c, FALSE);

  /* Nuke the connection to the bus */
  g_timeout_add (100 /* ms */, on_timeout, NULL);

  g_main_loop_run (loop);

  /* If we didn't act on connection-loss we'd be getting G_IO_ERROR_TIMEOUT
   * generated locally. So if we get G_IO_ERROR_CLOSED it means that we
   * are acting correctly on connection loss.
   */
  g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CLOSED);
  g_assert (!g_dbus_error_is_remote_error (error));
  g_clear_error (&error);

  g_object_unref (proxy);
}
コード例 #8
0
static gboolean
init_gdbus (void)
{
	GError *error = NULL;

	if (connection != NULL)
		return TRUE;
	connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
	if (error) {
		g_warning ("could not get system bus: %s\n", error->message);
		g_error_free (error);
		return FALSE;
	}
	g_dbus_connection_set_exit_on_close (connection, FALSE);
	g_signal_connect (connection, "closed", G_CALLBACK (connection_closed_cb), NULL);

	return TRUE;
}
コード例 #9
0
static GDBusConnection *
get_system_bus (void)
{
        GError          *error;
        GDBusConnection *bus;

        error = NULL;
        bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
        if (bus == NULL) {
                g_warning ("Couldn't connect to system bus: %s",
                           error->message);
                g_error_free (error);
                goto out;
        }

        g_dbus_connection_set_exit_on_close (bus, FALSE);

 out:
        return bus;
}
コード例 #10
0
static GDBusConnection *
create_connection (GIOStream  *stream,
                   GMainLoop  *main_loop,
                   GError    **error)
{
  GDBusConnection *ret;

  g_assert (G_IS_IO_STREAM (stream));
  g_assert (main_loop != NULL);
  g_assert (error != NULL);

  if ((ret = g_dbus_connection_new_sync (stream, NULL,
                                          G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING,
                                          NULL, NULL, error)))
    {
      g_dbus_connection_set_exit_on_close (ret, FALSE);
      g_signal_connect_swapped (ret, "closed", G_CALLBACK (g_main_loop_quit), main_loop);
    }

  return ret;
}
コード例 #11
0
static gboolean
ide_worker_manager_new_connection_cb (IdeWorkerManager *self,
                                      GDBusConnection  *connection,
                                      GDBusServer      *server)
{
  GCredentials *credentials;
  GHashTableIter iter;
  gpointer key, value;

  IDE_ENTRY;

  g_assert (IDE_IS_WORKER_MANAGER (self));
  g_assert (G_IS_DBUS_CONNECTION (connection));
  g_assert (G_IS_DBUS_SERVER (server));

  g_dbus_connection_set_exit_on_close (connection, FALSE);

  credentials = g_dbus_connection_get_peer_credentials (connection);
  if ((credentials == NULL) || (-1 == g_credentials_get_unix_pid (credentials, NULL)))
    IDE_RETURN (FALSE);

  g_hash_table_iter_init (&iter, self->plugin_name_to_worker);

  while (g_hash_table_iter_next (&iter, &key, &value))
    {
      IdeWorkerProcess *process = value;

      if (ide_worker_process_matches_credentials (process, credentials))
        {
          ide_worker_process_set_connection (process, connection);
          IDE_RETURN (TRUE);
        }
    }

  IDE_RETURN (FALSE);
}
コード例 #12
0
static void
test_getservers_uccs (void)
{
	DbusTestService * service = dbus_test_service_new(NULL);

	/* RLS */
	DbusTestProcess * rls = dbus_test_process_new(REMOTE_LOGON_SERVICE);
	dbus_test_process_append_param(rls, "--config-file=" UCCS_CONFIG_FILE);
	dbus_test_service_add_task(service, DBUS_TEST_TASK(rls));

	/* Dummy */
	DbusTestTask * dummy = dbus_test_task_new();
	dbus_test_task_set_wait_for(dummy, "org.ArcticaProject.RemoteLogon");
	dbus_test_service_add_task(service, dummy);

	/* Get RLS up and running and us on that bus */
	dbus_test_service_start_tasks(service);

	GDBusConnection * session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
	g_dbus_connection_set_exit_on_close(session, FALSE);

	GVariant * retval = g_dbus_connection_call_sync(session,
	                                                "org.ArcticaProject.RemoteLogon",
	                                                "/org/ArcticaProject/RemoteLogon",
	                                                "org.ArcticaProject.RemoteLogon",
	                                                "GetServers",
	                                                NULL, /* params */
	                                                G_VARIANT_TYPE("(a(sssba(sbva{sv})a(si)))"), /* ret type */
	                                                G_DBUS_CALL_FLAGS_NONE,
	                                                -1,
	                                                NULL,
	                                                NULL);

	g_assert(retval != NULL);
	g_assert(g_variant_n_children(retval) == 1);

	GVariant * array = g_variant_get_child_value(retval, 0);
	g_assert(g_variant_n_children(array) == 1);
	g_assert(g_variant_is_of_type(array, G_VARIANT_TYPE_ARRAY));

	GVariant * tuple = g_variant_get_child_value(array, 0);

	if (TRUE) { /* type check */
		GVariant * type = g_variant_get_child_value(tuple, 0);
		g_assert(g_variant_is_of_type(type, G_VARIANT_TYPE_STRING));
		g_assert(g_strcmp0(g_variant_get_string(type, NULL), "uccs") == 0);
		g_variant_unref(type);
	}

	if (TRUE) { /* name check */
		GVariant * name = g_variant_get_child_value(tuple, 1);
		g_assert(g_variant_is_of_type(name, G_VARIANT_TYPE_STRING));
		g_assert(g_strcmp0(g_variant_get_string(name, NULL), "Test Server Name") == 0);
		g_variant_unref(name);
	}

	if (TRUE) { /* uri check */
		GVariant * uri = g_variant_get_child_value(tuple, 2);
		g_assert(g_variant_is_of_type(uri, G_VARIANT_TYPE_STRING));
		g_assert(g_strcmp0(g_variant_get_string(uri, NULL), "https://uccs.test.mycompany.com/") == 0);
		g_variant_unref(uri);
	}

	g_variant_unref(tuple);
	g_variant_unref(array);
	g_variant_unref(retval);

	g_object_unref(session);
	g_object_unref(rls);
	g_object_unref(service);

	return;
}
コード例 #13
0
ファイル: meta-daemon.c プロジェクト: gicmo/gvfs
int
main (int argc, char *argv[])
{
  GMainLoop *loop;
  GDBusConnection *conn;
  gboolean replace;
  gboolean show_version;
  GError *error;
  guint name_owner_id;
  GBusNameOwnerFlags flags;
  GOptionContext *context;
  const GOptionEntry options[] = {
    { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace,  N_("Replace old daemon."), NULL },
    { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version."), NULL},
    { NULL }
  };

  setlocale (LC_ALL, "");

  bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  g_set_application_name (_("GVFS Metadata Daemon"));
  context = g_option_context_new ("");

  g_option_context_set_summary (context, _("Metadata daemon for GVFS"));

  g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);

  replace = FALSE;
  show_version = FALSE;
  name_owner_id = 0;

  error = NULL;
  if (!g_option_context_parse (context, &argc, &argv, &error))
    {
      /* Translators: the first %s is the application name, */
      /* the second %s is the error message                 */
      g_printerr (_("%s: %s"), g_get_application_name(), error->message);
      g_printerr ("\n");
      g_printerr (_("Try \"%s --help\" for more information."),
		  g_get_prgname ());
      g_printerr ("\n");
      g_error_free (error);
      g_option_context_free (context);
      return 1;
    }

  g_option_context_free (context);

  if (show_version)
    {
      g_print(PACKAGE_STRING "\n");
      return 0;
    }

  error = NULL;
  conn = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
  if (!conn)
    {
      g_printerr ("Failed to connect to the D-BUS daemon: %s (%s, %d)\n",
                  error->message, g_quark_to_string (error->domain), error->code);
      g_error_free (error);
      return 1;
    }

  tree_infos = g_hash_table_new_full (g_str_hash,
				      g_str_equal,
				      NULL,
				      (GDestroyNotify)tree_info_free);

  loop = g_main_loop_new (NULL, FALSE);
  g_dbus_connection_set_exit_on_close (conn, FALSE);
  g_signal_connect (conn, "closed", G_CALLBACK (on_connection_closed), loop);

  flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT;
  if (replace)
    flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE;

  skeleton = gvfs_metadata_skeleton_new ();

  g_signal_connect (skeleton, "handle-set", G_CALLBACK (handle_set), skeleton);
  g_signal_connect (skeleton, "handle-remove", G_CALLBACK (handle_remove), skeleton);
  g_signal_connect (skeleton, "handle-move", G_CALLBACK (handle_move), skeleton);
  g_signal_connect (skeleton, "handle-get-tree-from-device", G_CALLBACK (handle_get_tree_from_device), skeleton);

  error = NULL;
  if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (skeleton), conn,
                                         G_VFS_DBUS_METADATA_PATH, &error))
    {
      g_printerr ("Error exporting metadata daemon: %s (%s, %d)\n",
                  error->message, g_quark_to_string (error->domain), error->code);
      g_error_free (error);
      g_object_unref (conn);
      g_main_loop_unref (loop);
      return 1;
    }

  name_owner_id = g_bus_own_name_on_connection (conn,
                                                G_VFS_DBUS_METADATA_NAME,
                                                flags,
                                                NULL,
                                                on_name_lost,
                                                loop,
                                                NULL);
  
  g_main_loop_run (loop);
  
  if (skeleton)
    g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (skeleton));
  if (name_owner_id != 0)
    g_bus_unown_name (name_owner_id);
  if (conn)
    g_object_unref (conn);
  if (loop != NULL)
    g_main_loop_unref (loop);

  return 0;
}
コード例 #14
0
ファイル: xdp-main.c プロジェクト: devcurmudgeon/xdg-app
int
main (int    argc,
      char **argv)
{
  guint owner_id;
  GBytes *introspection_bytes;
  g_autoptr(GError) error = NULL;
  g_autofree char *path = NULL;
  GDBusConnection  *session_bus;
  GOptionContext *context;

  setlocale (LC_ALL, "");

  /* Avoid even loading gvfs to avoid accidental confusion */
  g_setenv ("GIO_USE_VFS", "local", TRUE);

  context = g_option_context_new ("- document portal");
  g_option_context_add_main_entries (context, entries, NULL);
  if (!g_option_context_parse (context, &argc, &argv, &error))
    {
      g_printerr ("option parsing failed: %s\n", error->message);
      return 1;
    }

  if (opt_daemon)
    {
      pid_t pid;
      ssize_t read_res;

      daemon_event_fd = eventfd (0, EFD_CLOEXEC);
      pid = fork ();
      if (pid != 0)
        {
          guint64 counter;

          read_res = read (daemon_event_fd, &counter, sizeof (counter));
          if (read_res != 8)
            exit (1);
          exit (counter - 1);
        }
    }

  if (opt_verbose)
    g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, message_handler, NULL);

  g_set_prgname (argv[0]);

  loop = g_main_loop_new (NULL, FALSE);

  path = g_build_filename (g_get_user_data_dir (), "xdg-app/db", TABLE_NAME, NULL);
  db = xdg_app_db_new (path, FALSE, &error);
  if (db == NULL)
    {
      g_printerr ("Failed to load db: %s\n", error->message);
      do_exit (2);
    }

  session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
  if (session_bus == NULL)
    {
      g_printerr ("No session bus: %s\n", error->message);
      do_exit (3);
    }

  permission_store = xdg_app_permission_store_proxy_new_sync (session_bus,G_DBUS_PROXY_FLAGS_NONE,
                                                              "org.freedesktop.XdgApp",
                                                              "/org/freedesktop/XdgApp/PermissionStore",
                                                              NULL, &error);
  if (permission_store == NULL)
    {
      g_print ("No permission store: %s\n", error->message);
      do_exit (4);
    }

  /* We want do do our custom post-mainloop exit */
  g_dbus_connection_set_exit_on_close (session_bus, FALSE);

  g_signal_connect (session_bus, "closed", G_CALLBACK (session_bus_closed), NULL);

  if (set_one_signal_handler(SIGHUP, exit_handler, 0) == -1 ||
      set_one_signal_handler(SIGINT, exit_handler, 0) == -1 ||
      set_one_signal_handler(SIGTERM, exit_handler, 0) == -1 ||
      set_one_signal_handler(SIGPIPE, SIG_IGN, 0) == -1)
    {
      do_exit (5);
    }

  introspection_bytes = g_resources_lookup_data ("/org/freedesktop/portal/Documents/org.freedesktop.portal.Documents.xml", 0, NULL);
  g_assert (introspection_bytes != NULL);

  introspection_data = g_dbus_node_info_new_for_xml (g_bytes_get_data (introspection_bytes, NULL), NULL);

  owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
                             "org.freedesktop.portal.Documents",
                             G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | (opt_replace ? G_BUS_NAME_OWNER_FLAGS_REPLACE : 0),
                             on_bus_acquired,
                             on_name_acquired,
                             on_name_lost,
                             NULL,
                             NULL);

  g_main_loop_run (loop);

  xdp_fuse_exit ();

  g_bus_unown_name (owner_id);

  g_dbus_node_info_unref (introspection_data);

  do_exit (final_exit_status);

  return 0;
}
int
main (int argc, char **argv)
{
    GError *error = NULL;
    GDBusConnection *gdbus = NULL;
    GDBusConnection *gdbus_system = NULL;
    DBusConnection *connection = NULL;
    int ret = 1;
    GMainLoop *teardown_loop;
    guint linger_time = 5;

    g_type_init ();

    g_set_application_name ("Mission Control regression tests");

    mcd_debug_init ();
    tp_debug_set_flags (g_getenv ("MC_TP_DEBUG"));

    /* Not all warnings are fatal due to MC spamming warnings (fd.o #23486),
     * but GLib and GObject warnings are pretty serious */
    g_log_set_fatal_mask ("GLib",
        G_LOG_FATAL_MASK | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
    g_log_set_fatal_mask ("GLib-GObject",
        G_LOG_FATAL_MASK | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);

    gdbus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
    g_assert_no_error (error);
    g_assert (gdbus != NULL);
    g_dbus_connection_set_exit_on_close (gdbus, FALSE);

    gdbus_system = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
    g_assert_no_error (error);
    g_assert (gdbus_system != NULL);
    g_dbus_connection_set_exit_on_close (gdbus_system, FALSE);

    bus_daemon = tp_dbus_daemon_dup (&error);
    g_assert_no_error (error);
    g_assert (bus_daemon != NULL);

    /* It appears that dbus-glib registers a filter that wrongly returns
     * DBUS_HANDLER_RESULT_HANDLED for signals, so for *our* filter to have any
     * effect, we need to install it as soon as possible */
    connection = dbus_g_connection_get_connection (
	tp_proxy_get_dbus_connection (bus_daemon));
    dbus_connection_add_filter (connection, dbus_filter_function, NULL, NULL);

    mcd = mcd_service_new ();

    /* Listen for suicide notification */
    g_signal_connect_after (mcd, "abort", G_CALLBACK (on_abort), NULL);

    /* connect */
    mcd_mission_connect (MCD_MISSION (mcd));

    dbus_connection_set_exit_on_disconnect (connection, FALSE);

    mcd_service_run (MCD_OBJECT (mcd));

    ret = 0;

    teardown_loop = g_main_loop_new (NULL, FALSE);

    if (g_getenv ("MC_LINGER_TIME") != NULL)
      {
        linger_time = g_ascii_strtoull (g_getenv ("MC_LINGER_TIME"), NULL, 10);
      }

    /* Keep running in the background until it's all over. This means valgrind
     * and refdbg can get complete information. */
    g_timeout_add_seconds_full (G_PRIORITY_DEFAULT, linger_time, the_end,
        teardown_loop, (GDestroyNotify) g_main_loop_unref);

    g_main_loop_run (teardown_loop);

    if (connection != NULL)
    {
        dbus_connection_flush (connection);
    }

    tp_clear_object (&gdbus);
    tp_clear_object (&gdbus_system);
    tp_clear_object (&bus_daemon);

    dbus_shutdown ();

    g_message ("Exiting with %d", ret);

    return ret;
}
コード例 #16
0
gboolean
e_mapi_util_trigger_krb_auth (const EMapiProfileData *empd,
			      GError **error)
{
	gint success = FALSE;
	GError *local_error = NULL;
	GDBusConnection *connection;
	GDBusMessage *message, *reply;
	gchar *name;

	connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &local_error);
	if (local_error) {
		g_warning ("could not get system bus: %s\n",
			   local_error->message);
		g_propagate_error (error, local_error);
		return FALSE;
	}

	g_dbus_connection_set_exit_on_close (connection, FALSE);
	/* Create a new message on the KRB_DBUS_INTERFACE */
	message = g_dbus_message_new_method_call (KRB_DBUS_INTERFACE,
						  KRB_DBUS_PATH,
						  KRB_DBUS_INTERFACE,
						  "acquireTgt");
	if (!message) {
		g_object_unref (connection);
		return FALSE;
	}

	/* Appends the data as an argument to the message */
	name = g_strdup_printf ("%s@%s", empd->username, empd->krb_realm);
	g_dbus_message_set_body (message, g_variant_new ("(s)", name));

	/* Sends the message: Have a 300 sec wait timeout  */
	reply = g_dbus_connection_send_message_with_reply_sync (connection, message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 300 * 1000, NULL, NULL, &local_error);
	g_free (name);

	if (!local_error && reply) {
		if (g_dbus_message_to_gerror (reply, &local_error)) {
			g_object_unref (reply);
			reply = NULL;
		}
	}

	if (local_error) {
		g_dbus_error_strip_remote_error (local_error);
		g_propagate_error (error, local_error);
	}

	if (reply) {
		GVariant *body = g_dbus_message_get_body (reply);
		if (body) {
			g_variant_get (body, "(b)", &success);
		}
		g_object_unref (reply);
	}

	/* Free the message */
	g_object_unref (message);
	g_object_unref (connection);

	return success && !local_error;
}