public inbox for cygwin-xfree@sourceware.org
help / color / mirror / Atom feed
* XWin does not delete the lock files
@ 2010-03-31 14:14 Rodrigo Medina
  2010-04-05 21:10 ` Jon TURNEY
  0 siblings, 1 reply; 3+ messages in thread
From: Rodrigo Medina @ 2010-03-31 14:14 UTC (permalink / raw)
  To: cygwin-xfree

Hi,
I have found that XWin -multiwindow -clipboard & dos not remove the locl
files when it is stopped
with the 'Exit' button of the XWin menu

$ ls -Fa /tmp
./  ../  .X11-unix/
$ ls -Fa /tmp/.X11-unix/
./  ../


$ XWin -multiwindow -clipboard & 
$ Welcome to the XWin X Server
Vendor: The Cygwin/X Project
Release: 1.7.6.0 (10706000)
....

Then XWin is stopped with the 'Exit'  button
$ winDeinitMultiWindowWM - Noting shutdown in progress
winClipboardProc - winClipboardFlushWindowsMessageQueue trapped WM_QUIT
message, exiting main loop.
winClipboardProc - XDestroyWindow succeeded.
winClipboardIOErrorHandler!


[1]+  Done                    XWin -multiwindow -clipboard
$ ls -Fa /tmp
./  ../  .X0-lock  .X11-unix/
$ ls -Fa /tmp/.X11-unix/
./  ../  X0=

Bye
Rodrigo Medina



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: XWin does not delete the lock files
  2010-03-31 14:14 XWin does not delete the lock files Rodrigo Medina
@ 2010-04-05 21:10 ` Jon TURNEY
  2010-04-05 21:33   ` [PATCH] Store pthread_ids and chain IOError handlers to avoid longjmp across threads Jon TURNEY
  0 siblings, 1 reply; 3+ messages in thread
From: Jon TURNEY @ 2010-04-05 21:10 UTC (permalink / raw)
  To: cygwin-xfree; +Cc: rodmedina

On 30/03/2010 22:02, Rodrigo Medina wrote:
> I have found that XWin -multiwindow -clipboard&  dos not remove the lock
> files when it is stopped
> with the 'Exit' button of the XWin menu
[...]

Thanks for the reproduction steps here, although I wasn't able to reproduce 
the problem without also connecting an xterm before shutting down the X server.

At least part of the problem seems to be awesomely bad multi-threaded code: It 
looks like the code thinks XSetIOErrorHandler() sets a per-thread handler, 
rather than the global handler it actually sets, so each client thread sets it 
to a handler which longjmp()s somewhere, and we end up getting the last one 
which happened to get installed if the handler ever actually gets called, with 
hilarious consequences... (longjmp()ing to a setjmp() buffer allocated in 
another thread being undefined, and even if it happens to work, it isn't going 
to do the right thing)

This also seems to be the cause of the segfault on shutdown you have reported 
in another thread.

I've had a go at working around these issues a bit, although the only way of 
handling the multithreading correctly looks to be to re-write the clipboard 
and multiwindow WM to use xcb.

Perhaps you could try out the test build I have uploaded at [1] and see if 
that resolves this problem for you?

[1] ftp://cygwin.com/pub/cygwinx/XWin.20100405215019.exe.bz2

-- 
Jon TURNEY
Volunteer Cygwin/X X Server maintainer

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] Store pthread_ids and chain IOError handlers to avoid longjmp across threads
  2010-04-05 21:10 ` Jon TURNEY
