From 95523387d619af5b400748898d722e080b5ce1a6 Mon Sep 17 00:00:00 2001 From: Jamey Sharp Date: Sat, 2 Jun 2007 11:57:39 -0700 Subject: [PATCH] Allow re-entrant Xlib calls from _XIOError. Some libraries try to clean up X resources from atexit handlers, _fini, or C++ destructors. To make these work, the Display lock should be downgraded to a user lock (as in XLockDisplay) before calling exit(3). This blocks Xlib calls from threads other than the one calling exit(3) while still allowing the exit handlers to call Xlib. This assumes that the thread calling exit will call any atexit handlers. If this does not hold, then an alternate solution would involve registering an atexit handler to take over the lock, which would only assume that the same thread calls all the atexit handlers. Commit by Josh Triplett and Jamey Sharp. --- src/XlibInt.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/XlibInt.c b/src/XlibInt.c index 1d025c7b..d6e72204 100644 --- a/src/XlibInt.c +++ b/src/XlibInt.c @@ -2926,6 +2926,16 @@ _XIOError ( errno = WSAGetLastError(); #endif + /* This assumes that the thread calling exit will call any atexit handlers. + * If this does not hold, then an alternate solution would involve + * registering an atexit handler to take over the lock, which would only + * assume that the same thread calls all the atexit handlers. */ +#ifdef XTHREADS + if (dpy->lock) + (*dpy->lock->user_lock_display)(dpy); +#endif + UnlockDisplay(dpy); + if (_XIOErrorFunction != NULL) (*_XIOErrorFunction)(dpy); else