Created attachment 57733 [details] [review]
Use correct write FD to select() on.
FlushFD() contains logic to handle the Xclient or Xserver blocking on a write() by changing the global read and write fd_set's so that MainLoop() will select() on the blocking write FD instead of the peer read FD. Unfortunately, the code contains a logic error so that it winds up select()ing for write on the peer FD instead of the blocked FD.
The result is that xscope and the traced Xclient deadlock since the outstanding data is never written. With X.org 7.5.1 on an old 3.2GHz HTT P4 and a SMP kernel, I could trigger this about 50% of the time using xscope to trace an AF_UNIX connection from xterm. Debug output from xscope with the attached patch shows that EWOULDBLOCK is still returned on occasion but is now handled correctly.
Thanks for the patch - pushed to git master for next release: