public inbox for cygwin-xfree@sourceware.org
help / color / mirror / Atom feed
From: Jon TURNEY <jon.turney@dronecode.org.uk>
To: cygwin-xfree@cygwin.com
Cc: hummel.michel@gmail.com
Subject: Re: XWin crash after the launch of startkde on a remote Red Hat 5 machine
Date: Sun, 31 Oct 2010 16:59:00 -0000	[thread overview]
Message-ID: <4CCDA052.8090903@dronecode.org.uk> (raw)
In-Reply-To: <AANLkTi=R+HAtOfnpo8aHF6P=3T1CHU1ANLh7nUnSi3cE@mail.gmail.com>

On 29/09/2010 15:05, Michel Hummel wrote:
> You will find attached to this Email the modifications you asked.
>
> The X server doesn't freeze anymore when clipboard restarts on xdmcp,
> certainly fixed by the cygwin patches.
>
> I added a rate-limit of clipboard_generation which disables restart after
> XWIN_CLIPBOARD_RETRIES retries (defined to 40 in winclipboard.h)
> and a sleep(XWIN_CLIPBOARD_DELAY) before retries (defined to 1 in
> winclipboard.h)
>
> I hope you will like this new version

I really appreciate your work on this set of patches, and I'm sorry it's taken 
me so long to get around to looking at them.

I must confess that the size of each patch didn't help.  You can never make 
patches too small :-).  'git gui' and 'git rebase --interactive' are excellent 
tools for splitting, merging and reordering patches.

I've merged most of it, with some tweaks and rearrangement into my latest 
snapshot (code is at [1]), and it should be included in a 1.9.1-1 release I'll 
be making shortly.

A few detailed comments:

I really want to keep fdMessageQueue under HAS_DEVWINDOWS for clarity and for 
ease of sharing patches with XMing, so I had to rearrange things a bit to 
permit that.

diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c
index f85d8cf..5c8d0be 100644
--- a/hw/xwin/winclipboardthread.c
+++ b/hw/xwin/winclipboardthread.c
@@ -119,7 +119,7 @@ winClipboardProc (void *pvNotUsed)
    if (XInitThreads () == 0)
      {
        ErrorF ("winClipboardProc - XInitThreads failed.\n");
-      pthread_exit (NULL);
+      goto winClipboardProc_Done;
      }

    /* See if X supports the current locale */
@@ -143,7 +143,7 @@ winClipboardProc (void *pvNotUsed)
        /* setjmp returned an unknown value, exit */
        ErrorF ("winClipboardProc - setjmp returned: %d exiting\n",
               iReturn);
-      pthread_exit (NULL);
+      goto winClipboardProc_Done;
      }
    else if (iReturn == WIN_JMP_ERROR_IO)
      {

These two failure modes are unlikely to get better when we restart the thread, 
so I've tweaked these so they will be handled as a critical problem, causing 
the X server to exit.

+  /* global clipboard variable reset */
+  g_fClipboardLaunched = FALSE;
+  g_fClipboardStarted = FALSE;
+  g_iClipboardWindow = None;
+  g_hwndClipboard = NULL;
+  g_fUnicodeClipboard = FALSE;
+  g_pClipboardDisplay = NULL;

Resetting g_fUnicodeClipboard seems unlikely to be right, as that will always 
turn off unicode clipboard handling for all but the first invocation of the 
thread.

diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c
index 2d1ecf9..437f0fa 100644
--- a/hw/xwin/winclipboardthread.c
+++ b/hw/xwin/winclipboardthread.c
@@ -503,6 +503,16 @@ winClipboardErrorHandler (Display *pDisplay, XErrorEvent 
*pErr)
           pErr->serial,
           pErr->request_code,
           pErr->minor_code);
+  if (pthread_equal(pthread_self(),g_winClipboardProcThread) && 
(pErr->request_code == 24))
+    {
+      /* We are in the clipboard thread and a bad window is detected.
+       * This means the Xwindow part of the clipboard doesn't exist anymore
+       * The call to "pthread_exit(NULL)" will restart the thread
+       */
+       ErrorF("winClipboardErrorHandler - Badwindow detected, restarting 
clipboard thread\n");
+       pthread_exit(NULL);
+    }
+
    return 0;
  }

I left this bit out for the moment.  This code doesn't seem to do what it says 
it does.  Checking for a BadWindow would be pErr->error_code == BadWindow (3). 
  I think checking pErr->request_code == 24 is checking the operation is 
X_ConvertSelection (see /usr/include/X11/Xproto.h)

I'm not sure currently works correctly at all in multiwindow mode, as 
XSetErrorHandler() also gets called by the internal WM thread, so this error 
handler may not be the one installed.

Is there a reason why we can't work out which Xlib function is actually 
failing BadWindow and handle it there?

Can you explain a bit more about the case which this helps with.   Are you 
xkill-ing the clipboard X window?

On another topic, I am still a bit concerned we have a potential race 
condition with the two uses of winInitClipboard() during a server 
regeneration.  g_fClipboardLaunched is FALSE before it's called, and set 
afterwards, but since these two calls happen in different threads, there's 
nothing I can see preventing the thread getting started twice.

It might be that having the clipboard thread to exit after setting 
g_fClipboardLaunched to FALSE if the server generation has changed creates the 
needed ordering of events (if it doesn't already exist), but it would take 
some staring at the code to be sure...

[1] http://cgit.freedesktop.org/~jturney/xserver/log/?h=snapshot

-- 
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/


      reply	other threads:[~2010-10-31 16:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <AANLkTikJdnM+_7z5qvrdyannbTUifMGodisQniJd6-GW@mail.gmail.com>
2010-08-03  7:55 ` Michel Hummel
2010-08-06 12:55 ` Michel Hummel
2010-08-08 13:14   ` Jon TURNEY
2010-09-18 18:44     ` michel hummel
2010-09-20 13:59       ` Jon TURNEY
2010-09-20 14:49         ` Michel Hummel
2010-09-22  9:03           ` Michel Hummel
2010-09-22 14:30             ` Jon TURNEY
2010-09-22 17:11               ` XWin.exe parms wrapped by startwin.exe Fouts, Christopher
2010-09-23 12:39                 ` Jon TURNEY
2010-09-24  8:15               ` XWin crash after the launch of startkde on a remote Red Hat 5 machine Michel Hummel
2010-09-24 15:04                 ` Michel Hummel
2010-09-28 20:12                 ` Jon TURNEY
2010-09-28 21:28                   ` Jim Reisert AD1C
2010-09-29  8:59                   ` Michel Hummel
2010-09-29 14:05                     ` Michel Hummel
2010-10-31 16:59                       ` Jon TURNEY [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4CCDA052.8090903@dronecode.org.uk \
    --to=jon.turney@dronecode.org.uk \
    --cc=cygwin-xfree@cygwin.com \
    --cc=hummel.michel@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).