void server_quit(void) { // QUARANTINE log_debug("@%s()", __FUNCTION__); // detach from database notifications database_set_changed_cb(0); database_set_restart_request_cb(0); // save data if we have unhandled changes server_changes_save(); // detach from dbus if( server_bus != 0 ) { dbus_connection_remove_filter(server_bus, server_filter, 0); dbus_connection_unref(server_bus); server_bus = 0; } }
//Removes a DBus filter previously added with add_dbus_filter. //Returns 0 on failure or 1 on success. //TODO: Cache DBus connection, since libxcdbus doesn't. int remove_dbus_filter(char * match, DBusHandleMessageFunction filter_func, void * func_data) { DBusConnection * connection; //Don't segfault if something else has already torn down the DBus connection. if (xcdbus_conn == NULL) { //xcpmd_log(LOG_WARNING, "Tried removing filter, but xcdbus connection is unavailable"); return 0; } connection = xcdbus_get_dbus_connection(xcdbus_conn); if (connection == NULL) { xcpmd_log(LOG_WARNING, "Unable to get dbus connection from xcdbus"); return 0; } dbus_bus_remove_match(connection, match, NULL); dbus_connection_remove_filter(connection, filter_func, func_data); return 1; }
int dbusrecv_uninit(dbusrecv_hdl_st *p_dbusrecv_hdl) { if (NULL == p_dbusrecv_hdl) { printf("dbusrecv_uninit: invalid parameter, p_dbusrecv_hdl!"); return -1; } if (p_dbusrecv_hdl->dbusloop) { _dbus_loop_quit (p_dbusrecv_hdl->dbusloop); sleep(2); } if (p_dbusrecv_hdl->connection) { test_connection_shutdown (p_dbusrecv_hdl->dbusloop, p_dbusrecv_hdl->connection); if (p_dbusrecv_hdl->filter_func) dbus_connection_remove_filter (p_dbusrecv_hdl->connection, p_dbusrecv_hdl->filter_func, NULL); dbus_connection_unref (p_dbusrecv_hdl->connection); p_dbusrecv_hdl->connection = NULL; } if (p_dbusrecv_hdl->dbusloop) { _dbus_loop_unref (p_dbusrecv_hdl->dbusloop); p_dbusrecv_hdl->dbusloop = NULL; } dbus_shutdown(); if (p_dbusrecv_hdl->dbusrecv_cfg.myname) { free(p_dbusrecv_hdl->dbusrecv_cfg.myname); p_dbusrecv_hdl->dbusrecv_cfg.myname = NULL; } free(p_dbusrecv_hdl); p_dbusrecv_hdl = NULL; _dbus_verbose("%s: service exiting!\n", __FILE__); return 0; }
void rd_release( rd_device *d) { if (!d) return; assert(d->ref > 0); if (--d->ref > 0) return; if (d->filtering) dbus_connection_remove_filter( d->connection, filter_handler, d); if (d->registered) dbus_connection_unregister_object_path( d->connection, d->object_path); if (d->owning) dbus_bus_release_name( d->connection, d->service_name, NULL); free(d->device_name); free(d->application_name); free(d->application_device_name); free(d->service_name); free(d->object_path); if (d->connection) dbus_connection_unref(d->connection); free(d); }
void DBus_Disconnect(Tcl_Interp *interp, Tcl_HashEntry *busPtr) { Tcl_DBusBus *data; Tcl_HashEntry *hPtr; Tcl_DBusMonitorData *snoop; data = Tcl_GetHashValue(busPtr); /* Find all paths with handlers registered by the interp */ DBus_InterpCleanup(interp, data->conn, "/"); /* Find all handlers of the interp without a path */ if (data->fallback != NULL) { if (DBus_HandlerCleanup(interp, data->fallback)) { ckfree((char *)data->fallback); data->fallback = NULL; } } /* Find snoop handlers */ hPtr = Tcl_FindHashEntry(data->snoop, (char *) interp); if (hPtr != NULL) { snoop = Tcl_GetHashValue(hPtr); if (snoop != NULL) { /* Uninstall the monitor script */ dbus_connection_remove_filter(data->conn, DBus_Monitor, snoop); Tcl_DecrRefCount(snoop->script); ckfree((char *) snoop); } Tcl_DeleteHashEntry(hPtr); if (Tcl_CheckHashEmpty(data->snoop)) { /* Last interpreter that was connected to the dbus */ Tcl_DeleteHashTable(data->snoop); ckfree((char *) data->snoop); if (data->type == N_BUS_TYPES) dbus_connection_unref(data->conn); ckfree((char *) data); if (defaultbus == data) defaultbus = NULL; Tcl_DeleteHashEntry(busPtr); } } }
NS_IMETHODIMP nsNativeAppSupportUnix::Stop(bool *aResult) { NS_ENSURE_ARG(aResult); *aResult = true; #if (MOZ_PLATFORM_MAEMO == 5) if (m_osso_context) { // Disable the accelerometer when closing OssoRequestAccelerometer(m_osso_context, false); // Remove the MCE callback filter DBusConnection *connnection = (DBusConnection*)osso_get_sys_dbus_connection(m_osso_context); dbus_connection_remove_filter(connnection, OssoModeControlCallback, nullptr); osso_hw_unset_event_cb(m_osso_context, nullptr); osso_rpc_unset_default_cb_f(m_osso_context, OssoDbusCallback, nullptr); osso_deinitialize(m_osso_context); m_osso_context = nullptr; } #endif return NS_OK; }
wxDBusConnection::wxDBusConnection(int ID, wxEvtHandler * EvtHandler, bool System) : m_filter_installed() { // Make sure libdbus locks its data structures, otherwise // there'll be crashes if it gets used from multiple threads // at the same time dbus_threads_init_default(); m_error = new wxDBusError; m_connection = System ? dbus_bus_get(DBUS_BUS_SYSTEM, &(m_error->GetError())) : dbus_bus_get(DBUS_BUS_SESSION, &(m_error->GetError())); if (!m_connection) { fprintf(stderr, "Failed to connect to D-BUS: %s\n", m_error->GetError().message); m_thread = NULL; } else { m_filter_installed = dbus_connection_add_filter(m_connection, handle_message, (void *) this, NULL); m_ID = ID; m_EvtHandler = EvtHandler; m_thread = new DBusThread(wxTHREAD_JOINABLE, this, ID, m_connection); if (!m_thread->Init()) { fprintf(stderr, "Failed to create worker thread\n"); delete m_thread; m_thread = NULL; if (m_filter_installed) { dbus_connection_remove_filter(m_connection, handle_message, (void *) this); m_filter_installed = false; } dbus_connection_unref(m_connection); m_connection = 0; } } }
void _bluetooth_network_client_remove_filter(void) { DBG("+\n"); bt_info_t *bt_internal_info = NULL; DBusError dbus_error; bt_internal_info = _bluetooth_internal_get_information(); if (bt_internal_info->sys_conn == NULL) { DBG("sys_conn is NULL"); return; } /* Add the filter for network client functions */ dbus_error_init(&dbus_error); dbus_connection_remove_filter(bt_internal_info->sys_conn, __bluetooth_network_event_filter, NULL); bt_internal_info->sys_conn = NULL; DBG("-\n"); }
static void gsm_consolekit_free_dbus (GsmConsolekit *manager) { if (manager->priv->bus_proxy != NULL) { g_object_unref (manager->priv->bus_proxy); manager->priv->bus_proxy = NULL; } if (manager->priv->ck_proxy != NULL) { g_object_unref (manager->priv->ck_proxy); manager->priv->ck_proxy = NULL; } if (manager->priv->dbus_connection != NULL) { DBusConnection *connection; connection = dbus_g_connection_get_connection (manager->priv->dbus_connection); dbus_connection_remove_filter (connection, gsm_consolekit_dbus_filter, manager); dbus_g_connection_unref (manager->priv->dbus_connection); manager->priv->dbus_connection = NULL; } }
static void open_shutdown_private_connection (dbus_bool_t use_guid) { DBusError error; DBusLoop *loop; DBusConnection *session; DBusMessage *msg; DBusMessage *reply; DBusConnection *privconn; char *addr; dbus_bool_t service_died; dbus_bool_t private_conn_lost; dbus_error_init (&error); service_died = FALSE; private_conn_lost = FALSE; loop = _dbus_loop_new (); session = dbus_bus_get (DBUS_BUS_SESSION, &error); if (!session) die ("couldn't access session bus\n"); dbus_connection_set_exit_on_disconnect (session, FALSE); test_connection_setup (loop, session); dbus_bus_add_match (session, PRIVSERVER_DIED_RULE, &error); if (dbus_error_is_set (&error)) die ("couldn't add match rule \"%s\": %s: %s", PRIVSERVER_DIED_RULE, error.name, error.message); if (!dbus_connection_add_filter (session, filter_session_message, &service_died, NULL)) die ("couldn't add filter to session bus\n"); msg = dbus_message_new_method_call (PRIVSERVER_SERVICE, "/", PRIVSERVER_INTERFACE, "GetPrivateAddress"); if (!(reply = dbus_connection_send_with_reply_and_block (session, msg, -1, &error))) die ("couldn't send message: %s\n", error.message); dbus_message_unref (msg); if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &addr, DBUS_TYPE_INVALID)) die ("couldn't parse message replym\n"); printf ("# got private temp address %s\n", addr); addr = strdup (addr); if (!use_guid) { char *comma = strrchr (addr, ','); if (comma) *comma = '\0'; } privconn = dbus_connection_open (addr, &error); free (addr); if (!privconn) die ("couldn't connect to server direct connection: %s\n", error.message); dbus_message_unref (reply); dbus_connection_set_exit_on_disconnect (privconn, FALSE); if (!dbus_connection_add_filter (privconn, filter_private_message, &private_conn_lost, NULL)) die ("couldn't add filter to private connection\n"); test_connection_setup (loop, privconn); msg = dbus_message_new_method_call (PRIVSERVER_SERVICE, "/", PRIVSERVER_INTERFACE, "Quit"); if (!dbus_connection_send (session, msg, NULL)) die ("couldn't send Quit message\n"); dbus_message_unref (msg); while (!service_died || !private_conn_lost) _dbus_loop_iterate (loop, TRUE); dbus_connection_remove_filter (session, filter_session_message, &service_died); dbus_bus_remove_match (session, PRIVSERVER_DIED_RULE, NULL); test_connection_shutdown (loop, session); dbus_connection_unref (session); test_connection_shutdown (loop, privconn); dbus_connection_remove_filter (privconn, filter_private_message, &private_conn_lost); dbus_connection_unref (privconn); _dbus_loop_unref (loop); }
int tool_cmd_scan(int argc, char *argv[]) { int ret = 0; int c; int timeout = DEFAULT_TIMEOUT_IN_SECONDS * 1000; DBusConnection* connection = NULL; DBusMessage *message = NULL; DBusMessage *reply = NULL; DBusPendingCall *pending = NULL; DBusError error; int32_t scan_period = 0; uint32_t channel_mask = 0; dbus_error_init(&error); while (1) { static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"timeout", required_argument, 0, 't'}, {"channel", required_argument, 0, 'c'}, {0, 0, 0, 0} }; int option_index = 0; c = getopt_long(argc, argv, "hc:t:", long_options, &option_index); if (c == -1) break; switch (c) { case 'h': print_arg_list_help(scan_option_list, argv[0], scan_cmd_syntax); ret = ERRORCODE_HELP; goto bail; case 't': timeout = strtol(optarg, NULL, 0); break; case 'c': channel_mask = strtomask_uint32(optarg); break; } } if (optind < argc) { if (scan_period == 0) { scan_period = strtol(argv[optind], NULL, 0); optind++; } } if (optind < argc) { fprintf(stderr, "%s: error: Unexpected extra argument: \"%s\"\n", argv[0], argv[optind]); ret = ERRORCODE_BADARG; goto bail; } if (gInterfaceName[0] == 0) { fprintf(stderr, "%s: error: No WPAN interface set (use the `cd` command, or the `-I` argument for `wpanctl`).\n", argv[0]); ret = ERRORCODE_BADARG; goto bail; } connection = dbus_bus_get(DBUS_BUS_STARTER, &error); if (!connection) { dbus_error_free(&error); dbus_error_init(&error); connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error); } require_string(connection != NULL, bail, error.message); dbus_bus_add_match(connection, gDBusObjectManagerMatchString, &error); require_string(error.name == NULL, bail, error.message); dbus_connection_add_filter(connection, &dbus_beacon_handler, NULL, NULL); { char path[DBUS_MAXIMUM_NAME_LENGTH+1]; char interface_dbus_name[DBUS_MAXIMUM_NAME_LENGTH+1]; DBusMessageIter iter; ret = lookup_dbus_name_from_interface(interface_dbus_name, gInterfaceName); if (ret != 0) { goto bail; } snprintf( path, sizeof(path), "%s/%s", WPANTUND_DBUS_PATH, gInterfaceName ); message = dbus_message_new_method_call( interface_dbus_name, path, WPANTUND_DBUS_APIv1_INTERFACE, WPANTUND_IF_CMD_NET_SCAN_START ); dbus_message_append_args( message, DBUS_TYPE_UINT32, &channel_mask, DBUS_TYPE_INVALID ); print_scan_header(); gScannedNetworkCount = 0; if(!dbus_connection_send_with_reply( connection, message, &pending, timeout )) { fprintf(stderr, "%s: error: IPC failure\n", argv[0]); ret = ERRORCODE_UNKNOWN; goto bail; } while ((dbus_connection_get_dispatch_status(connection) == DBUS_DISPATCH_DATA_REMAINS) || dbus_connection_has_messages_to_send(connection) || !dbus_pending_call_get_completed(pending) ) { dbus_connection_read_write_dispatch(connection, 5000 /*ms*/); } reply = dbus_pending_call_steal_reply(pending); require(reply!=NULL, bail); dbus_message_iter_init(reply, &iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_INT32) { fprintf(stderr, "%s: error: Server returned a bad response ('%c')\n", argv[0], dbus_message_iter_get_arg_type(&iter)); ret = ERRORCODE_UNKNOWN; goto bail; } // Get return code dbus_message_iter_get_basic(&iter, &ret); if (ret) { fprintf(stderr, "%s failed with error %d. %s\n", argv[0], ret, wpantund_status_to_cstr(ret)); print_error_diagnosis(ret); goto bail; } } bail: if (reply) { dbus_message_unref(reply); } if (pending != NULL) { dbus_pending_call_unref(pending); } if (message) { dbus_message_unref(message); } if (connection) { dbus_bus_remove_match(connection, gDBusObjectManagerMatchString, NULL); dbus_connection_remove_filter(connection,&dbus_beacon_handler,NULL); dbus_connection_unref(connection); } dbus_error_free(&error); return ret; }
/* FIXME: Cleanup track refs */ void common_cleanup(struct con_win *cwin) { CDEBUG(DBG_INFO, "Cleaning up"); if ((cwin->cstate->state == ST_STOPPED) && (cwin->cstate->curr_mobj_clear)) delete_musicobject(cwin->cstate->curr_mobj); if ((cwin->cstate->state == ST_PLAYING) || (cwin->cstate->state == ST_PAUSED)) stop_playback(cwin); save_preferences(cwin); g_object_unref(cwin->library_store); g_object_unref(cwin->pixbuf->image_play); g_object_unref(cwin->pixbuf->image_pause); if (cwin->pixbuf->pixbuf_app) g_object_unref(cwin->pixbuf->pixbuf_app); if (cwin->pixbuf->pixbuf_dir) g_object_unref(cwin->pixbuf->pixbuf_dir); if (cwin->pixbuf->pixbuf_artist) g_object_unref(cwin->pixbuf->pixbuf_artist); if (cwin->pixbuf->pixbuf_album) g_object_unref(cwin->pixbuf->pixbuf_album); if (cwin->pixbuf->pixbuf_track) g_object_unref(cwin->pixbuf->pixbuf_track); if (cwin->pixbuf->pixbuf_genre) g_object_unref(cwin->pixbuf->pixbuf_genre); g_slice_free(struct pixbuf, cwin->pixbuf); if (cwin->album_art) gtk_widget_destroy(cwin->album_art); if (cwin->cstate->cdda_drive) cdio_cddap_close(cwin->cstate->cdda_drive); if (cwin->cstate->cddb_disc) cddb_disc_destroy(cwin->cstate->cddb_disc); if (cwin->cstate->cddb_conn) { cddb_destroy(cwin->cstate->cddb_conn); libcddb_shutdown(); } g_free(cwin->cpref->lw.lastfm_user); g_free(cwin->cpref->lw.lastfm_pass); #ifdef HAVE_LIBGLYR g_free(cwin->cpref->cache_folder); #endif g_free(cwin->cpref->configrc_file); g_free(cwin->cpref->installed_version); g_free(cwin->cpref->audio_sink); g_free(cwin->cpref->audio_alsa_device); g_free(cwin->cpref->audio_oss_device); g_free(cwin->cpref->album_art_pattern); g_free(cwin->cpref->audio_cd_device); g_free(cwin->cpref->start_mode); g_free(cwin->cpref->sidebar_pane); g_key_file_free(cwin->cpref->configrc_keyfile); free_str_list(cwin->cpref->library_dir); free_str_list(cwin->cpref->lib_add); free_str_list(cwin->cpref->lib_delete); free_str_list(cwin->cpref->library_tree_nodes); free_str_list(cwin->cpref->playlist_columns); g_slist_free(cwin->cpref->playlist_column_widths); g_slice_free(struct con_pref, cwin->cpref); g_rand_free(cwin->cstate->rand); g_free(cwin->cstate->last_folder); g_mutex_free(cwin->cstate->c_mutex); /* Hack, hack */ if (g_mutex_trylock(cwin->cstate->l_mutex) == TRUE) { g_mutex_unlock(cwin->cstate->l_mutex); g_mutex_free(cwin->cstate->l_mutex); } g_cond_free(cwin->cstate->c_cond); g_slice_free(struct con_state, cwin->cstate); #ifdef HAVE_LIBGLYR uninit_glyr_related (cwin); #endif g_free(cwin->cdbase->db_file); sqlite3_close(cwin->cdbase->db); g_slice_free(struct con_dbase, cwin->cdbase); if (cwin->cstate->audio_init && cwin->cmixer) cwin->cmixer->deinit_mixer(cwin); if (cwin->clibao->ao_dev) { CDEBUG(DBG_INFO, "Freeing ao dev"); ao_close(cwin->clibao->ao_dev); } ao_shutdown(); g_slice_free(struct con_mixer, cwin->cmixer); g_slice_free(struct con_libao, cwin->clibao); g_free(cwin->clastfm->session_id); g_free(cwin->clastfm->submission_url); if (cwin->clastfm->curl_handle) curl_easy_cleanup(cwin->clastfm->curl_handle); curl_global_cleanup(); g_slice_free(struct con_lastfm, cwin->clastfm); dbus_connection_remove_filter(cwin->con_dbus, dbus_filter_handler, cwin); dbus_bus_remove_match(cwin->con_dbus, "type='signal',path='/org/pragha/DBus'", NULL); dbus_connection_unref(cwin->con_dbus); #if HAVE_GLIB_2_26 mpris_cleanup(cwin); #endif if (notify_is_initted()) notify_uninit(); #ifdef HAVE_LIBKEYBINDER keybinder_unbind("XF86AudioPlay", (KeybinderHandler) keybind_play_handler); keybinder_unbind("XF86AudioStop", (KeybinderHandler) keybind_stop_handler); keybinder_unbind("XF86AudioPrev", (KeybinderHandler) keybind_prev_handler); keybinder_unbind("XF86AudioNext", (KeybinderHandler) keybind_next_handler); keybinder_unbind("XF86AudioMedia", (KeybinderHandler) keybind_media_handler); #endif g_option_context_free(cwin->cmd_context); g_slice_free(struct con_win, cwin); }
dbusrecv_hdl_st *dbusrecv_init(char *myname, callbk_filter_func filter_func) { dbusrecv_hdl_st *p_dbusrecv_hdl = NULL; int result = 0; int retval = 0; if (NULL == myname) { printf("dbusrev_init: invalid parameters, myname couldn't be NULL!\n"); return NULL; } if (NULL == filter_func) { printf("dbusrev_init: invalid parameters, filter_func couldn't be NULL!\n"); return NULL; } p_dbusrecv_hdl = DBUS_MALLOC(sizeof(dbusrecv_hdl_st)); if (NULL == p_dbusrecv_hdl) { printf("dbusrev_init: malloc failed, p_dbusrecv_hdl!\n"); return NULL; } p_dbusrecv_hdl->dbusrecv_cfg.myname = (char *)malloc(strlen(myname) + 1); memset(p_dbusrecv_hdl->dbusrecv_cfg.myname, 0x0, strlen(myname) + 1); memcpy(p_dbusrecv_hdl->dbusrecv_cfg.myname, myname, strlen(myname)); p_dbusrecv_hdl->filter_func = filter_func; dbus_error_init (&p_dbusrecv_hdl->error); p_dbusrecv_hdl->connection = dbus_bus_get (DBUS_BUS_SYSTEM, &p_dbusrecv_hdl->error); if (NULL == p_dbusrecv_hdl->connection) { printf("%s: Failed to open connection to activating message bus: %s\n", __FILE__, p_dbusrecv_hdl->error.message); retval = -1; goto ERROR; } p_dbusrecv_hdl->dbusloop = _dbus_loop_new (); if (NULL == p_dbusrecv_hdl->dbusloop) { printf("%s: No memory, p_dbusrecv_hdl->dbusloop\n", __FILE__); retval = -1; goto ERROR; } if (!test_connection_setup (p_dbusrecv_hdl->dbusloop, p_dbusrecv_hdl->connection)) { printf("%s: No memory, test_connection_setup\n", __FILE__); retval = -1; goto ERROR; } /* match options: type interface; member; sender; destination; path; */ #if 0 memset(rules, 0x0, sizeof(rules)); sprintf(rules, "type='signal', interface='%s'", p_dbusrecv_hdl->dbusrecv_cfg.interface); dbus_bus_add_match (p_dbusrecv_hdl->connection, rules, &p_dbusrecv_hdl->error); if (dbus_error_is_set (&p_dbusrecv_hdl->error)) { printf("%s: add match(%s) failed\n", __FILE__, rules); retval = -1; goto ERROR; } memset(rules, 0x0, sizeof(rules)); sprintf(rules, "type='signal', interface='org.actiontec.Test'"); dbus_bus_add_match (p_dbusrecv_hdl->connection, rules, &p_dbusrecv_hdl->error); if (dbus_error_is_set (&p_dbusrecv_hdl->error)) { printf("%s: add match(%s) failed\n", __FILE__, rules); retval = -1; goto ERROR; } #endif if (!dbus_connection_add_filter(p_dbusrecv_hdl->connection, p_dbusrecv_hdl->filter_func, (void *)p_dbusrecv_hdl, NULL)) { printf("%s: No memory, dbus_connection_add_filter\n", __FILE__); retval = -1; goto ERROR; } p_dbusrecv_hdl->is_addfilter = 1; if (!dbus_connection_register_object_path (p_dbusrecv_hdl->connection, DBUS_DEFAULT_PATH, &dbusrecv_vtable, (void *)p_dbusrecv_hdl)) //(void*) 0xdeadbeef)) { printf("%s: No memory, dbus_connection_register_object_path\n", __FILE__); retval = -1; goto ERROR; } { void *d; if (!dbus_connection_get_object_path_data (p_dbusrecv_hdl->connection, DBUS_DEFAULT_PATH, &d)) { printf("%s: No memory, dbus_connection_get_object_path_data\n", __FILE__); retval = -1; goto ERROR; } //if (d != (void*) 0xdeadbeef) if (d != (void*) p_dbusrecv_hdl) { printf("%s: dbus_connection_get_object_path_data() doesn't seem to work right\n", __FILE__); retval = -1; goto ERROR; } } result = dbus_bus_request_name(p_dbusrecv_hdl->connection, myname, 0, &p_dbusrecv_hdl->error); if (dbus_error_is_set (&p_dbusrecv_hdl->error)) { printf("%s: Failed to acquire service: %s\n", __FILE__, p_dbusrecv_hdl->error.message); retval = -1; goto ERROR; } //_dbus_verbose("%s: service(%s) entering main loop!\n", __FILE__, myname); //_dbus_loop_run(p_dbusrecv_hdl->dbusloop); retval = 0; ERROR: if (-1 == retval) { dbus_error_free (&p_dbusrecv_hdl->error); if (p_dbusrecv_hdl->connection) { test_connection_shutdown (p_dbusrecv_hdl->dbusloop, p_dbusrecv_hdl->connection); if (p_dbusrecv_hdl->is_addfilter) dbus_connection_remove_filter (p_dbusrecv_hdl->connection, p_dbusrecv_hdl->filter_func, NULL);// dbus_connection_unref (p_dbusrecv_hdl->connection); p_dbusrecv_hdl->connection = NULL; } if (p_dbusrecv_hdl->dbusloop) { _dbus_loop_unref (p_dbusrecv_hdl->dbusloop); p_dbusrecv_hdl->dbusloop = NULL; } dbus_shutdown(); _dbus_verbose("%s: service(%s) exiting!\n", __FILE__, myname); return NULL; } return p_dbusrecv_hdl; }
static DBusHandlerResult on_prompt_signal (DBusConnection *connection, DBusMessage *message, void *user_data) { on_prompt_args *args = user_data; DBusMessageIter iter; dbus_bool_t dismissed; GkrOperation *op; const char *object_name; const char *new_owner; const char *old_owner; g_assert (args); if (!args->path || !args->op->prompting) return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; /* org.freedesktop.Secret.Prompt.Completed(BOOLEAN dismissed, VARIANT result) */ if (dbus_message_has_path (message, args->path) && dbus_message_is_signal (message, PROMPT_INTERFACE, "Completed")) { /* Only one call, even if daemon decides to be strange */ g_free (args->path); args->path = NULL; if (!dbus_message_iter_init (message, &iter) || dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_BOOLEAN) g_return_val_if_reached (BROKEN); dbus_message_iter_get_basic (&iter, &dismissed); op = gkr_operation_ref (args->op); if (dismissed) gkr_operation_complete (op, MATE_KEYRING_RESULT_CANCELLED); else callback_with_message (op, message); if (op->prompting) dbus_connection_remove_filter (args->op->conn, on_prompt_signal, args); gkr_operation_unref (op); return DBUS_HANDLER_RESULT_HANDLED; } /* org.freedesktop.DBus.NameOwnerChanged(STRING name, STRING old_owner, STRING new_owner) */ if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged") && dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &object_name, DBUS_TYPE_STRING, &old_owner, DBUS_TYPE_STRING, &new_owner, DBUS_TYPE_INVALID)) { /* See if it's the secret service going away */ if (object_name && g_str_equal (gkr_service_name (), object_name) && new_owner && g_str_equal ("", new_owner)) { g_message ("Secret service disappeared while waiting for prompt"); op = gkr_operation_ref (args->op); gkr_operation_complete (op, MATE_KEYRING_RESULT_IO_ERROR); if (op->prompting) dbus_connection_remove_filter (args->op->conn, on_prompt_signal, args); gkr_operation_unref (op); } return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; }
int DBusMonitorCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { Tcl_DBusBus *dbus = defaultbus; Tcl_DBusMonitorData *snoop; Tcl_HashEntry *memberPtr; Tcl_Obj *handler; int x = 1, flags = 0, index; char c; static const char *options[] = {"-details", NULL}; enum options {DBUS_DETAILS}; if (objc > 2) { c = Tcl_GetString(objv[1])[0]; /* If the arg doesn't start with '-', it must be a busId specification */ if (c != '-') { if (DBus_BusType(interp, objv[1]) < 0) return TCL_ERROR; dbus = DBus_GetConnection(interp, objv[1]); x++; } } for (; x < objc - 1; x++) { c = Tcl_GetString(objv[x])[0]; if (c != '-') break; if (Tcl_GetIndexFromObj(interp, objv[x], options, "option", 0, &index) != TCL_OK) { return TCL_ERROR; } switch ((enum options) index) { case DBUS_DETAILS: flags |= DBUSFLAG_DETAILS; break; } } if (objc != x + 1) { Tcl_WrongNumArgs(interp, 1, objv, "?busId? script"); return TCL_ERROR; } handler = objv[x]; if (dbus == NULL) { Tcl_SetObjResult(interp, Tcl_NewStringObj("Not connected", -1)); return TCL_ERROR; } /* Find the snoop entry for the current interpreter */ memberPtr = Tcl_FindHashEntry(dbus->snoop, (char *) interp); snoop = Tcl_GetHashValue(memberPtr); /* Unregistering the old handler */ if (snoop != NULL) { dbus_connection_remove_filter(dbus->conn, DBus_Monitor, snoop); Tcl_DecrRefCount(snoop->script); ckfree((char *) snoop); Tcl_SetHashValue(memberPtr, NULL); } if (Tcl_GetCharLength(handler) > 0) { /* Register the new handler */ snoop = (Tcl_DBusMonitorData *)ckalloc(sizeof(Tcl_DBusMonitorData)); snoop->interp = interp; snoop->script = handler; snoop->flags = flags; Tcl_IncrRefCount(handler); Tcl_SetHashValue(memberPtr, snoop); dbus_connection_add_filter(dbus->conn, DBus_Monitor, snoop, NULL); } return TCL_OK; }
int module_cleanup(struct ipc_module_t* module){ dbus_bus_remove_match(bus, dbus_rule, &error); dbus_connection_remove_filter(bus, signal_filter, NULL); dbus_error_free(&error); return 0; }
void Connection::remove_filter( Filter& f ) { cbus_dbg("%s: removing filter",unique_name()); dbus_connection_remove_filter(_connection, message_filter_stub, &f); }
int main (int argc, char **argv) { DBusError error; int result; DBusConnection *connection; dbus_error_init (&error); connection = dbus_bus_get (DBUS_BUS_STARTER, &error); if (connection == NULL) { fprintf (stderr, "*** Failed to open connection to activating message bus: %s\n", error.message); dbus_error_free (&error); return 1; } loop = _dbus_loop_new (); if (loop == NULL) die ("No memory\n"); if (!test_connection_setup (loop, connection)) die ("No memory\n"); if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL)) die ("No memory"); if (!dbus_connection_register_object_path (connection, echo_path, &echo_vtable, (void*) 0xdeadbeef)) die ("No memory"); { void *d; if (!dbus_connection_get_object_path_data (connection, echo_path, &d)) die ("No memory"); if (d != (void*) 0xdeadbeef) die ("dbus_connection_get_object_path_data() doesn't seem to work right\n"); } result = dbus_bus_request_name (connection, "org.freedesktop.DBus.TestSuiteEchoService", 0, &error); if (dbus_error_is_set (&error)) { fprintf (stderr, "Error %s\n", error.message); _dbus_verbose ("*** Failed to acquire service: %s\n", error.message); dbus_error_free (&error); exit (1); } _dbus_verbose ("*** Test service entering main loop\n"); _dbus_loop_run (loop); test_connection_shutdown (loop, connection); dbus_connection_remove_filter (connection, filter_func, NULL); dbus_connection_unref (connection); _dbus_loop_unref (loop); loop = NULL; dbus_shutdown (); _dbus_verbose ("*** Test service exiting\n"); return 0; }
int main (int argc, char **argv) { DBusError error; int result; DBusConnection *connection; const char *name; dbus_bool_t do_fork; if (argc != 3) { name = "org.freedesktop.DBus.TestSuiteEchoService"; do_fork = FALSE; } else { name = argv[1]; #ifndef DBUS_WIN do_fork = strcmp (argv[2], "fork") == 0; #else do_fork = FALSE; #endif } /* The bare minimum for simulating a program "daemonizing"; the intent * is to test services which move from being legacy init scripts to * activated services. * https://bugzilla.redhat.com/show_bug.cgi?id=545267 */ #ifndef DBUS_WIN if (do_fork) { pid_t pid = fork (); if (pid != 0) exit (0); sleep (1); } #endif dbus_error_init (&error); connection = dbus_bus_get (DBUS_BUS_STARTER, &error); if (connection == NULL) { fprintf (stderr, "*** Failed to open connection to activating message bus: %s\n", error.message); dbus_error_free (&error); return 1; } loop = _dbus_loop_new (); if (loop == NULL) die ("No memory\n"); if (!test_connection_setup (loop, connection)) die ("No memory\n"); if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL)) die ("No memory"); if (!dbus_connection_register_object_path (connection, echo_path, &echo_vtable, (void*) 0xdeadbeef)) die ("No memory"); { void *d; if (!dbus_connection_get_object_path_data (connection, echo_path, &d)) die ("No memory"); if (d != (void*) 0xdeadbeef) die ("dbus_connection_get_object_path_data() doesn't seem to work right\n"); } result = dbus_bus_request_name (connection, name, 0, &error); if (dbus_error_is_set (&error)) { fprintf (stderr, "Error %s\n", error.message); _dbus_verbose ("*** Failed to acquire service: %s\n", error.message); dbus_error_free (&error); exit (1); } _dbus_verbose ("*** Test service entering main loop\n"); _dbus_loop_run (loop); test_connection_shutdown (loop, connection); dbus_connection_remove_filter (connection, filter_func, NULL); dbus_connection_unref (connection); _dbus_loop_unref (loop); loop = NULL; dbus_shutdown (); _dbus_verbose ("*** Test service exiting\n"); return 0; }
dbus_bool_t bus_setup_debug_client (DBusConnection *connection) { dbus_bool_t retval; if (!dbus_connection_add_filter (connection, client_disconnect_filter, NULL, NULL)) return FALSE; retval = FALSE; if (client_loop == NULL) { client_loop = _dbus_loop_new (); if (client_loop == NULL) goto out; } if (!dbus_connection_set_watch_functions (connection, add_client_watch, remove_client_watch, toggle_client_watch, connection, NULL)) goto out; if (!dbus_connection_set_timeout_functions (connection, add_client_timeout, remove_client_timeout, NULL, connection, NULL)) goto out; if (!_dbus_list_append (&clients, connection)) goto out; retval = TRUE; out: if (!retval) { dbus_connection_remove_filter (connection, client_disconnect_filter, NULL); dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL); dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL); _dbus_list_remove_last (&clients, connection); if (clients == NULL) { _dbus_loop_unref (client_loop); client_loop = NULL; } } return retval; }