proto, server: Add internal server error message. (v2)

Many languages such as C++ or Rust have an unwinding error-reporting
mechanism. Code in these languages can (and must!) wrap request handling
callbacks in unwind guards to avoid undefined behaviour.

As a consequence such code will detect internal server errors, but have
no way to communicate such failures to the client.

This adds a WL_DISPLAY_ERROR_IMPLEMENTATION error to wl_display so that
such code can notify (and disconnect) clients which hit internal bugs.
While servers can currently abuse other wl_display errors for the same
effect, adding an explicit error code allows clients to tell the
difference between errors which are their fault and errors which are the
server's fault. This is particularly interesting for automated bug
reporting.

v2: Rename error from "internal" to "implementation", in sympathy with
    X11's BadImplementation error.
    Add more justification in the commit message.

Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.com>
This commit is contained in:
Christopher James Halse Rogers 2018-11-20 18:02:50 +11:00 committed by Pekka Paalanen
parent 10c1f37a7c
commit d325140289
5 changed files with 73 additions and 0 deletions

View file

@ -185,6 +185,9 @@ display_protocol_error(struct wl_display *display, uint32_t code,
case WL_DISPLAY_ERROR_NO_MEMORY:
err = ENOMEM;
break;
case WL_DISPLAY_ERROR_IMPLEMENTATION:
err = EPROTO;
break;
default:
err = EFAULT;
}

View file

@ -324,6 +324,10 @@ wl_client_get_object(struct wl_client *client, uint32_t id);
void
wl_client_post_no_memory(struct wl_client *client);
void
wl_client_post_implementation_error(struct wl_client *client,
const char* msg, ...) WL_PRINTF(2,3);
void
wl_client_add_resource_created_listener(struct wl_client *client,
struct wl_listener *listener);

View file

@ -650,6 +650,30 @@ wl_client_post_no_memory(struct wl_client *client)
WL_DISPLAY_ERROR_NO_MEMORY, "no memory");
}
/** Report an internal server error
*
* \param client The client object
* \param msg A printf-style format string
* \param ... Format string arguments
*
* Report an unspecified internal implementation error and disconnect
* the client.
*
* \memberof wl_client
*/
WL_EXPORT void
wl_client_post_implementation_error(struct wl_client *client,
char const *msg, ...)
{
va_list ap;
va_start(ap, msg);
wl_resource_post_error_vargs(client->display_resource,
WL_DISPLAY_ERROR_IMPLEMENTATION,
msg, ap);
va_end(ap);
}
WL_EXPORT void
wl_resource_post_no_memory(struct wl_resource *resource)
{