From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23009 invoked by alias); 18 Sep 2010 18:44:34 -0000 Received: (qmail 23000 invoked by uid 22791); 18 Sep 2010 18:44:33 -0000 X-SWARE-Spam-Status: No, hits=1.5 required=5.0 tests=AWL,BAYES_50,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,TW_HW,TW_TK,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mail-ww0-f45.google.com (HELO mail-ww0-f45.google.com) (74.125.82.45) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 18 Sep 2010 18:44:27 +0000 Received: by wwa36 with SMTP id 36so4308652wwa.2 for ; Sat, 18 Sep 2010 11:44:25 -0700 (PDT) Received: by 10.216.144.22 with SMTP id m22mr2591265wej.0.1284835465457; Sat, 18 Sep 2010 11:44:25 -0700 (PDT) Received: from [192.168.0.10] (mch82-1-88-186-80-172.fbx.proxad.net [88.186.80.172]) by mx.google.com with ESMTPS id w14sm3896672weq.9.2010.09.18.11.44.22 (version=SSLv3 cipher=RC4-MD5); Sat, 18 Sep 2010 11:44:23 -0700 (PDT) Message-ID: <4C950885.5080205@gmail.com> Date: Sat, 18 Sep 2010 18:44:00 -0000 From: michel hummel User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.12) Gecko/20100915 Thunderbird/3.0.8 MIME-Version: 1.0 To: cygwin-xfree@cygwin.com Subject: Re: XWin crash after the launch of startkde on a remote Red Hat 5 machine References: <4C5EADBB.5000009@dronecode.org.uk> In-Reply-To: <4C5EADBB.5000009@dronecode.org.uk> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-IsSubscribed: yes Mailing-List: contact cygwin-xfree-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-xfree-owner@cygwin.com Reply-To: cygwin-xfree@cygwin.com Mail-Followup-To: cygwin-xfree@cygwin.com X-SW-Source: 2010-09/txt/msg00037.txt.bz2 Hi, I have checked the code of the clipboard thread and the race condition you talk about should not be a problem. Before to start a new clipboard thread, the code waits for the end of the first thread (pthread_join) then fixe the variable g_fClipboardLaunched = FALSE; g_fClipboardStarted = FALSE; So the new thread will never be launched before the old one has terminated. I have a proposition of modification to make the clipboard thread more robust. 1/ Adding a cleanup function which will be automaticaly called at the end of the thread. I purpose the use of the macro pthread_cleanup_push() pthread_cleanup_pop() 2/ You said that having a long-lived thread will be a good solution to simplify the code. I have an other proposition which needs less modification and can simplify the code : By using also here the macro pthread_cleanup_push() we can automaticaly restart the thread on every unexpected exit. We just have to delete this restart when the exit is expected (ie. End of the function) With this solution we don't have to take care about the thread being killed by anyone, it will be restarted. 3/ An other thing I saw is that when the Xwindow part of the clipboard is killed by an other application, the thread will still be alive but the clipboard doesn't work anymore. A solution can be : when an winClipboardErrorHandler() is catched, check for this Xwindow window and whenever this window doesn't exist anymore, create a new one. What do you think about my suggestions ? I tested them and they seem to work as expected. For example, I skipped the wrapper of XQueryTree (actualy needed for xdmcp) and the clipboard is now working with xdmcp/gdm, etc. If you don't like something in my propositions, please tell me what and I will try to adapt it. If you are interested in a patch doing this, I will be happy to give it after a quick review and a clean Thks Michel Hummel Le 08/08/2010 15:14, Jon TURNEY a écrit : > On 06/08/2010 13:55, Michel Hummel wrote: > > I didn't saw any response to my patch proposition, did someone tried > it ? > > If I didn't posted it in the good place where should I have to > > Yes, this is abolutely the right place for your patch. > > It looks good and I shall incorporate it in the next X server release. > > > I will be happy to explain the problem if my first mail wasn't clear. > > Nope, the analysis was very clear, thank you. > > I wonder if there also exists a race condition when the clipboard > thread is stopping? i.e. if we try to start a new one just as the old > one is stopping, we think it is still running and fail to do so? > > In general this code could do with a tidy up: I think it would be much > more sensible to have a long-lived thread which tries to reconnect to > the server when ever it gets disconnected, it would avoid all this > complexity and the complexity of trying to avoid being killed by GDM > as well. > >> 2010/8/3 Michel Hummel: >>> Hello, >>> I'm using cygwin on Microsoft Windows XP with XWin version : >>> sh-3.2# XWin.exe -version >>> Welcome to the XWin X Server >>> Vendor: The Cygwin/X Project >>> Release: 1.8.0.0 (10800000) >>> Build Date: 2010-04-02 >>> Contact: >>> >>> I think I have found a bug in the XWin reset procedure which leads to >>> the start of two clipboard thread's and sometime to a crash of the X >>> server. >>> >>> The crash can be produced by lauching startkde on a Red Hat 5 remote >>> machine (The crash should arrive after some minutes of work) >>> but the bug can simply be produced like this : >>> >>> On my installation if I launch Xwin with this options : >>> XWin :0 -ac& >>> then I do >>> xsetroot -solid '#FFFF00' >>> >>> After setting the color, Xwin launches its reset procedure because >>> there is no more client connected ( the server loses the color but it >>> is the normal comportment isn't it ? >>> http://sourceware.org/ml/cygwin-xfree/2002-01/msg00106.html) >>> >>> The problem comes from the clipboard thread. In this example, when the >>> server launches its reset procedure, the clipboard is in state >>> "Launched" but is not in state "Started" (Boolean variable about >>> clipboard status, see file hw/xwin/winclipboardthread.c). >>> >>> This particular status of the ClipboardThread during server reset is >>> normaly managed by two "if" statements : >>> >>> * An "if" in the file hw/xwin/InitOutput.c disables the exit of the >>> clipboard thread in this state >>> Extract of the file hw/xwin/InitOutput.c (with line number) : >>> >>> 169 winClipboardShutdown (void) >>> 170 { >>> 171 /* Close down clipboard resources */ >>> 172 if (g_fClipboard&& g_fClipboardLaunched&& >>> g_fClipboardStarted) >>> 173 { >>> 174 /* Synchronously destroy the clipboard window */ >>> 175 if (g_hwndClipboard != NULL) >>> 176 { >>> 177 SendMessage (g_hwndClipboard, WM_DESTROY, 0, 0); >>> 178 /* NOTE: g_hwndClipboard is set to NULL in >>> winclipboardthread.c */ >>> 179 } >>> 180 else >>> 181 return; >>> 182 >>> 183 /* Wait for the clipboard thread to exit */ >>> 184 pthread_join (g_ptClipboardProc, NULL); >>> 185 >>> 186 g_fClipboardLaunched = FALSE; >>> 187 g_fClipboardStarted = FALSE; >>> 188 >>> 189 winDebug ("winClipboardShutdown - Clipboard thread has >>> exited.\n"); >>> 190 } >>> 191 } >>> >>> * An "if" statement in the file hw/xwin/winclipboardwrappers.c >>> prohibits the launch of clipboard thread if one is already Launched. >>> Extract of the file hw/xwin/winclipboardwrappers.c (with line number) >>> 256 /* If the clipboard client has already been started, abort */ >>> 257 if (g_fClipboardLaunched) >>> 258 { >>> 259 ErrorF ("winProcEstablishConnection - Clipboard client >>> already " >>> 260 "launched, returning.\n"); >>> 261 return iReturn; >>> 262 } >>> >>> >>> The problem is that the Boolean variables g_fClipboardLaunched and >>> g_fClipboardStarted are re-initialized by the server reset procedure >>> (function winInitializeGlobals of the file hw/xwin/winglobals.c) >>> Extract of the file hw/xwin/winglobals.c (with line number) >>> 128 /* >>> 129 * Re-initialize global variables that are invalidated 130 * by a >>> server reset. >>> 131 */ >>> 132 >>> 133 void >>> 134 winInitializeGlobals (void) >>> 135 { >>> 136 g_dwCurrentThreadID = GetCurrentThreadId (); >>> 137 g_hwndKeyboardFocus = NULL; >>> 138 #ifdef XWIN_CLIPBOARD >>> 139 g_fClipboardLaunched = FALSE; >>> 140 g_fClipboardStarted = FALSE; >>> 141 g_iClipboardWindow = None; >>> 142 g_pClipboardDisplay = NULL; >>> 143 g_atomLastOwnedSelection = None; >>> 144 g_hwndClipboard = NULL; >>> 145 #endif >>> 146 } >>> >>> The consequence of this Re-initialization in this particular situation >>> is that the clipboard thread is launched two times and sometimes leads >>> to a crash of the X server. >>> You can see the double launch of the clipboard thread at the end of >>> the attached log file Xwin.0.log ( 2 times the sentence : >>> winClipboardProc - XOpenDisplay () returned and successfully opened >>> the display. ) >>> >>> To fix this bug I purpose to remove the variables g_fClipboardLaunched >>> and g_fClipboardStarted of the "winInitializeGlobals (void)" function, >>> as their re-initializations are handled in in the files : >>> hw/xwin/InitOutput.c. >>> >>> That what is doing the patch Attached to this email. > > -- 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/