static void bus_data_free (void *data) { BusData *bd = data; if (bd->is_well_known) { int i; _DBUS_LOCK (bus); /* We may be stored in more than one slot */ /* This should now be impossible - these slots are supposed to * be cleared on disconnect, so should not need to be cleared on * finalize */ i = 0; while (i < N_BUS_TYPES) { if (bus_connections[i] == bd->connection) bus_connections[i] = NULL; ++i; } _DBUS_UNLOCK (bus); } dbus_free (bd->unique_name); dbus_free (bd); dbus_connection_free_data_slot (&bus_data_slot); }
static void bus_data_free (void *data) { BusData *bd = data; if (bd->is_well_known) { int i; _DBUS_LOCK (bus); /* We may be stored in more than one slot */ i = 0; while (i < N_BUS_TYPES) { if (bus_connections[i] == bd->connection) bus_connections[i] = NULL; ++i; } _DBUS_UNLOCK (bus); } dbus_free (bd->unique_name); dbus_free (bd); dbus_connection_free_data_slot (&bus_data_slot); }
/** * Gets the hex-encoded UUID of the machine this function is * executed on. This UUID is guaranteed to be the same for a given * machine at least until it next reboots, though it also * makes some effort to be the same forever, it may change if the * machine is reconfigured or its hardware is modified. * * @param uuid_str string to append hex-encoded machine uuid to * @returns #FALSE if no memory */ dbus_bool_t _dbus_get_local_machine_uuid_encoded (DBusString *uuid_str) { dbus_bool_t ok; _DBUS_LOCK (machine_uuid); if (machine_uuid_initialized_generation != _dbus_current_generation) { DBusError error = DBUS_ERROR_INIT; if (!_dbus_read_local_machine_uuid (&machine_uuid, FALSE, &error)) { #ifndef DBUS_BUILD_TESTS /* For the test suite, we may not be installed so just continue silently * here. But in a production build, we want to be nice and loud about * this. */ _dbus_warn_check_failed ("D-Bus library appears to be incorrectly set up; failed to read machine uuid: %s\n" "See the manual page for dbus-uuidgen to correct this issue.\n", error.message); #endif dbus_error_free (&error); _dbus_generate_uuid (&machine_uuid); } } ok = _dbus_uuid_encode (&machine_uuid, uuid_str); _DBUS_UNLOCK (machine_uuid); return ok; }
static void free_link (DBusList *link) { _DBUS_LOCK (list); if (_dbus_mem_pool_dealloc (list_pool, link)) { _dbus_mem_pool_free (list_pool); list_pool = NULL; } _DBUS_UNLOCK (list); }
/* the mem pool is probably a speed hit, with the thread * lock, though it does still save memory - unknown. */ static DBusList* alloc_link (void *data) { DBusList *link; if (!_DBUS_LOCK (list)) return NULL; if (list_pool == NULL) { list_pool = _dbus_mem_pool_new (sizeof (DBusList), TRUE); if (list_pool == NULL) { _DBUS_UNLOCK (list); return NULL; } link = _dbus_mem_pool_alloc (list_pool); if (link == NULL) { _dbus_mem_pool_free (list_pool); list_pool = NULL; _DBUS_UNLOCK (list); return NULL; } } else { link = _dbus_mem_pool_alloc (list_pool); } if (link) link->data = data; _DBUS_UNLOCK (list); return link; }
/** * Register a cleanup function to be called exactly once * the next time dbus_shutdown() is called. * * @param func the function * @param data data to pass to the function * @returns #FALSE on not enough memory */ dbus_bool_t _dbus_register_shutdown_func (DBusShutdownFunction func, void *data) { dbus_bool_t ok; if (!_DBUS_LOCK (shutdown_funcs)) return FALSE; ok = _dbus_register_shutdown_func_unlocked (func, data); _DBUS_UNLOCK (shutdown_funcs); return ok; }
static void free_link (DBusList *link) { if (!_DBUS_LOCK (list)) _dbus_assert_not_reached ("we should have initialized global locks " "before we allocated a linked-list link"); if (_dbus_mem_pool_dealloc (list_pool, link)) { _dbus_mem_pool_free (list_pool); list_pool = NULL; } _DBUS_UNLOCK (list); }
void _dbus_list_get_stats (dbus_uint32_t *in_use_p, dbus_uint32_t *in_free_list_p, dbus_uint32_t *allocated_p) { if (!_DBUS_LOCK (list)) { *in_use_p = 0; *in_free_list_p = 0; *allocated_p = 0; return; } _dbus_mem_pool_get_stats (list_pool, in_use_p, in_free_list_p, allocated_p); _DBUS_UNLOCK (list); }
/** * Internal function that checks to see if this * is a shared connection owned by the bus and if it is unref it. * * @param connection a connection that has been disconnected. */ void _dbus_bus_notify_shared_connection_disconnected_unlocked (DBusConnection *connection) { int i; _DBUS_LOCK (bus); /* We are expecting to have the connection saved in only one of these * slots, but someone could in a pathological case set system and session * bus to the same bus or something. Or set one of them to the starter * bus without setting the starter bus type in the env variable. * So we don't break the loop as soon as we find a match. */ for (i = 0; i < N_BUS_TYPES; ++i) { if (bus_connections[i] == connection) { bus_connections[i] = NULL; } } _DBUS_UNLOCK (bus); }
/** * Register a cleanup function to be called exactly once * the next time dbus_shutdown() is called. * * @param func the function * @param data data to pass to the function * @returns #FALSE on not enough memory */ dbus_bool_t _dbus_register_shutdown_func (DBusShutdownFunction func, void *data) { ShutdownClosure *c; c = dbus_new (ShutdownClosure, 1); if (c == NULL) return FALSE; c->func = func; c->data = data; _DBUS_LOCK (shutdown_funcs); c->next = registered_globals; registered_globals = c; _DBUS_UNLOCK (shutdown_funcs); return TRUE; }
void _dbus_user_database_unlock_system (void) { database_locked = FALSE; _DBUS_UNLOCK (system_users); }
/** * Connects to a bus daemon and registers the client with it. If a * connection to the bus already exists, then that connection is * returned. Caller owns a reference to the bus. * * @todo alex thinks we should nullify the connection when we get a disconnect-message. * * @param type bus type * @param error address where an error can be returned. * @returns a DBusConnection with new ref */ DBusConnection * dbus_bus_get (DBusBusType type, DBusError *error) { const char *address; DBusConnection *connection; BusData *bd; DBusBusType address_type; _dbus_return_val_if_fail (type >= 0 && type < N_BUS_TYPES, NULL); _dbus_return_val_if_error_is_set (error, NULL); _DBUS_LOCK (bus); if (!init_connections_unlocked ()) { _DBUS_UNLOCK (bus); _DBUS_SET_OOM (error); return NULL; } /* We want to use the activation address even if the * activating bus is the session or system bus, * per the spec. */ address_type = type; /* Use the real type of the activation bus for getting its * connection, but only if the real type's address is available. (If * the activating bus isn't a well-known bus then * activation_bus_type == DBUS_BUS_STARTER) */ if (type == DBUS_BUS_STARTER && bus_connection_addresses[activation_bus_type] != NULL) type = activation_bus_type; if (bus_connections[type] != NULL) { connection = bus_connections[type]; dbus_connection_ref (connection); _DBUS_UNLOCK (bus); return connection; } address = bus_connection_addresses[address_type]; if (address == NULL) { dbus_set_error (error, DBUS_ERROR_FAILED, "Unable to determine the address of the message bus"); _DBUS_UNLOCK (bus); return NULL; } connection = dbus_connection_open (address, error); if (!connection) { _DBUS_ASSERT_ERROR_IS_SET (error); _DBUS_UNLOCK (bus); return NULL; } /* By default we're bound to the lifecycle of * the message bus. */ dbus_connection_set_exit_on_disconnect (connection, TRUE); if (!dbus_bus_register (connection, error)) { _DBUS_ASSERT_ERROR_IS_SET (error); dbus_connection_close (connection); dbus_connection_unref (connection); _DBUS_UNLOCK (bus); return NULL; } bus_connections[type] = connection; bd = ensure_bus_data (connection); _dbus_assert (bd != NULL); bd->is_well_known = TRUE; _DBUS_UNLOCK (bus); return connection; }