static gboolean bus_register (DBusGConnection *bus) { DBusGProxy *bus_proxy; gboolean ret; mate_settings_profile_start (NULL); ret = FALSE; bus_proxy = get_bus_proxy (bus); if (bus_proxy == NULL) { g_warning ("Could not construct bus_proxy object"); goto out; } ret = acquire_name_on_proxy (bus_proxy); g_object_unref (bus_proxy); if (!ret) { g_warning ("Could not acquire name"); goto out; } g_debug ("Successfully connected to D-Bus"); out: mate_settings_profile_end (NULL); return ret; }
static gboolean acquire_name(void) { DBusGProxy* bus_proxy; GError* error; DBusGConnection* connection; error = NULL; connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if (connection == NULL) { gsm_util_init_error(TRUE, "Could not connect to session bus: %s", error->message); /* not reached */ } bus_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (!acquire_name_on_proxy(bus_proxy, GSM_DBUS_NAME)) { gsm_util_init_error(TRUE, "%s", "Could not acquire name on session bus"); /* not reached */ } g_object_unref(bus_proxy); return TRUE; }
int main (int argc, char **argv) { GMainLoop *loop; GsdDatetimeMechanism *mechanism; DBusGProxy *bus_proxy; DBusGConnection *connection; int ret; ret = 1; if (! g_thread_supported ()) { g_thread_init (NULL); } dbus_g_thread_init (); g_type_init (); connection = get_system_bus (); if (connection == NULL) { goto out; } bus_proxy = get_bus_proxy (connection); if (bus_proxy == NULL) { g_warning ("Could not construct bus_proxy object; bailing out"); goto out; } if (!acquire_name_on_proxy (bus_proxy) ) { g_warning ("Could not acquire name; bailing out"); goto out; } mechanism = gsd_datetime_mechanism_new (); if (mechanism == NULL) { goto out; } loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); g_object_unref (mechanism); g_main_loop_unref (loop); ret = 0; out: return ret; }
static gboolean acquire_name (void) { GError *error; DBusGConnection *connection; error = NULL; connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) { csm_util_init_error (TRUE, "Could not connect to session bus: %s", error->message); return FALSE; } bus_proxy = dbus_g_proxy_new_for_name_owner (connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, &error); if (error != NULL) { csm_util_init_error (TRUE, "Could not connect to session bus: %s", error->message); return FALSE; } g_signal_connect_swapped (bus_proxy, "destroy", G_CALLBACK (shutdown_cb), NULL); if (! acquire_name_on_proxy (bus_proxy, CSM_DBUS_NAME) ) { csm_util_init_error (TRUE, "%s", "Could not acquire name on session bus"); return FALSE; } return TRUE; }
int main (int argc, char **argv) { GMainLoop *main_loop; DBusGConnection *connection; DBusGProxy *bus_proxy; g_type_init (); connection = get_system_bus (); if (connection == NULL) { goto out; } bus_proxy = get_bus_proxy (connection); if (bus_proxy == NULL) { g_warning ("Could not construct bus_proxy object; bailing out"); goto out; } if (! acquire_name_on_proxy (bus_proxy) ) { g_warning ("Could not acquire name; bailing out"); goto out; } settings = gdm_settings_new (); if (settings == NULL) { g_warning ("Unable to initialize settings"); exit (1); } main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); g_main_loop_unref (main_loop); g_object_unref (settings); out: return 0; }
int main (int argc, char **argv) { GMainLoop *loop; GConfDefaults *mechanism; DBusGProxy *bus_proxy; DBusGConnection *connection; int ret; GOptionContext *options; GError *error = NULL; ret = 1; if (! g_thread_supported ()) { g_thread_init (NULL); } dbus_g_thread_init (); options = g_option_context_new (NULL); g_option_context_add_main_entries (options, entries, NULL); if (!g_option_context_parse (options, &argc, &argv, &error)) { g_warning ("Failed to parse options: %s\n", error->message); g_error_free (error); } g_option_context_free (options); g_log_set_default_handler (log_default_handler, NULL); if (debug) { log_levels = log_levels | G_LOG_LEVEL_DEBUG; } connection = get_system_bus (); if (connection == NULL) { g_warning ("Could not get system bus connection; bailing out"); goto out; } bus_proxy = get_bus_proxy (connection); if (bus_proxy == NULL) { g_warning ("Could not construct bus_proxy object; bailing out"); goto out; } mechanism = gconf_defaults_new (); if (mechanism == NULL) { goto out; } if (!acquire_name_on_proxy (bus_proxy)) { g_warning ("Could not acquire name; bailing out"); goto out; } loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); g_object_unref (mechanism); g_main_loop_unref (loop); ret = 0; out: return ret; }
int main (int argc, char *argv[]) { Daemon *daemon; DBusGConnection *bus; DBusGProxy *system_bus_proxy; GError *error; gint ret; GOptionContext *context; static gboolean replace; static gboolean show_version; static GOptionEntry entries[] = { { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Output version information and exit"), NULL }, { "replace", 0, 0, G_OPTION_ARG_NONE, &replace, N_("Replace existing instance"), NULL }, { "debug", 0, 0, G_OPTION_ARG_NONE, &debug, N_("Enable debugging code"), NULL }, { NULL } }; ret = 1; error = NULL; setlocale (LC_ALL, ""); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); g_type_init (); if (!g_setenv ("GIO_USE_VFS", "local", TRUE)) { g_warning ("Couldn't set GIO_USE_GVFS"); goto out; } context = g_option_context_new (""); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_set_summary (context, _("Provides D-Bus interfaces for querying and manipulating\nuser account information.")); g_option_context_add_main_entries (context, entries, NULL); error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { g_warning ("%s", error->message); g_error_free (error); goto out; } g_option_context_free (context); if (show_version) { g_print ("mateaccounts-daemon " VERSION "\n"); ret = 0; goto out; } g_log_set_default_handler (log_handler, NULL); bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (bus == NULL) { g_warning ("Could not connect to system bus: %s", error->message); g_error_free (error); goto out; } system_bus_proxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (system_bus_proxy == NULL) { g_warning ("Could not construct system_bus_proxy object"); goto out; } if (!acquire_name_on_proxy (system_bus_proxy, replace)) { g_warning ("Could not acquire name"); goto out; } daemon = daemon_new (); if (daemon == NULL) goto out; openlog ("mateaccounts-daemon", LOG_PID, LOG_DAEMON); syslog (LOG_INFO, "started daemon version %s", VERSION); closelog (); openlog ("mateaccounts-daemon", 0, LOG_AUTHPRIV); loop = g_main_loop_new (NULL, FALSE); g_debug ("entering main loop\n"); g_main_loop_run (loop); g_main_loop_unref (loop); ret = 0; out: return ret; }