Commit d65483ec authored by Leandro Ribeiro's avatar Leandro Ribeiro Committed by Pekka Paalanen

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: default avatarLeandro Ribeiro <leandrohr@riseup.net>
parent 9aaaf96a
......@@ -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);
......
......@@ -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);
}
......
......@@ -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.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment