<div dir="auto"><div><div class="gmail_extra"><div class="gmail_quote">On Feb 1, 2017 9:23 AM, "Arthur Huillet" <<a href="mailto:arthur.huillet@free.fr">arthur.huillet@free.fr</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="quoted-text">On Wed, 1 Feb 2017 09:12:47 -0800<br>
Jamey Sharp <<a href="mailto:jamey@minilop.net">jamey@minilop.net</a>> wrote:<br></div><div class="quoted-text">
> I'm a little confused by the notes in the commit message about whether this<br>
> is legal. I don't know why it should be considered legal to use a Display<br>
> from a _fini or atexit handler… although this has been a source of bugs for<br>
> C++ apps in the past, so clearly people do it. I guess "there exist apps in<br>
> the wild that do this" is as good a definition of what's legal in Xlib as<br>
> any. But if you have a more specific reference for why it's legal, it'd be<br>
> nice to have that.<br>
<br>
</div>I am surprised that the notion that it is legal would require discussion.<br>
It's not forbidden anywhere (that I'm aware of), therefore, it's allowed. Doesn't that reasoning work?<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">I guess that's kind of a philosophical question, made more confusing by Xlib's long history.</div><div dir="auto"><br></div><div dir="auto">In my opinion, and speaking about software in general: no, I don't think that's sound reasoning. :-) It leads to brittle software that relies on accidents of implementation which may change without notice.</div><div dir="auto"><br></div><div dir="auto">The story for Xlib is more complicated, because in practice, its specification is not its documentation, but rather, "if it worked ten years ago, it should probably work now." Of course this means Xlib is nearly impossible to maintain. On a related note: many thanks to the people who continue maintaining Xlib anyway. :-)</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Yes, it sounds completely useless...</blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">I never said that. :-) I just thought, from your use of the word "legal", that you'd found explicit justification for this behavior in the documentation. If you had, then there would be no question that a patch like this is necessary, and that would be useful to call out in the commit message.</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="quoted-text">As for clarification of the commit message, I thought that the paragraph mentioning dlopen/dlclose was covering the problem.<br></div>
What do you feel needs clarifying?<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">You said all that in the commit message but I didn't understand it. :-) It's not super important I guess.</div><div dir="auto"><br></div><div dir="auto">But: have you considered not using Xlib to issue requests, at least in your _fini handler? I think it should always be safe to call XGetXCBConnection and then issue your cleanup requests using XCB, which is carefully designed to be safe in any context except signal handlers. That would make the driver work on older Xlib installations too.</div><div dir="auto"><br></div><div dir="auto">I'll also point out that I believe using a _fini handler to do X resource cleanup is guaranteed to break if the application calls fork. Both the parent and the child will attempt to clean up the resources, and one of them will find the X connection is in the wrong state. If the other process was still using that connection, it will probably hang next time it tries to get a reply. Finding a different hook to do cleanup would be better.</div><div dir="auto"><br></div><div dir="auto">I'll still offer a</div><div dir="auto"><br></div><div dir="auto">Reviewed-by: Jamey Sharp <<a href="mailto:jamey@minilop.net">jamey@minilop.net</a>></div><div dir="auto"><br></div><div dir="auto">because with Xlib, all we can do is harm reduction. If people insist on doing things like this, we can at least try to minimize end-users' suffering.</div><div dir="auto"><br></div><div dir="auto">Jamey</div></div>