XQuartz: Make the DarwinProcessFDAdditionQueue_thread wait 3 seconds to allow xinitrc to catch up

Previously, we weren't always waiting the full three seconds.  This should
be better, but is still sub-optimal.  We really want to start processing
these once a WM has been started.

http://xquartz.macosforge.org/trac/ticket/416

Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
This commit is contained in:
Jeremy Huddleston 2011-04-21 15:11:52 -07:00
parent b3d2164a03
commit 7524dbd061
2 changed files with 23 additions and 16 deletions

View File

@ -61,6 +61,7 @@ in this Software without prior written authorization from The Open Group.
#include <unistd.h>
#include <pthread.h>
#include <errno.h>
#include <time.h>
#include <IOKit/hidsystem/IOLLEvent.h>
@ -305,6 +306,27 @@ void DarwinListenOnOpenFD(int fd) {
}
static void DarwinProcessFDAdditionQueue_thread(void *args) {
/* TODO: Possibly adjust this to no longer be a race... maybe trigger this
* once a client connects and claims to be the WM.
*
* From ajax:
* There's already an internal callback chain for setting selection [in 1.5]
* ownership. See the CallSelectionCallback at the bottom of
* ProcSetSelectionOwner, and xfixes/select.c for an example of how to hook
* into it.
*/
struct timespec sleep_for;
struct timespec sleep_remaining;
sleep_for.tv_sec = 3;
sleep_for.tv_nsec = 0;
ErrorF("X11.app: DarwinProcessFDAdditionQueue_thread: Sleeping to allow xinitrc to catchup.\n");
while(nanosleep(&sleep_for, &sleep_remaining) != 0) {
sleep_for = sleep_remaining;
}
pthread_mutex_lock(&fd_add_lock);
while(true) {
while(fd_add_count) {

View File

@ -47,7 +47,6 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/time.h>
#include <fcntl.h>
#include <mach/mach.h>
@ -204,7 +203,6 @@ static void socket_handoff_thread(void *arg) {
socket_handoff_t *handoff_data = (socket_handoff_t *)arg;
int launchd_fd = -1;
int connected_fd;
unsigned remain;
/* Now actually get the passed file descriptor from this connection
* If we encounter an error, keep listening.
@ -227,20 +225,7 @@ static void socket_handoff_thread(void *arg) {
close(handoff_data->fd);
unlink(handoff_data->filename);
free(handoff_data);
/* TODO: Clean up this race better... giving xinitrc time to run... need to wait for 1.5 branch:
*
* From ajax:
* There's already an internal callback chain for setting selection [in 1.5]
* ownership. See the CallSelectionCallback at the bottom of
* ProcSetSelectionOwner, and xfixes/select.c for an example of how to hook
* into it.
*/
remain = 3000000;
fprintf(stderr, "X11.app: Received new $DISPLAY fd: %d ... sleeping to allow xinitrc to catchup.\n", launchd_fd);
while((remain = usleep(remain)) > 0);
fprintf(stderr, "X11.app Handing off fd to server thread via DarwinListenOnOpenFD(%d)\n", launchd_fd);
DarwinListenOnOpenFD(launchd_fd);
}