<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On 19 April 2014 10:22, Pekka Paalanen <span dir="ltr"><<a href="mailto:ppaalanen@gmail.com" target="_blank">ppaalanen@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, 18 Apr 2014 12:27:59 +0200<br>
<div><div class="h5">Marek Chalupa <<a href="mailto:mchqwerty@gmail.com">mchqwerty@gmail.com</a>> wrote:<br>
<br>
> On 15 April 2014 15:36, Pekka Paalanen <<a href="mailto:ppaalanen@gmail.com">ppaalanen@gmail.com</a>> wrote:<br>
><br>
> > On Fri, 11 Apr 2014 11:39:13 +0200<br>
> > Marek Chalupa <<a href="mailto:mchqwerty@gmail.com">mchqwerty@gmail.com</a>> wrote:<br>
> ><br>
> > > When an error occures, than wl_display_get_error() do not<br>
> > > provide any way of getting know if it was a local error or if it was<br>
> > > an error event, respectively what object caused the error and what<br>
> > > the error was.<br>
> > ><br>
> > > This patch introduces a new function wl_display_get_protocol_error()<br>
> > > which will return error code, interface and id of the object that<br>
> > > generated the error.<br>
> > > wl_display_get_error() will work the same way as before.<br>
> > ><br>
> > > wl_display_get_protcol_error() DO NOT indicate that the error happed.<br>
> > > It returns valid information only in that case that (protocol) error<br>
> > > happend, so it should be used after calling wl_display_get_error()<br>
> > > with positive result.<br>
> > ><br>
> > > Thanks to Pekka Paalanen <<a href="mailto:ppaalanen@gmail.com">ppaalanen@gmail.com</a>> for pointing out<br>
> > > issues in the first versions of this patch.<br>
> > > ---<br>
> > > src/wayland-client.c | 149<br>
> > +++++++++++++++++++++++++++++++++++++++++++++------<br>
> > > src/wayland-client.h | 3 ++<br>
> > > 2 files changed, 136 insertions(+), 16 deletions(-)<br>
> > ><br>
> > > diff --git a/src/wayland-client.c b/src/wayland-client.c<br>
> > > index bd40313..7f21fcd 100644<br>
> > > --- a/src/wayland-client.c<br>
> > > +++ b/src/wayland-client.c<br>
> > > @@ -78,7 +78,25 @@ struct wl_event_queue {<br>
> > > struct wl_display {<br>
> > > struct wl_proxy proxy;<br>
> > > struct wl_connection *connection;<br>
> > > +<br>
> > > + /* errno of the last wl_display error or 1 when the error<br>
> > > + * came via wire as an event */<br>
> ><br>
> > 1 is EPERM, we might just pick an errno that fits best, and call it<br>
> > that.<br>
> ><br>
> ><br>
> True, 1 is not a right choice. All errnos are positive, so what about to<br>
> use -1? Then the wl_display_get_error() would return the same as before for<br>
> local errors and -1 for protocol errors.<br>
<br>
</div></div>Looking at the manual page of errno, it doesn't explicitly require<br>
errno to be non-negative, so I guess -1 would be ok.<br>
<br>
It seems POSIX.1 defines EPROTO, maybe what would be approriate<br>
for custom (non-wl_display) protocol errors instead?<br>
It would make strerror() spew something more understandable.<br></blockquote><div> </div><div>EPROTO sounds good to me.<br> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="">
> > But does the code really do this?<br>
> ><br>
> > I suppose we are still free to pick the errno, since the implementation<br>
> > so far has been buggy, interpreting all protocol error codes in the<br>
> > wl_display context and picking the errno based on that, instead<br>
> > accounting for the actual interface it came with.<br>
> ><br>
><br>
> The current implementation is buggy, but what if some old code relies on<br>
> currently picked errnos? On the other hand, I think that in most cases it<br>
> does not, so it wouldn't do much damage to pick errno freely.<br>
<br>
</div>Yeah, I would not worry about it.<br>
<div><div class="h5"><br>
> > > @@ -579,25 +643,32 @@ display_handle_error(void *data,<br>
> > > uint32_t code, const char *message)<br>
> > > {<br>
> > > struct wl_proxy *proxy = object;<br>
> > > - int err;<br>
> > > + int err = 1;<br>
> > ><br>
> > > wl_log("%s@%u: error %d: %s\n",<br>
> > > proxy->object.interface->name, proxy-><a href="http://object.id" target="_blank">object.id</a>, code,<br>
> > message);<br>
> > ><br>
> > > - switch (code) {<br>
> > > - case WL_DISPLAY_ERROR_INVALID_OBJECT:<br>
> > > - case WL_DISPLAY_ERROR_INVALID_METHOD:<br>
> > > - err = EINVAL;<br>
> > > - break;<br>
> > > - case WL_DISPLAY_ERROR_NO_MEMORY:<br>
> > > - err = ENOMEM;<br>
> > > - break;<br>
> > > - default:<br>
> > > - err = EFAULT;<br>
> > > - break;<br>
> > > + /* due to compatibility, we must pass an errno to<br>
> > display_protocol_error()<br>
> > > + * (for setting display->last_error). I can imagine that later<br>
> > this code<br>
> > > + * is deleted and protocol errors will have display->last_error<br>
> > set to 1<br>
> > > + */<br>
> > > + if (wl_interface_equal(proxy->object.interface,<br>
> > &wl_display_interface)) {<br>
> > > + switch (code) {<br>
> > > + case WL_DISPLAY_ERROR_INVALID_OBJECT:<br>
> > > + case WL_DISPLAY_ERROR_INVALID_METHOD:<br>
> > > + err = EINVAL;<br>
> > > + break;<br>
> > > + case WL_DISPLAY_ERROR_NO_MEMORY:<br>
> > > + err = ENOMEM;<br>
> > > + break;<br>
> > > + default:<br>
> > > + err = EFAULT;<br>
> > > + break;<br>
> > > + }<br>
> ><br>
> > This is what referred to at the top, we still set the errno as before<br>
> > instead of 1, right?<br>
> ><br>
> ><br>
> Yes, but now only for wl_display object.<br>
><br>
> I think we need to keep this, so we don't change the<br>
> > behaviour in the valid use case of wl_display_get_error().<br>
> ><br>
> ><br>
> Yes, that's the point of this part of code. Anyway, it would be nice to do<br>
> not do that, because it<br>
> causes inconsistency in identifying protocol vs. local errors. I hope it<br>
> could be removed some day.<br>
<br>
</div></div>I'm not sure. Protocol errors on wl_display are sort of special,<br>
like generic "out of memory" that is not tied to any specific<br>
protocol extension. I'd say keep the behaviour for wl_display, and<br>
change it for everything else.<br>
<div class=""><br></div></blockquote><div> </div><div>I'm totally OK with ENOMEM, it's reasonable - once you're out of memory, it<br>doesn't matter where the error occurred. But when we will set EINVAL for the<br>
</div><div>invalid object/method (protocol errors) then it will make it harder to<br></div><div>tell off these errors from local errors, i. e. EINVAL from recvmsg. I'd rather<br>set EPROTO for these two as well.<br><br>
However, I don't see it as a big deal and I'm OK with keeping these errnos as it is,<br>so I'm sending new version of a patch.<br><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="">
> Actually, if we would be picking new errnos, as you wrote before, then I<br>
> don't see any reason for this<br>
> code to be here any more. Once you change the numbers that will<br>
> wl_display_get_error() return,<br>
> let's do it properly :)<br>
<br>
</div>That's what I am aiming for. Let's keep the return codes that make<br>
sense, and fix the rest.<br>
<br>
So we'd be picking a new errno only for non-wl_display error<br>
events. Up to now, they have been practically undefined.<br>
<div><div class="h5"><br>
> > > diff --git a/src/wayland-client.h b/src/wayland-client.h<br>
> > > index 2a32785..61aec0c 100644<br>
> > > --- a/src/wayland-client.h<br>
> > > +++ b/src/wayland-client.h<br>
> > > @@ -161,6 +161,9 @@ int wl_display_dispatch_queue_pending(struct<br>
> > wl_display *display,<br>
> > > struct wl_event_queue *queue);<br>
> > > int wl_display_dispatch_pending(struct wl_display *display);<br>
> > > int wl_display_get_error(struct wl_display *display);<br>
> > > +int wl_display_get_protocol_error(struct wl_display *display,<br>
> > > + const struct wl_interface **interface,<br>
> > > + unsigned int *id);<br>
> > ><br>
> > > int wl_display_flush(struct wl_display *display);<br>
> > > int wl_display_roundtrip(struct wl_display *display);<br>
> ><br>
> > Right, I like this idea, not only because it was something I wished<br>
> > for. :-)<br>
> ><br>
> > I read through this patch, but didn't have time to do an in-depth<br>
> > review of the correctness yet.<br>
> ><br>
> ><br>
> > Thanks,<br>
> > pq<br>
> ><br>
><br>
> Thanks for comments. To sum it up, I'd like to do it like:<br>
><br>
> wl_display_get_error() would return 0 when no error occurred, errno for<br>
> local errors (that's the same as now) and -1 for protocol errors. Then you<br>
> could use it like:<br>
><br>
> err = wl_display_get_error(display);<br>
><br>
> if (err == -1) {<br>
> wl_display_get_protocol_error(....);<br>
> ... /* handle protocol errors */<br>
> } else if (err) {<br>
> ... /* handle errors */<br>
> }<br>
<br>
</div></div>Yeah, something like that.<br>
<br>
<br>
Thanks,<br>
pq<br>
</blockquote></div><br></div></div>