diff --git a/src/pipewire/context.c b/src/pipewire/context.c index 650804429..846238277 100644 --- a/src/pipewire/context.c +++ b/src/pipewire/context.c @@ -496,7 +496,7 @@ struct pw_global *pw_context_find_global(struct pw_context *context, uint32_t id struct pw_global *global; global = pw_map_lookup(&context->globals, id); - if (global == NULL) { + if (global == NULL || global->destroyed) { errno = ENOENT; return NULL; } diff --git a/src/pipewire/global.c b/src/pipewire/global.c index dabf23fcc..0f9218e6e 100644 --- a/src/pipewire/global.c +++ b/src/pipewire/global.c @@ -37,7 +37,6 @@ /** \cond */ struct impl { struct pw_global this; - bool registered; }; /** \endcond */ @@ -127,15 +126,14 @@ error_cleanup: SPA_EXPORT int pw_global_register(struct pw_global *global) { - struct impl *impl = SPA_CONTAINER_OF(global, struct impl, this); struct pw_resource *registry; struct pw_context *context = global->context; - if (impl->registered) + if (global->registered) return -EEXIST; spa_list_append(&context->global_list, &global->link); - impl->registered = true; + global->registered = true; spa_list_for_each(registry, &context->registry_resource_list, link) { uint32_t permissions = pw_global_get_permissions(global, registry->client); @@ -157,11 +155,10 @@ int pw_global_register(struct pw_global *global) static int global_unregister(struct pw_global *global) { - struct impl *impl = SPA_CONTAINER_OF(global, struct impl, this); struct pw_context *context = global->context; struct pw_resource *resource; - if (!impl->registered) + if (!global->registered) return 0; spa_list_for_each(resource, &context->registry_resource_list, link) { @@ -173,7 +170,7 @@ static int global_unregister(struct pw_global *global) spa_list_remove(&global->link); pw_map_remove(&context->globals, global->id); - impl->registered = false; + global->registered = false; pw_log_debug(NAME" %p: unregistered %u", global, global->id); pw_context_emit_global_removed(context, global); @@ -215,8 +212,7 @@ SPA_EXPORT int pw_global_update_keys(struct pw_global *global, const struct spa_dict *dict, const char *keys[]) { - struct impl *impl = SPA_CONTAINER_OF(global, struct impl, this); - if (impl->registered) + if (global->registered) return -EINVAL; return pw_properties_update_keys(global->properties, dict, keys); } @@ -378,6 +374,8 @@ void pw_global_destroy(struct pw_global *global) { struct pw_resource *resource; + global->destroyed = true; + pw_log_debug(NAME" %p: destroy %u", global, global->id); pw_global_emit_destroy(global); diff --git a/src/pipewire/impl-client.c b/src/pipewire/impl-client.c index 822eb2e6e..becbc1956 100644 --- a/src/pipewire/impl-client.c +++ b/src/pipewire/impl-client.c @@ -700,6 +700,7 @@ void pw_impl_client_set_busy(struct pw_impl_client *client, bool busy) pw_impl_client_emit_busy_changed(client, busy); } } + SPA_EXPORT int pw_impl_client_check_permissions(struct pw_impl_client *client, uint32_t global_id, uint32_t permissions) diff --git a/src/pipewire/private.h b/src/pipewire/private.h index 76d170f19..6e8531c7c 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -219,6 +219,9 @@ struct pw_global { void *object; /**< object associated with the interface */ struct spa_list resource_list; /**< The list of resources of this global */ + + unsigned int registered:1; + unsigned int destroyed:1; }; #define pw_core_resource(r,m,v,...) pw_resource_call(r, struct pw_core_events, m, v, ##__VA_ARGS__)