From d65483ec75cc8c0dc29353d3393cb99bed42ee3c Mon Sep 17 00:00:00 2001 From: Leandro Ribeiro Date: Mon, 3 Feb 2020 23:45:59 -0300 Subject: [PATCH] weston-log-wayland: make stream_destroy() use weston_log_subscriber_release() Make stream_destroy() use weston_log_subscriber_release(). This avoids code duplication and allow us to destroy weston_log_subscriber_get_only_subscription(), since it's being used only in this case and it's internal. Calls for weson_log_subscriber_release() leads to weston_log_debug_wayland_to_destroy(), which should not send an error event when the stream has already been closed. Also, stream_destroy() shouldn't lead to an event error, as it is a wl_resource destroy handler. So close the stream before calling weston_log_subscriber_release() in stream_destroy() Signed-off-by: Leandro Ribeiro --- libweston/weston-log-internal.h | 3 --- libweston/weston-log-wayland.c | 18 +++++------------- libweston/weston-log.c | 24 ------------------------ 3 files changed, 5 insertions(+), 40 deletions(-) diff --git a/libweston/weston-log-internal.h b/libweston/weston-log-internal.h index 02a05f19..f1bfa6a5 100644 --- a/libweston/weston-log-internal.h +++ b/libweston/weston-log-internal.h @@ -72,9 +72,6 @@ weston_log_subscription_create(struct weston_log_subscriber *owner, void weston_log_subscription_destroy(struct weston_log_subscription *sub); -struct weston_log_subscription * -weston_log_subscriber_get_only_subscription(struct weston_log_subscriber *subscriber); - void weston_log_subscription_add(struct weston_log_scope *scope, struct weston_log_subscription *sub); diff --git a/libweston/weston-log-wayland.c b/libweston/weston-log-wayland.c index 732439f2..0add7728 100644 --- a/libweston/weston-log-wayland.c +++ b/libweston/weston-log-wayland.c @@ -162,7 +162,9 @@ static void weston_log_debug_wayland_to_destroy(struct weston_log_subscriber *sub) { struct weston_log_debug_wayland *stream = to_weston_log_debug_wayland(sub); - stream_close_on_failure(stream, "debug name removed"); + + if (stream->fd != -1) + stream_close_on_failure(stream, "debug name removed"); } static struct weston_log_debug_wayland * @@ -201,20 +203,10 @@ static void stream_destroy(struct wl_resource *stream_resource) { struct weston_log_debug_wayland *stream; - struct weston_log_subscription *sub = NULL; - stream = wl_resource_get_user_data(stream_resource); - if (stream->fd != -1) - close(stream->fd); - - sub = weston_log_subscriber_get_only_subscription(&stream->base); - - /* we can have a zero subscription if clients tried to subscribe - * to a non-existent scope */ - if (sub) - weston_log_subscription_destroy(sub); - + stream_close_unlink(stream); + weston_log_subscriber_release(&stream->base); free(stream); } diff --git a/libweston/weston-log.c b/libweston/weston-log.c index 7d85a6be..b6f46c31 100644 --- a/libweston/weston-log.c +++ b/libweston/weston-log.c @@ -293,30 +293,6 @@ weston_log_subscription_destroy(struct weston_log_subscription *sub) free(sub); } -/** Retrieve a subscription by using the subscriber - * - * This is useful when trying to find a subscription from the subscriber by - * having only access to the stream. - * - * @param subscriber the subscriber in question - * @returns a weston_log_subscription object - * - * @memberof weston_log_subscription - */ -struct weston_log_subscription * -weston_log_subscriber_get_only_subscription(struct weston_log_subscriber *subscriber) -{ - struct weston_log_subscription *sub; - /* unlikely, but can happen */ - if (wl_list_length(&subscriber->subscription_list) == 0) - return NULL; - - assert(wl_list_length(&subscriber->subscription_list) == 1); - - return wl_container_of(subscriber->subscription_list.prev, - sub, owner_link); -} - /** Adds the subscription \c sub to the subscription list of the * scope. *