/** Stop connman OfflineMode property mirroring */ static void xconnman_quit(void) { if( connman_bus ) { dbus_connection_remove_filter(connman_bus, xconnman_dbus_filter_cb, 0); dbus_bus_remove_match(connman_bus, xconnman_prop_change_rule, 0); dbus_bus_remove_match(connman_bus, xconnman_name_owner_rule, 0); dbus_connection_unref(connman_bus), connman_bus = 0; } }
void HippoDBusIpcProviderImpl::setBusUniqueName(const char *uniqueName) { g_debug("unique name of client: %s", uniqueName ? uniqueName : "NULL"); if (uniqueName == NULL && busUniqueName_ == NULL) return; if (uniqueName && busUniqueName_ && strcmp(uniqueName, busUniqueName_) == 0) return; if (busUniqueName_ != NULL && connection_) { char *connectedRule = connected_rule(busUniqueName_); char *disconnectedRule = disconnected_rule(busUniqueName_); // both of these will fail if the matched busUniqueName_ is disconnected, // since the bus garbage collects the match rules for nonexistent unique // names. we just want to ignore the failure. g_debug("removing rule %s", connectedRule); dbus_bus_remove_match(connection_, connectedRule, NULL); g_debug("removing rule %s", disconnectedRule); dbus_bus_remove_match(connection_, disconnectedRule, NULL); g_free(connectedRule); g_free(disconnectedRule); } /* note the new unique name can be NULL */ busUniqueName_ = g_strdup(uniqueName); if (busUniqueName_ != NULL && connection_) { char *connectedRule = connected_rule(busUniqueName_); char *disconnectedRule = disconnected_rule(busUniqueName_); g_debug("adding rule %s", connectedRule); dbus_bus_add_match(connection_, connectedRule, NULL); g_debug("adding rule %s", disconnectedRule); dbus_bus_add_match(connection_, disconnectedRule, NULL); g_free(connectedRule); g_free(disconnectedRule); } if (busUniqueName_ != NULL) notifyRegisterEndpointOpportunity(); else notifyEndpointsInvalidated(); }
void HippoDBusIpcProviderImpl::forgetBusConnection() { setBusUniqueName(NULL); if (connection_ != NULL) { dbus_connection_remove_filter(connection_, handleMessageCallback, (void*) this); /* should silently be an error if we're disconnected */ dbus_bus_remove_match(connection_, busNameOwnerChangedRule_, NULL); /* With older dbus versions, unreffing the connection from * dbus_bus_get() will cause an assertion failure if this is * the last reference and we're still connected. There's no * way to get around this so we just keep the connection_ * object around in a static variable once we've gotten it * once. We'll leak a refcount if this module is unloaded * then loaded again, but that's more or less harmless. */ // dbus_connection_unref(connection_); // connection_ = NULL; g_debug("Dropped bus connection"); } // this is a pointless extra call really since setting the unique name to NULL // already did it too notifyEndpointsInvalidated(); }
int pa_dbus_add_matches(DBusConnection *c, DBusError *error, ...) { const char *t; va_list ap; unsigned k = 0; pa_assert(c); pa_assert(error); va_start(ap, error); while ((t = va_arg(ap, const char*))) { dbus_bus_add_match(c, t, error); if (dbus_error_is_set(error)) goto fail; k++; } va_end(ap); return 0; fail: va_end(ap); va_start(ap, error); for (; k > 0; k--) { pa_assert_se(t = va_arg(ap, const char*)); dbus_bus_remove_match(c, t, NULL); } va_end(ap); return -1; }
void removeSignalWatch( Signals* signals, char* busname, char* objectpath, char* interface, char* signalname) { DBusError dbusError; dbus_error_init(&dbusError); bstring rule = createRule(busname, objectpath, interface, signalname); char* cstr_rule = bstr2cstr(rule,'\0'); printf("Rule : %s\n",cstr_rule); pthread_mutex_lock(&signals->dbus_mutex); dbus_bus_remove_match(signals->con,cstr_rule,&dbusError); pthread_mutex_unlock(&signals->dbus_mutex); if (dbus_error_is_set(&dbusError)) { fprintf(stderr, "%s %d: Error occurred: %s\n",__FILE__,__LINE__, dbusError.message); dbus_error_free(&dbusError); } bcstrfree(cstr_rule); bdestroy(rule); }
static void cka_client_delete(cka_client_t *self) { if( self != 0 ) { mce_log(LL_DEBUG, "client deleted; %s", cka_client_identify(self)); tick_t now = cka_tick_get_current(); /* Finish all sessions */ GHashTableIter iter; gpointer val; g_hash_table_iter_init(&iter, self->cli_sessions); while( g_hash_table_iter_next(&iter, 0, &val) ) { cka_session_t *session = val; cka_session_finish(session, now); } /* NULL error -> match will be removed asynchronously */ dbus_bus_remove_match(cka_dbus_systembus, self->cli_match_rule, 0); /* Cleanup */ g_hash_table_unref(self->cli_sessions); g_free(self->cli_dbus_name); g_free(self->cli_match_rule); g_free(self); } }
EAPI Eina_Bool eldbus_signal_handler_match_extra_vset(Eldbus_Signal_Handler *sh, va_list ap) { const char *key = NULL, *read; DBusError err; ELDBUS_SIGNAL_HANDLER_CHECK_RETVAL(sh, EINA_FALSE); dbus_error_init(&err); dbus_bus_remove_match(sh->conn->dbus_conn, eina_strbuf_string_get(sh->match), &err); EINA_SAFETY_ON_TRUE_RETURN_VAL(dbus_error_is_set(&err), EINA_FALSE); for (read = va_arg(ap, char *); read; read = va_arg(ap, char *)) { Signal_Argument *arg; if (!key) { key = read; continue; } arg = calloc(1, sizeof(Signal_Argument)); EINA_SAFETY_ON_NULL_GOTO(arg, error); if (!strncmp(key, ARGX, strlen(ARGX))) { int id = atoi(key + strlen(ARGX)); arg->index = (unsigned short) id; arg->value = eina_stringshare_add(read); sh->args = eina_inlist_sorted_state_insert(sh->args, EINA_INLIST_GET(arg), _sort_arg, sh->state_args); _match_append(sh->match, key, read); } else { ERR("%s not supported", key); free(arg); } key = NULL; } dbus_error_init(&err); dbus_bus_add_match(sh->conn->dbus_conn, eina_strbuf_string_get(sh->match), &err); if (!dbus_error_is_set(&err)) return EINA_TRUE; ERR("Error setting new match."); return EINA_FALSE; error: dbus_error_init(&err); dbus_bus_add_match(sh->conn->dbus_conn, eina_strbuf_string_get(sh->match), &err); if (dbus_error_is_set(&err)) ERR("Error setting partial extra arguments."); return EINA_FALSE; }
static void gkd_secret_service_dispose (GObject *obj) { GkdSecretService *self = GKD_SECRET_SERVICE (obj); if (self->match_rule) { g_return_if_fail (self->connection); dbus_bus_remove_match (self->connection, self->match_rule, NULL); g_free (self->match_rule); self->match_rule = NULL; } /* Closes all the clients */ g_hash_table_remove_all (self->clients); /* Hide all the objects */ if (self->objects) { g_object_run_dispose (G_OBJECT (self->objects)); g_object_unref (self->objects); self->objects = NULL; } if (self->connection) { dbus_connection_remove_filter (self->connection, gkd_secret_service_filter_handler, self); dbus_connection_unref (self->connection); self->connection = NULL; } G_OBJECT_CLASS (gkd_secret_service_parent_class)->dispose (obj); }
void profile_tracker_disconnect(void) { DBusError err = DBUS_ERROR_INIT; if( profile_tracker_con != 0 ) { ENTER /* stop listening to profiled signals */ dbus_bus_remove_match(profile_tracker_con, PROFILED_MATCH, &err); if( dbus_error_is_set(&err) ) { log_err("%s: %s: %s: %s\n", "libprofile", "dbus_bus_remove_match", err.name, err.message); dbus_error_free(&err); } /* remove message filter function */ dbus_connection_remove_filter(profile_tracker_con, profile_tracker_filter, 0); /* release connection reference */ dbus_connection_unref(profile_tracker_con); profile_tracker_con = 0; LEAVE }
static void* FcitxNotifyCreate(FcitxInstance *instance) { FcitxNotify *notify = fcitx_utils_new(FcitxNotify); notify->owner = instance; notify->notify_counter = 1; notify->conn = FcitxDBusGetConnection(notify->owner); if (fcitx_unlikely(!notify->conn)) goto connect_error; DBusError err; dbus_error_init(&err); dbus_bus_add_match(notify->conn, NOTIFICATIONS_MATCH_ACTION, &err); if (fcitx_unlikely(dbus_error_is_set(&err))) goto filter_error; dbus_bus_add_match(notify->conn, NOTIFICATIONS_MATCH_CLOSED, &err); if (fcitx_unlikely(dbus_error_is_set(&err))) goto filter_error; if (fcitx_unlikely(!dbus_connection_add_filter(notify->conn, FcitxNotifyDBusFilter, notify, NULL))) goto filter_error; dbus_error_free(&err); notify->hide_notify = fcitx_string_map_new(NULL, '\0'); fcitx_desktop_file_init(¬ify->dconfig, NULL, NULL); FcitxNotifyLoadDConfig(notify); FcitxDBusWatchName(instance, NOTIFICATIONS_SERVICE_NAME, notify, FcitxNotifyOwnerChanged, NULL, NULL); FcitxNotifyGetCapabilities(notify); FcitxFreeDesktopNotifyAddFunctions(instance); return notify; filter_error: dbus_bus_remove_match(notify->conn, NOTIFICATIONS_MATCH_ACTION, NULL); dbus_bus_remove_match(notify->conn, NOTIFICATIONS_MATCH_CLOSED, NULL); dbus_error_free(&err); connect_error: free(notify); return NULL; }
void Connection::remove_match( const char* rule ) { Error e; dbus_bus_remove_match(_connection, rule, e); cbus_dbg("%s: removed match rule %s", unique_name(), rule); if(e) throw e; }
void pa_dbus_remove_matches(DBusConnection *c, ...) { const char *t; va_list ap; pa_assert(c); va_start(ap, c); while ((t = va_arg(ap, const char*))) dbus_bus_remove_match(c, t, NULL); va_end(ap); }
static int watch_dbus_addr(const char *addr, int watchit, DBusHandlerResult (*filter)(DBusConnection *, DBusMessage *, void *), void *user_data) { char match[1024]; DBusError err; snprintf(match, sizeof(match), "type='signal'," "sender='%s',interface='%s',member='%s',path='%s'," "arg0='%s'", DBUS_ADMIN_INTERFACE, DBUS_ADMIN_INTERFACE, DBUS_NAME_OWNER_CHANGED, DBUS_ADMIN_PATH, addr); if (filter) { if (watchit) { if (!dbus_connection_add_filter(sys_conn, filter, user_data,NULL)) { OHM_ERROR("Failed to install dbus filter %p.", filter); return FALSE; } } else dbus_connection_remove_filter(sys_conn, filter, user_data); } /* * Notes: * We block when adding filters, to minimize (= eliminate ?) the time * window for the client to crash after it has let us know about itself * but before we managed to install the filter. According to the docs * we do not re-enter the main loop and all other messages than the * reply to AddMatch will get queued and processed once we're back in the * main loop. On the watch removal path we do not care about errors and * we do not want to block either. */ if (watchit) { dbus_error_init(&err); dbus_bus_add_match(sys_conn, match, &err); if (dbus_error_is_set(&err)) { OHM_ERROR("Can't add match \"%s\": %s", match, err.message); dbus_error_free(&err); return FALSE; } } else dbus_bus_remove_match(sys_conn, match, NULL); return TRUE; }
void __connman_task_cleanup(void) { DBG(""); dbus_bus_remove_match(connection, task_rule, NULL); dbus_connection_flush(connection); g_hash_table_destroy(task_hash); task_hash = NULL; dbus_connection_remove_filter(connection, task_filter, NULL); dbus_connection_unref(connection); }
void pre_disconnect_hook(void) { DBusError error; dbus_error_init(&error); dbus_connection_unregister_object_path(connection_data->connection, connection_data->busobject); dbus_bus_remove_match(connection_data->connection, MATCH_RULE, &error); dbus_bus_release_name(connection_data->connection, connection_data->busname, &error); dbus_error_free(&error); }
static void database_remove_listening_client (GConfDatabase *db, ListeningClientData *client) { gchar *rule; rule = get_rule_for_service (client->service); dbus_bus_remove_match (gconfd_dbus_get_connection (), rule, NULL); g_free (rule); g_hash_table_remove (db->listening_clients, client->service); g_free (client->service); g_free (client); }
static void clear_dbus_matches(struct cmtspeech_dbus_conn *e, DBusConnection *dbusconn) { int i; for(i = PA_ELEMENTSOF(e->dbus_match_rules) - 1; i >= 0; i--) { if (e->dbus_match_rules[i] == NULL) continue; dbus_bus_remove_match(dbusconn, e->dbus_match_rules[i], NULL); pa_log_debug("removed dbus match \"%s\"", e->dbus_match_rules[i]); pa_xfree(e->dbus_match_rules[i]); e->dbus_match_rules[i] = NULL; } }
static void connect_hook(DBusConnection *connection, void *data) { DBusError error; DBusObjectPathVTable vtable = { .message_function = message_handler, }; struct connection_info *info = data; info->connection = connection; dbus_error_init(&error); dbus_bus_request_name(info->connection, info->busname, 0, &error); if (dbus_error_is_set(&error)) { ErrorF("[config/dbus] couldn't take over org.x.config: %s (%s)\n", error.name, error.message); goto err_start; } /* blocks until we get a reply. */ dbus_bus_add_match(info->connection, MATCH_RULE, &error); if (dbus_error_is_set(&error)) { ErrorF("[config/dbus] couldn't add match: %s (%s)\n", error.name, error.message); goto err_name; } if (!dbus_connection_register_object_path(info->connection, info->busobject, &vtable, info)) { ErrorF("[config/dbus] couldn't register object path\n"); goto err_match; } DebugF("[dbus] registered %s, %s\n", info->busname, info->busobject); dbus_error_free(&error); return; err_match: dbus_bus_remove_match(info->connection, MATCH_RULE, &error); err_name: dbus_bus_release_name(info->connection, info->busname, &error); err_start: dbus_error_free(&error); reset_info(info); }
static void client_delete(client_t *self) { if( self != 0 ) { mce_log(LL_NOTICE, "removed cpu-keepalive client %s", self->dbus_name); /* NULL error -> match will be removed asynchronously */ dbus_bus_remove_match(systembus, self->match_rule, 0); g_free(self->dbus_name); g_free(self->match_rule); g_free(self); } }
void weston_dbus_remove_match(DBusConnection *c, const char *format, ...) { int r; va_list list; char *str; va_start(list, format); r = vasprintf(&str, format, list); va_end(list); if (r < 0) return; dbus_bus_remove_match(c, str, NULL); free(str); }
void pa_dbus_remove_matches(DBusConnection *c, ...) { const char *t; va_list ap; DBusError error; pa_assert(c); dbus_error_init(&error); va_start(ap, c); while ((t = va_arg(ap, const char*))) { dbus_bus_remove_match(c, t, &error); dbus_error_free(&error); } va_end(ap); }
int ep_unregister (DBusConnection *c) { DBusMessage *msg = NULL, *reply = NULL; DBusPendingCall *pend; int success = 0; char polrule[512]; (void) c; /* first, let's remove the filter */ snprintf(polrule, sizeof(polrule), "type='signal',interface='%s'," "path='%s/%s'", POLICY_DBUS_INTERFACE, POLICY_DBUS_PATH, POLICY_DECISION); dbus_connection_remove_filter(connection, filter, NULL); dbus_bus_remove_match(connection, polrule, NULL); /* then unregister */ msg = dbus_message_new_method_call(POLICY_DBUS_NAME, POLICY_DBUS_PATH, POLICY_DBUS_INTERFACE, "unregister"); if (msg == NULL) { goto failed; } success = dbus_connection_send_with_reply(connection, msg, &pend, 1000); if (!success) { goto failed; } dbus_pending_call_block(pend); reply = dbus_pending_call_steal_reply(pend); if (!reply || dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { goto failed; } success = 1; /* intentional fallthrough */ failed: dbus_message_unref(msg); return success; }
static void supplicant_destroy(void) { if (g_slist_length(driver_list) > 0) return; _DBG_SUPPLICANT("connection %p", connection); if (watch > 0) g_dbus_remove_watch(connection, watch); dbus_bus_remove_match(connection, supplicant_rule, NULL); dbus_connection_flush(connection); dbus_connection_remove_filter(connection, supplicant_filter, NULL); dbus_connection_unref(connection); connection = NULL; }
void FcitxNotificationItemDestroy(void* arg) { FcitxNotificationItem* notificationitem = (FcitxNotificationItem*) arg; if (notificationitem->conn) { dbus_connection_unregister_object_path(notificationitem->conn, NOTIFICATION_ITEM_DEFAULT_OBJ); dbus_connection_unregister_object_path(notificationitem->conn, "/MenuBar"); dbus_connection_remove_filter(notificationitem->conn, FcitxNotificationItemDBusFilter, notificationitem); dbus_bus_remove_match(notificationitem->conn, "type='signal'," "interface='" DBUS_INTERFACE_DBUS "'," "path='" DBUS_PATH_DBUS "'," "member='NameOwnerChanged'," "arg0='" NOTIFICATION_WATCHER_DBUS_ADDR "'", NULL); } free(notificationitem); }
bool DBusThread::TearDownEventLoop() { MOZ_ASSERT(mConnection); DBusError err; dbus_error_init(&err); for (uint32_t i = 0; i < ArrayLength(DBUS_SIGNALS); ++i) { dbus_bus_remove_match(mConnection, DBUS_SIGNALS[i], &err); if (dbus_error_is_set(&err)) { LOG_AND_FREE_DBUS_ERROR(&err); } } return true; }
//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; }
static void unregister_daemon_in_session (DBusConnection *conn) { DBusMessageIter args; DBusMessage *msg; DBusMessage *reply; DBusError derr = { 0 }; if (client_session_rule) { dbus_bus_remove_match (conn, client_session_rule, NULL); g_free (client_session_rule); client_session_rule = NULL; } if (!client_session_path) return; msg = dbus_message_new_method_call (SERVICE_SESSION_MANAGER, PATH_SESSION_MANAGER, IFACE_SESSION_MANAGER, "UnregisterClient"); g_return_if_fail (msg); dbus_message_iter_init_append (msg, &args); if (!dbus_message_iter_append_basic (&args, DBUS_TYPE_OBJECT_PATH, &client_session_path)) g_return_if_reached (); reply = dbus_connection_send_with_reply_and_block (conn, msg, 1000, &derr); dbus_message_unref (msg); if (!reply) { g_message ("dbus failure unregistering from session: %s", derr.message); return; } dbus_message_unref (reply); g_free (client_session_path); client_session_path = 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; }
int main(int argc, char**argv) { GMainLoop *loop; DBusError error; int godaemon = 1; /* * Signal the kernel that we're not timing critical */ #ifdef PR_SET_TIMERSLACK prctl(PR_SET_TIMERSLACK,1000*1000*1000, 0, 0, 0); #endif read_config_file("/etc/kerneloops.conf"); if (argc > 1 && strstr(argv[1], "--nodaemon")) godaemon = 0; if (argc > 1 && strstr(argv[1], "--debug")) { printf("Starting kerneloops in debug mode\n"); godaemon = 0; testmode = 1; opted_in = 2; } if (!opted_in && !testmode) { fprintf(stderr, " [Inactive by user preference]"); return EXIT_SUCCESS; } /* * the curl docs say that we "should" call curl_global_init early, * even though it'll be called later on via curl_easy_init(). * We ignore this advice, since 99.99% of the time this program * will not use http at all, but the curl code does consume * memory. */ /* curl_global_init(CURL_GLOBAL_ALL); */ if (godaemon && daemon(0, 0)) { printf("kerneloops failed to daemonize.. exiting \n"); return EXIT_FAILURE; } sched_yield(); loop = g_main_loop_new(NULL, FALSE); dbus_error_init(&error); bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error); if (bus) { dbus_connection_setup_with_g_main(bus, NULL); dbus_bus_add_match(bus, "type='signal',interface='org.kerneloops.submit.ping'", &error); dbus_bus_add_match(bus, "type='signal',interface='org.kerneloops.submit.permission'", &error); dbus_connection_add_filter(bus, got_message, NULL, NULL); } /* we scan dmesg before /var/log/messages; dmesg is a more accurate source normally */ scan_dmesg(NULL); /* during boot... don't go too fast and slow the system down */ if (!testmode) sleep(10); scan_filename(log_file, 1); if (argc > 2 && strstr(argv[1], "--file")) scan_filename(argv[2], 1); if (testmode && argc > 2) { int q; for (q = 2; q < argc; q++) { printf("Scanning %s\n", argv[q]); scan_filename(argv[q], 0); } } if (testmode) { g_main_loop_unref(loop); dbus_bus_remove_match(bus, "type='signal',interface='org.kerneloops.submit.ping'", &error); dbus_bus_remove_match(bus, "type='signal',interface='org.kerneloops.submit.permission'", &error); free(submit_url); return EXIT_SUCCESS; } /* now, start polling for oopses to occur */ g_timeout_add_seconds(10, scan_dmesg, NULL); g_main_loop_run(loop); dbus_bus_remove_match(bus, "type='signal',interface='org.kerneloops.submit.ping'", &error); dbus_bus_remove_match(bus, "type='signal',interface='org.kerneloops.submit.permission'", &error); g_main_loop_unref(loop); free(submit_url); return EXIT_SUCCESS; }