@ 2010-04-05 21:33   ` Jon TURNEY
  0 siblings, 0 replies; 3+ messages in thread
From: Jon TURNEY @ 2010-04-05 21:33 UTC (permalink / raw)
  To: cygwin-xfree; +Cc: Jon TURNEY

Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
---
 hw/xwin/winclipboardthread.c |   24 +++++++++++++-----
 hw/xwin/winmultiwindowwm.c   |   54 ++++++++++++++++++++++++++++--------------
 2 files changed, 53 insertions(+), 25 deletions(-)

diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c
index f61037c..be8126f 100644
--- a/hw/xwin/winclipboardthread.c
+++ b/hw/xwin/winclipboardthread.c
@@ -58,6 +58,9 @@ extern Window		g_iClipboardWindow;
  */
 
 static jmp_buf			g_jmpEntry;
+static XIOErrorHandler g_winClipboardOldIOErrorHandler;
+static pthread_t g_winClipboardProcThread;
+
 Bool				g_fUnicodeSupport = FALSE;
 Bool				g_fUseUnicode = FALSE;
 
@@ -122,6 +125,11 @@ winClipboardProc (void *pvNotUsed)
       ErrorF ("winClipboardProc - Warning: Locale not supported by X.\n");
     }
 
+  /* Set error handler */
+  XSetErrorHandler (winClipboardErrorHandler);
+  g_winClipboardProcThread = pthread_self();
+  g_winClipboardOldIOErrorHandler = XSetIOErrorHandler (winClipboardIOErrorHandler);
+
   /* Set jump point for Error exits */
   iReturn = setjmp (g_jmpEntry);
   
@@ -144,10 +152,6 @@ winClipboardProc (void *pvNotUsed)
   /* Use our generated cookie for authentication */
   winSetAuthorization();
 
-  /* Set error handler */
-  XSetErrorHandler (winClipboardErrorHandler);
-  XSetIOErrorHandler (winClipboardIOErrorHandler);
-
   /* Initialize retry count */
   iRetries = 0;
 
@@ -452,8 +456,14 @@ winClipboardIOErrorHandler (Display *pDisplay)
 {
   ErrorF ("winClipboardIOErrorHandler!\n\n");
 
-  /* Restart at the main entry point */
-  longjmp (g_jmpEntry, WIN_JMP_ERROR_IO);
-  
+  if (pthread_equal(pthread_self(),g_winClipboardProcThread))
+    {
+      /* Restart at the main entry point */
+      longjmp (g_jmpEntry, WIN_JMP_ERROR_IO);
+    }
+
+  if (g_winClipboardOldIOErrorHandler)
+    g_winClipboardOldIOErrorHandler(pDisplay);
+
   return 0;
 }
diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c
index 43c047c..3f231bc 100644
--- a/hw/xwin/winmultiwindowwm.c
+++ b/hw/xwin/winmultiwindowwm.c
@@ -203,7 +203,11 @@ winUpdateWindowPosition (HWND hWnd, Bool reshape, HWND *zstyle);
  */
 
 static jmp_buf			g_jmpWMEntry;
+static XIOErrorHandler g_winMultiWindowWMOldIOErrorHandler;
+static pthread_t g_winMultiWindowWMThread;
 static jmp_buf			g_jmpXMsgProcEntry;
+static XIOErrorHandler g_winMultiWindowXMsgProcOldIOErrorHandler;
+static pthread_t g_winMultiWindowXMsgProcThread;
 static Bool			g_shutdown = FALSE;
 static Bool			redirectError = FALSE;
 static Bool			g_fAnotherWMRunning = FALSE;
@@ -900,9 +904,14 @@ winMultiWindowXMsgProc (void *pArg)
 
   ErrorF ("winMultiWindowXMsgProc - pthread_mutex_unlock () returned.\n");
 
+  /* Install our error handler */
+  XSetErrorHandler (winMultiWindowXMsgProcErrorHandler);
+  g_winMultiWindowXMsgProcThread = pthread_self();
+  g_winMultiWindowXMsgProcOldIOErrorHandler = XSetIOErrorHandler (winMultiWindowXMsgProcIOErrorHandler);
+
   /* Set jump point for IO Error exits */
   iReturn = setjmp (g_jmpXMsgProcEntry);
-  
+
   /* Check if we should continue operations */
   if (iReturn != WIN_JMP_ERROR_IO
       && iReturn != WIN_JMP_OKAY)
@@ -918,10 +927,6 @@ winMultiWindowXMsgProc (void *pArg)
       pthread_exit (NULL);
     }
 
-  /* Install our error handler */
-  XSetErrorHandler (winMultiWindowXMsgProcErrorHandler);
-  XSetIOErrorHandler (winMultiWindowXMsgProcIOErrorHandler);
-
   /* Setup the display connection string x */
   winGetDisplayName(pszDisplay, (int)pProcArg->dwScreen);
 
@@ -1282,9 +1287,14 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg)
 
   ErrorF ("winInitMultiWindowWM - pthread_mutex_unlock () returned.\n");
 
+  /* Install our error handler */
+  XSetErrorHandler (winMultiWindowWMErrorHandler);
+  g_winMultiWindowWMThread = pthread_self();
+  g_winMultiWindowWMOldIOErrorHandler = XSetIOErrorHandler (winMultiWindowWMIOErrorHandler);
+
   /* Set jump point for IO Error exits */
   iReturn = setjmp (g_jmpWMEntry);
-  
+
   /* Check if we should continue operations */
   if (iReturn != WIN_JMP_ERROR_IO
       && iReturn != WIN_JMP_OKAY)
@@ -1300,10 +1310,6 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg)
       pthread_exit (NULL);
     }
 
-  /* Install our error handler */
-  XSetErrorHandler (winMultiWindowWMErrorHandler);
-  XSetIOErrorHandler (winMultiWindowWMIOErrorHandler);
-
   /* Setup the display connection string x */
   winGetDisplayName(pszDisplay, (int)pProcArg->dwScreen);
 
@@ -1426,12 +1432,18 @@ winMultiWindowWMIOErrorHandler (Display *pDisplay)
 {
   ErrorF ("winMultiWindowWMIOErrorHandler!\n\n");
 
-  if (g_shutdown)
-    pthread_exit(NULL);
+  if (pthread_equal(pthread_self(),g_winMultiWindowWMThread))
+    {
+      if (g_shutdown)
+        pthread_exit(NULL);
+
+      /* Restart at the main entry point */
+      longjmp (g_jmpWMEntry, WIN_JMP_ERROR_IO);
+    }
+
+  if (g_winMultiWindowWMOldIOErrorHandler)
+    g_winMultiWindowWMOldIOErrorHandler(pDisplay);
 
-  /* Restart at the main entry point */
-  longjmp (g_jmpWMEntry, WIN_JMP_ERROR_IO);
-  
   return 0;
 }
 
@@ -1466,9 +1478,15 @@ winMultiWindowXMsgProcIOErrorHandler (Display *pDisplay)
 {
   ErrorF ("winMultiWindowXMsgProcIOErrorHandler!\n\n");
 
-  /* Restart at the main entry point */
-  longjmp (g_jmpXMsgProcEntry, WIN_JMP_ERROR_IO);
-  
+  if (pthread_equal(pthread_self(),g_winMultiWindowXMsgProcThread))
+    {
+      /* Restart at the main entry point */
+      longjmp (g_jmpXMsgProcEntry, WIN_JMP_ERROR_IO);
+    }
+
+  if (g_winMultiWindowXMsgProcOldIOErrorHandler)
+    g_winMultiWindowXMsgProcOldIOErrorHandler(pDisplay);
+
   return 0;
 }
 
-- 
1.7.0.4


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://x.cygwin.com/docs/
FAQ:                   http://x.cygwin.com/docs/faq/


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-04-05 21:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-31 14:14 XWin does not delete the lock files Rodrigo Medina
2010-04-05 21:10 ` Jon TURNEY
2010-04-05 21:33   ` [PATCH] Store pthread_ids and chain IOError handlers to avoid longjmp across threads Jon TURNEY

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).