gboolean gsm_consolekit_can_switch_user (GsmConsolekit *manager) { GError *error; char *seat_id; gboolean ret; error = NULL; if (!gsm_consolekit_ensure_ck_connection (manager, &error)) { g_warning ("Could not connect to ConsoleKit: %s", error->message); g_error_free (error); return FALSE; } seat_id = get_current_seat_id (dbus_g_connection_get_connection (manager->priv->dbus_connection)); if (seat_id == NULL || seat_id[0] == '\0') { g_debug ("seat id is not set; can't switch sessions"); return FALSE; } ret = seat_can_activate_sessions (dbus_g_connection_get_connection (manager->priv->dbus_connection), seat_id); g_free (seat_id); return ret; }
static void verve_dbus_service_init (VerveDBusService *dbus_service) { GError *error = NULL; /* Try to connect to the session bus */ dbus_service->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (G_LIKELY (dbus_service->connection != NULL)) { /* Register the /org/xfce/RunDialog object for Verve */ dbus_g_connection_register_g_object (dbus_service->connection, "/org/xfce/RunDialog", G_OBJECT (dbus_service)); /* Request service names */ #ifdef HAVE_DBUS_NEW_FLAGS dbus_bus_request_name (dbus_g_connection_get_connection (dbus_service->connection), "org.xfce.Verve", DBUS_NAME_FLAG_REPLACE_EXISTING|DBUS_NAME_FLAG_ALLOW_REPLACEMENT, NULL); dbus_bus_request_name (dbus_g_connection_get_connection (dbus_service->connection), "org.xfce.RunDialog", DBUS_NAME_FLAG_REPLACE_EXISTING|DBUS_NAME_FLAG_ALLOW_REPLACEMENT, NULL); #else dbus_bus_request_name (dbus_g_connection_get_connection (dbus_service->connection), "org.xfce.Verve", DBUS_NAME_FLAG_REPLACE_EXISTING, NULL); dbus_bus_request_name (dbus_g_connection_get_connection (dbus_service->connection), "org.xfce.RunDialog", DBUS_NAME_FLAG_REPLACE_EXISTING, NULL); #endif /* !HAVE_DBUS_NEW_FLAGS */ } else { /* Notify the user that D-BUS won't be a available */ g_fprintf (stderr, "Verve: Failed to connect to the D-BUS session bus: %s\n", error->message); g_error_free (error); } }
static char * _fprint_device_check_for_username (FprintDevice *rdev, DBusGMethodInvocation *context, const char *username, char **ret_sender, GError **error) { DBusConnection *conn; DBusError dbus_error; char *sender; unsigned long uid; struct passwd *user; char *client_username; /* Get details about the current sender, and username/uid */ conn = dbus_g_connection_get_connection (fprintd_dbus_conn); sender = dbus_g_method_get_sender (context); dbus_error_init (&dbus_error); uid = dbus_bus_get_unix_user (conn, sender, &dbus_error); if (dbus_error_is_set(&dbus_error)) { g_free (sender); dbus_set_g_error (error, &dbus_error); return NULL; } user = getpwuid (uid); if (user == NULL) { g_free (sender); g_set_error(error, FPRINT_ERROR, FPRINT_ERROR_INTERNAL, "Failed to get information about user UID %lu", uid); return NULL; } client_username = g_strdup (user->pw_name); /* The current user is usually allowed to access their * own data, this should be followed by PolicyKit checks * anyway */ if (username == NULL || *username == '\0' || g_str_equal (username, client_username)) { if (ret_sender != NULL) *ret_sender = sender; else g_free (sender); return client_username; } /* If we're not allowed to set a different username, * then fail */ if (_fprint_device_check_polkit_for_action (rdev, context, "net.reactivated.fprint.device.setusername", error) == FALSE) { g_free (sender); return NULL; } if (ret_sender != NULL) *ret_sender = sender; else g_free (sender); return g_strdup (username); }
static char * gconf_address_for_caller (GConfDefaults *mechanism, DBusGMethodInvocation *context, GError **gerror) { char *sender; DBusConnection *conn; uid_t uid; struct passwd *pwd; char *result; DBusError error; conn = dbus_g_connection_get_connection (mechanism->priv->system_bus_connection); sender = dbus_g_method_get_sender (context); dbus_error_init (&error); uid = dbus_bus_get_unix_user (conn, sender, &error); g_free (sender); if (uid == (unsigned)-1) { dbus_set_g_error (gerror, &error); dbus_error_free (&error); return NULL; } pwd = getpwuid (uid); if (pwd == NULL) { g_set_error (gerror, 0, 0, "Failed to get passwd information for uid %d", uid); return NULL; } result = g_strconcat ("xml:merged:", pwd->pw_dir, "/.gconf", NULL); return result; }
/* To support the BOT */ static void __unregister_agent_authorize_signal( obex_server_info_t *obex_server_info) { DBG("+"); DBusConnection *dbus_connection = NULL; if (obex_server_info == NULL) { DBG("info is NULL"); return; } if (obex_server_info->system_bus == NULL) { DBG("connection is NULL"); return; } dbus_connection = dbus_g_connection_get_connection( obex_server_info->system_bus); dbus_connection_remove_filter(dbus_connection, __obex_authorize_event_filter, NULL); dbus_g_connection_unref(obex_server_info->system_bus); obex_server_info->system_bus = NULL; if (vconf_set_int(BT_MEMORY_OBEX_NO_AGENT, 0) != 0) DBG("Set vconf failed"); DBG("-"); }
bool Skype::createDBusProxy() { if (m_proxy == NULL) { LOG4CXX_INFO(logger, "Creating DBus proxy for com.Skype.Api."); m_counter++; GError *error = NULL; m_proxy = dbus_g_proxy_new_for_name_owner(m_connection, "com.Skype.API", "/com/Skype", "com.Skype.API", &error); if (m_proxy == NULL && error != NULL) { LOG4CXX_INFO(logger, m_username << ":" << error->message); if (m_counter == MAX_SKYPE_DBUS_RETRIES) { LOG4CXX_ERROR(logger, "Logging out, proxy couldn't be created: " << error->message); m_np->handleDisconnected(m_user, pbnetwork::CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, error->message); logout(); g_error_free(error); return FALSE; } g_error_free(error); } if (m_proxy) { LOG4CXX_INFO(logger, "Proxy created."); DBusObjectPathVTable vtable; vtable.message_function = &skype_notify_handler; dbus_connection_register_object_path(dbus_g_connection_get_connection(m_connection), "/com/Skype/Client", &vtable, this); m_counter = 0; m_timer = g_timeout_add_seconds(1, load_skype_buddies, this); g_timeout_add_seconds(10, skype_check_missedmessages, this); return FALSE; } return TRUE; } return FALSE; }
int main (int argv, char ** argc) { g_type_init(); g_debug("Waiting to init."); GError * error = NULL; DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if (error != NULL) { g_error("Unable to get session bus: %s", error->message); return 1; } DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); gboolean has_owner = FALSE; gint owner_count = 0; while (!has_owner && owner_count < 10000) { org_freedesktop_DBus_name_has_owner(bus_proxy, "org.test", &has_owner, NULL); owner_count++; } if (owner_count == 10000) { g_error("Unable to get name owner after 10000 tries"); return 1; } g_usleep(500000); g_debug("Initing"); guint nameret = 0; if (!org_freedesktop_DBus_request_name(bus_proxy, NOTIFICATION_WATCHER_DBUS_ADDR, 0, &nameret, &error)) { g_error("Unable to call to request name"); return 1; } if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { g_error("Unable to get name"); return 1; } dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_filter, NULL, NULL); /* This is the final kill function. It really shouldn't happen unless we get an error. */ g_timeout_add(2000, kill_func, NULL); g_debug("Entering Mainloop"); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); g_debug("Exiting"); return 0; }
static void setup_network_monitor (MateWeatherApplet *gw_applet) { GError *error; static DBusGConnection *bus = NULL; DBusConnection *dbus; if (bus == NULL) { error = NULL; bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (bus == NULL) { g_warning ("Couldn't connect to system bus: %s", error->message); g_error_free (error); return; } dbus = dbus_g_connection_get_connection (bus); dbus_connection_add_filter (dbus, filter_func, gw_applet, NULL); dbus_bus_add_match (dbus, "type='signal'," "interface='" NM_DBUS_INTERFACE "'", NULL); } }
gboolean _init_dbus_signal(void) { DBG("+\n"); DBusGConnection *conn; GError *err = NULL; DBusError dbus_error; conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &err); if(!conn) { ERR(" DBUS get failed\n"); g_error_free(err); return FALSE; } dbus_connection = dbus_g_connection_get_connection(conn); /* Add the filter for network client functions */ dbus_error_init(&dbus_error); dbus_connection_add_filter(dbus_connection, __dbus_event_filter, NULL, NULL); dbus_bus_add_match(dbus_connection, "type=signal,interface=" NETWORK_SERIAL_INTERFACE ",member=ready_for_serial", &dbus_error); if (dbus_error_is_set(&dbus_error)) { ERR("Fail to add dbus filter signal\n"); dbus_error_free(&dbus_error); } DBG("-\n"); return TRUE; }
/** * hd_status_plugin_item_get_dbus_g_connection: * @item: A #HDStatusPluginItem * @type: The #DBusBusType %DBUS_BUS_SESSION or %DBUS_BUS_SYSTEM * @error: A #GError to return error messages * * Creates a new #DBusGConnection to the D-Bus session or system bus. * * Internally, calls dbus_g_bus_get(). See there for further informations. * * Returns: A shared connection. **/ DBusGConnection * hd_status_plugin_item_get_dbus_g_connection (HDStatusPluginItem *item, DBusBusType type, GError **error) { DBusGConnection *g_connection; DBusConnection *connection; GError *tmp_error = NULL; g_return_val_if_fail (HD_IS_STATUS_PLUGIN_ITEM (item), NULL); /* Create a DBusGConnection (not private yet) */ g_connection = dbus_g_bus_get (type, &tmp_error); if (tmp_error != NULL) { g_propagate_error (error, tmp_error); return NULL; } connection = dbus_g_connection_get_connection (g_connection); /* Log the connection name for debug purposes */ g_debug ("Plugin '%s' opened D-Bus connection '%s'.", hd_status_plugin_item_get_dl_filename (item), dbus_bus_get_unique_name (connection)); return g_connection; }
static void hd_panel_window_dialog_notify_condition (GObject *object, gboolean condition, HDPanelWindowDialog *window) { gboolean real_condition = FALSE; g_object_get (G_OBJECT (object), "condition", &real_condition, NULL); g_signal_emit_by_name (window, "update-status", HILDON_DESKTOP_ITEM (object)->id, real_condition); /* Some day instropection will work for GObject signals and this code won't make any sense */ DBusMessage *message; message = dbus_message_new_signal ("/org/hildon/Statusbar", "org.hildon.Statusbar", "UpdateStatus"); dbus_message_append_args (message, DBUS_TYPE_STRING, &(HILDON_DESKTOP_ITEM (object)->id), DBUS_TYPE_BOOLEAN, &real_condition, DBUS_TYPE_INVALID); dbus_connection_send (dbus_g_connection_get_connection(window->priv->connection), message, NULL); dbus_message_unref (message); }
void init_dbus() { GError *error = NULL; DBusConnection *local_conn; main_thread = g_thread_self(); info_mutex = g_mutex_new(); info_cond = g_cond_new(); AUDDBG ("Trying to initialize D-Bus.\n"); dbus_conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if (dbus_conn == NULL) { g_warning("Unable to connect to dbus: %s", error->message); g_error_free(error); return; } g_type_init(); g_object_new(audacious_rc_get_type(), NULL); g_object_new(mpris_root_get_type(), NULL); mpris = g_object_new(mpris_player_get_type(), NULL); g_object_new(mpris_tracklist_get_type(), NULL); local_conn = dbus_g_connection_get_connection(dbus_conn); dbus_connection_set_exit_on_disconnect(local_conn, FALSE); }
static DBusGConnection * get_session_bus (void) { GError *error; DBusGConnection *bus; DBusConnection *connection; error = NULL; bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (bus == NULL) { g_warning ("Couldn't connect to session bus: %s", error->message); g_error_free (error); goto out; } connection = dbus_g_connection_get_connection (bus); dbus_connection_add_filter (connection, (DBusHandleMessageFunction) bus_message_handler, NULL, NULL); dbus_connection_set_exit_on_disconnect (connection, FALSE); out: return bus; }
static void mcd_client_registry_dispose (GObject *object) { McdClientRegistry *self = MCD_CLIENT_REGISTRY (object); void (*chain_up) (GObject *) = G_OBJECT_CLASS (_mcd_client_registry_parent_class)->dispose; if (self->priv->dbus_daemon != NULL) { DBusGConnection *gconn = tp_proxy_get_dbus_connection (self->priv->dbus_daemon); DBusConnection *dconn = dbus_g_connection_get_connection (gconn); dbus_connection_remove_filter (dconn, mcd_client_registry_name_owner_filter, self); } tp_clear_object (&self->priv->dbus_daemon); if (self->priv->clients != NULL) { g_hash_table_foreach (self->priv->clients, mcd_client_registry_disconnect_client_signals, self); } tp_clear_pointer (&self->priv->clients, g_hash_table_unref); if (chain_up != NULL) chain_up (object); }
static void gui_dbus_service_init (Gimp *gimp) { GError *error = NULL; g_return_if_fail (GIMP_IS_GIMP (gimp)); g_return_if_fail (dbus_connection == NULL); dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (dbus_connection) { GObject *service = gimp_dbus_service_new (gimp); dbus_bus_request_name (dbus_g_connection_get_connection (dbus_connection), GIMP_DBUS_SERVICE_NAME, 0, NULL); dbus_g_connection_register_g_object (dbus_connection, GIMP_DBUS_SERVICE_PATH, service); } else { g_printerr ("%s\n", error->message); g_error_free (error); } }
gint main (gint argc, gchar * argv[]) { GError * error = NULL; DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if (error != NULL) { g_error("Unable to get session bus: %s", error->message); return 1; } DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(session_bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); guint nameret = 0; if (!org_freedesktop_DBus_request_name(bus_proxy, NOTIFICATION_WATCHER_DBUS_ADDR, 0, &nameret, &error)) { g_error("Unable to call to request name"); return 1; } if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { g_error("Unable to get name"); return 1; } dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_reg_filter, NULL, NULL); dbus_connection_add_filter(dbus_g_connection_get_connection(session_bus), dbus_filter, NULL, NULL); dbus_bus_add_match(dbus_g_connection_get_connection(session_bus), "type='signal',interface='" NOTIFICATION_ITEM_DBUS_IFACE "',member='NewStatus'", NULL); watchdog_hit = TRUE; g_timeout_add_seconds(20, kill_func, NULL); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); if (passed) { g_debug("Quiting"); return 0; } else { g_debug("Quiting as we're a failure"); return 1; } return 0; }
static gboolean init_udisks_connection(void) { GError *error; error = NULL; if (dbus_bus == NULL) { dbus_bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); if (dbus_bus == NULL) { g_message("Error connecting to message bus: %s", error->message); g_error_free(error); return FALSE; } // faggots from #dbus may go screw themselves dbus_connection_set_exit_on_disconnect(dbus_g_connection_get_connection(dbus_bus), FALSE); dbus_connection_add_filter(dbus_g_connection_get_connection(dbus_bus), signal_filter, NULL, NULL); } if (udisks_proxy == NULL) { udisks_proxy = dbus_g_proxy_new_for_name(dbus_bus, "org.freedesktop.UDisks", "/org/freedesktop/UDisks", "org.freedesktop.UDisks"); dbus_g_proxy_add_signal(udisks_proxy, "DeviceAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_add_signal(udisks_proxy, "DeviceRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_add_signal(udisks_proxy, "DeviceChanged", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_add_signal(udisks_proxy, "DeviceJobChanged", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_BOOLEAN, G_TYPE_DOUBLE, G_TYPE_INVALID); dbus_g_proxy_connect_signal(udisks_proxy, "DeviceAdded", G_CALLBACK(udisks_device_added), NULL, NULL); dbus_g_proxy_connect_signal(udisks_proxy, "DeviceRemoved", G_CALLBACK(udisks_device_removed), NULL, NULL); dbus_g_proxy_connect_signal(udisks_proxy, "DeviceChanged", G_CALLBACK(udisks_device_changed), NULL, NULL); dbus_g_proxy_connect_signal(udisks_proxy, "DeviceJobChanged", G_CALLBACK(udisks_device_job_changed), NULL, NULL); } return TRUE; }
NS_IMETHODIMP nsGIOService::OrgFreedesktopFileManager1ShowItems(const nsACString& aPath) { #ifndef MOZ_ENABLE_DBUS return NS_ERROR_FAILURE; #else GError* error = nullptr; static bool org_freedesktop_FileManager1_exists = true; if (!org_freedesktop_FileManager1_exists) { return NS_ERROR_NOT_AVAILABLE; } DBusGConnection* dbusGConnection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if (!dbusGConnection) { if (error) { g_printerr("Failed to open connection to session bus: %s\n", error->message); g_error_free(error); } return NS_ERROR_FAILURE; } char *uri = g_filename_to_uri(PromiseFlatCString(aPath).get(), nullptr, nullptr); if (uri == nullptr) { return NS_ERROR_FAILURE; } DBusConnection* dbusConnection = dbus_g_connection_get_connection(dbusGConnection); // Make sure we do not exit the entire program if DBus connection get lost. dbus_connection_set_exit_on_disconnect(dbusConnection, false); DBusGProxy* dbusGProxy = dbus_g_proxy_new_for_name(dbusGConnection, "org.freedesktop.FileManager1", "/org/freedesktop/FileManager1", "org.freedesktop.FileManager1"); const char *uris[2] = { uri, nullptr }; gboolean rv_dbus_call = dbus_g_proxy_call (dbusGProxy, "ShowItems", nullptr, G_TYPE_STRV, uris, G_TYPE_STRING, "", G_TYPE_INVALID, G_TYPE_INVALID); g_object_unref(dbusGProxy); dbus_g_connection_unref(dbusGConnection); g_free(uri); if (!rv_dbus_call) { org_freedesktop_FileManager1_exists = false; return NS_ERROR_NOT_AVAILABLE; } return NS_OK; #endif }
static gboolean billy_idle (gpointer user_data) { DBusMessage *reply = user_data; DBusConnection *connection = dbus_g_connection_get_connection ( tp_proxy_get_dbus_connection (bus_daemon)); if (!dbus_connection_send (connection, reply, NULL)) g_error ("Out of memory"); return FALSE; }
static gboolean check_polkit_for_action (GConfDefaults *mechanism, DBusGMethodInvocation *context, const char *action) { const char *sender; GError *error; DBusError dbus_error; PolKitCaller *pk_caller; PolKitAction *pk_action; PolKitResult pk_result; error = NULL; /* Check that caller is privileged */ sender = dbus_g_method_get_sender (context); dbus_error_init (&dbus_error); pk_caller = polkit_caller_new_from_dbus_name ( dbus_g_connection_get_connection (mechanism->priv->system_bus_connection), sender, &dbus_error); if (pk_caller == NULL) { error = g_error_new (GCONF_DEFAULTS_ERROR, GCONF_DEFAULTS_ERROR_GENERAL, "Error getting information about caller: %s: %s", dbus_error.name, dbus_error.message); dbus_error_free (&dbus_error); dbus_g_method_return_error (context, error); g_error_free (error); return FALSE; } pk_action = polkit_action_new (); polkit_action_set_action_id (pk_action, action); pk_result = polkit_context_is_caller_authorized (mechanism->priv->pol_ctx, pk_action, pk_caller, TRUE, NULL); polkit_caller_unref (pk_caller); if (pk_result != POLKIT_RESULT_YES) { dbus_error_init (&dbus_error); polkit_dbus_error_generate (pk_action, pk_result, &dbus_error); dbus_set_g_error (&error, &dbus_error); dbus_g_method_return_error (context, error); dbus_error_free (&dbus_error); g_error_free (error); polkit_action_unref (pk_action); return FALSE; } polkit_action_unref (pk_action); return TRUE; }
/* To support the BOT */ static int __register_agent_authorize_signal( obex_server_info_t *obex_server_info) { DBG("+"); DBusGConnection *conn = NULL; DBusConnection *dbus_connection = NULL; DBusError dbus_error; conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); if (conn == NULL) { DBG("conn is NULL\n"); return BLUETOOTH_ERROR_NO_RESOURCES; } dbus_connection = dbus_g_connection_get_connection(conn); /* Add the filter for authorize functions */ dbus_error_init(&dbus_error); dbus_connection_add_filter(dbus_connection, __obex_authorize_event_filter, NULL, NULL); dbus_bus_add_match(dbus_connection, "type=signal,interface=" BT_AGENT_INTERFACE ",member=ObexAuthorize", &dbus_error); if (dbus_error_is_set(&dbus_error)) { ERR("Fail to add dbus filter signal\n"); dbus_error_free(&dbus_error); dbus_connection_remove_filter(dbus_connection, __obex_authorize_event_filter, NULL); dbus_g_connection_unref(conn); return BLUETOOTH_ERROR_INTERNAL; } if (vconf_set_int(BT_MEMORY_OBEX_NO_AGENT, 1) != 0) { DBG("Set vconf failed"); dbus_connection_remove_filter(dbus_connection, __obex_authorize_event_filter, NULL); dbus_g_connection_unref(conn); return BLUETOOTH_ERROR_INTERNAL; } obex_server_info->system_bus = conn; DBG("-"); return BLUETOOTH_ERROR_NONE; }
static gboolean _check_polkit_for_action (GnomeClockAppletMechanism *mechanism, DBusGMethodInvocation *context, const char *action) { const char *sender; GError *error; DBusError dbus_error; PolKitCaller *pk_caller; PolKitAction *pk_action; PolKitResult pk_result; error = NULL; /* Check that caller is privileged */ sender = dbus_g_method_get_sender (context); dbus_error_init (&dbus_error); pk_caller = polkit_caller_new_from_dbus_name ( dbus_g_connection_get_connection (mechanism->priv->system_bus_connection), sender, &dbus_error); if (pk_caller == NULL) { error = g_error_new (GNOME_CLOCK_APPLET_MECHANISM_ERROR, GNOME_CLOCK_APPLET_MECHANISM_ERROR_GENERAL, "Error getting information about caller: %s: %s", dbus_error.name, dbus_error.message); dbus_error_free (&dbus_error); dbus_g_method_return_error (context, error); g_error_free (error); return FALSE; } pk_action = polkit_action_new (); polkit_action_set_action_id (pk_action, action); pk_result = polkit_context_can_caller_do_action (mechanism->priv->pol_ctx, pk_action, pk_caller); polkit_caller_unref (pk_caller); polkit_action_unref (pk_action); if (pk_result != POLKIT_RESULT_YES) { error = g_error_new (GNOME_CLOCK_APPLET_MECHANISM_ERROR, GNOME_CLOCK_APPLET_MECHANISM_ERROR_NOT_PRIVILEGED, "%s %s <-- (action, result)", action, polkit_result_to_string_representation (pk_result)); dbus_error_free (&dbus_error); dbus_g_method_return_error (context, error); g_error_free (error); return FALSE; } return TRUE; }
static gboolean galeon_dbus_connect_to_system_bus (GaleonDbus *galeon_dbus, GError **error) { GaleonDbusPrivate *priv = galeon_dbus->priv; // LOG ("GaleonDbus connecting to system DBUS"); priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, error); if (priv->system_bus == NULL) { g_warning ("Unable to connect to system bus: %s", error ? (*error)->message : ""); return FALSE; } if (dbus_g_connection_get_connection (priv->system_bus) == NULL) { g_warning ("DBus connection is null"); g_set_error (error, GALEON_DBUS_ERROR_QUARK, 0, "DBus connection is NULL"); return FALSE; } dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (priv->system_bus), FALSE); dbus_connection_add_filter (dbus_g_connection_get_connection (priv->system_bus), system_filter_func, galeon_dbus, NULL); g_signal_emit (galeon_dbus, signals[CONNECTED], 0, GALEON_DBUS_SYSTEM); return TRUE; }
static void galeon_dbus_shutdown (GaleonDbus *dbus) { GaleonDbusPrivate *priv = dbus->priv; // LOG ("GaleonDbus shutdown"); if (priv->session_reconnect_timeout_id != 0) { g_source_remove (priv->session_reconnect_timeout_id); priv->session_reconnect_timeout_id = 0; } if (priv->system_reconnect_timeout_id != 0) { g_source_remove (priv->system_reconnect_timeout_id); priv->system_reconnect_timeout_id = 0; } if (priv->session_bus) { dbus_connection_remove_filter (dbus_g_connection_get_connection (priv->session_bus), session_filter_func, dbus); dbus_g_connection_unref (priv->session_bus); priv->session_bus = NULL; } if (priv->system_bus) { dbus_connection_remove_filter (dbus_g_connection_get_connection (priv->system_bus), system_filter_func, dbus); dbus_g_connection_unref (priv->system_bus); priv->system_bus = NULL; } }
gboolean obexftp_init (void) { GError *err = NULL; connection = dbus_g_bus_get (DBUS_BUS_SESSION, &err); if (connection == NULL) { g_printerr ("Connecting to session bus failed: %s\n", err->message); g_error_free (err); return FALSE; } dbus_connection_set_exit_on_disconnect (dbus_g_connection_get_connection (connection), FALSE); return TRUE; }
static void modem_tones_init(ModemTones *self) { self->priv = G_TYPE_INSTANCE_GET_PRIVATE( self, MODEM_TYPE_TONES, ModemTonesPrivate); self->priv->connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, NULL); self->priv->timer = g_timer_new(); self->priv->ngf = ngf_client_create(NGF_TRANSPORT_DBUS, dbus_g_connection_get_connection(self->priv->connection)); ngf_client_set_callback(self->priv->ngf, ngf_callback, self); self->priv->event_id = 0; self->priv->notify_map = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, g_free); }
static DBusGConnection * get_system_bus (void) { GError *error; DBusGConnection *bus; error = NULL; bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (bus == NULL) { g_warning ("Couldn't connect to system bus: %s", error->message); g_error_free (error); goto out; } dbus_g_connection_get_connection (bus); out: return bus; }
static gboolean skype_connect() { GError *error = NULL; DBusObjectPathVTable vtable; //Initialise threading dbus_threads_init_default(); if (connection == NULL) { connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL && error != NULL) { skype_debug_info("skype_dbus", "Error: %s\n", error->message); g_error_free(error); return FALSE; } } if (proxy == NULL) { proxy = dbus_g_proxy_new_for_name_owner (connection, "com.Skype.API", "/com/Skype", "com.Skype.API", &error); if (proxy == NULL && error != NULL) { skype_debug_warning("skype_dbus", "%s\n", error->message); g_error_free(error); return FALSE; } g_signal_connect(G_OBJECT(proxy), "destroy", G_CALLBACK(skype_destroy_handler), NULL); #ifdef DBUS_MAJOR_VERSION dbus_g_proxy_set_default_timeout(proxy, 3000); #endif vtable.message_function = &skype_notify_handler; dbus_connection_register_object_path(dbus_g_connection_get_connection(connection), "/com/Skype/Client", &vtable, NULL); } return TRUE; }
/** * pk_connection_valid: * @connection: a valid #PkConnection instance * * Return value: %TRUE if packagekitd is running **/ gboolean pk_connection_valid (PkConnection *connection) { DBusError error; DBusConnection *conn; gboolean ret; g_return_val_if_fail (PK_IS_CONNECTION (connection), FALSE); /* get raw connection */ conn = dbus_g_connection_get_connection (connection->priv->connection); dbus_error_init (&error); ret = dbus_bus_name_has_owner (conn, PK_DBUS_SERVICE, &error); if (dbus_error_is_set (&error)) { egg_debug ("error: %s", error.message); dbus_error_free (&error); } return ret; }
static void watch_clients (McdClientRegistry *self) { TpDBusDaemon *dbus_daemon = self->priv->dbus_daemon; DBusGConnection *gconn = tp_proxy_get_dbus_connection (dbus_daemon); DBusConnection *dconn = dbus_g_connection_get_connection (gconn); DBusError error = { 0 }; #define MATCH_ITEM(t,x) #t "='" x "'" #define NAME_OWNER_RULE \ MATCH_ITEM (type, "signal") "," \ MATCH_ITEM (sender, DBUS_SERVICE_DBUS) "," \ MATCH_ITEM (interface, DBUS_INTERFACE_DBUS) "," \ MATCH_ITEM (member, "NameOwnerChanged") #define CLIENT_MATCH_RULE \ NAME_OWNER_RULE "," \ MATCH_ITEM (arg0namespace, "org.freedesktop.Telepathy.Client") if (!dbus_connection_add_filter (dconn, mcd_client_registry_name_owner_filter, self, NULL)) g_critical ("Could not add filter for NameOwnerChanged (out of memory?)"); dbus_error_init (&error); dbus_bus_add_match (dconn, CLIENT_MATCH_RULE, &error); if (dbus_error_is_set (&error)) { DEBUG ("Could not add client names match rule (D-Bus 1.6 required): %s", error.message); dbus_error_free (&error); dbus_bus_add_match (dconn, NAME_OWNER_RULE, &error); if (dbus_error_is_set (&error)) { g_critical ("Could not add all dbus names match rule: %s", error.message); dbus_error_free (&error); } } }