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 <leandrohr@riseup.net>
dev
Leandro Ribeiro 5 years ago committed by Pekka Paalanen
parent 9aaaf96a6a
commit d65483ec75
  1. 3
      libweston/weston-log-internal.h
  2. 16
      libweston/weston-log-wayland.c
  3. 24
      libweston/weston-log.c

@ -72,9 +72,6 @@ weston_log_subscription_create(struct weston_log_subscriber *owner,
void void
weston_log_subscription_destroy(struct weston_log_subscription *sub); 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 void
weston_log_subscription_add(struct weston_log_scope *scope, weston_log_subscription_add(struct weston_log_scope *scope,
struct weston_log_subscription *sub); struct weston_log_subscription *sub);

@ -162,6 +162,8 @@ static void
weston_log_debug_wayland_to_destroy(struct weston_log_subscriber *sub) weston_log_debug_wayland_to_destroy(struct weston_log_subscriber *sub)
{ {
struct weston_log_debug_wayland *stream = to_weston_log_debug_wayland(sub); struct weston_log_debug_wayland *stream = to_weston_log_debug_wayland(sub);
if (stream->fd != -1)
stream_close_on_failure(stream, "debug name removed"); stream_close_on_failure(stream, "debug name removed");
} }
@ -201,20 +203,10 @@ static void
stream_destroy(struct wl_resource *stream_resource) stream_destroy(struct wl_resource *stream_resource)
{ {
struct weston_log_debug_wayland *stream; struct weston_log_debug_wayland *stream;
struct weston_log_subscription *sub = NULL;
stream = wl_resource_get_user_data(stream_resource); stream = wl_resource_get_user_data(stream_resource);
if (stream->fd != -1) stream_close_unlink(stream);
close(stream->fd); weston_log_subscriber_release(&stream->base);
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);
free(stream); free(stream);
} }

@ -293,30 +293,6 @@ weston_log_subscription_destroy(struct weston_log_subscription *sub)
free(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 /** Adds the subscription \c sub to the subscription list of the
* scope. * scope.
* *

Loading…
Cancel
Save