xserver: Branch 'xorg-server-1.4-apple'

Jeremy Huddleston jeremyhu at kemper.freedesktop.org
Tue Aug 5 15:14:55 PDT 2008


 hw/xquartz/darwinEvents.c             |   33 ++++++++++++++++++++++++++++-----
 hw/xquartz/darwinEvents.h             |    3 ---
 hw/xquartz/mach-startup/bundle-main.c |   10 ++++++----
 hw/xquartz/mach-startup/stub.c        |   12 ++++++------
 4 files changed, 40 insertions(+), 18 deletions(-)

New commits:
commit a8f0d32216e321b8ae6da182be9b1ea792f6e004
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Tue Aug 5 15:14:08 2008 -0700

    XQuartz: Added code and made comments more helpful for debugging first-client-auth bug.

diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index da10e20..9b39baa 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -83,12 +83,28 @@ static int old_flags = 0;  // last known modifier state
 static int fd_add[FD_ADD_MAX];
 int fd_add_count = 0;
 static pthread_mutex_t fd_add_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_cond_t fd_add_ready_cond = PTHREAD_COND_INITIALIZER;
+static pthread_t fd_add_tid = NULL;
 
 static xEvent *darwinEvents = NULL;
 
 static pthread_mutex_t mieq_lock = PTHREAD_MUTEX_INITIALIZER;
 static pthread_cond_t mieq_ready_cond = PTHREAD_COND_INITIALIZER;
 
+/*** Pthread Magics ***/
+static pthread_t create_thread(void *func, void *arg) {
+    pthread_attr_t attr;
+    pthread_t tid;
+
+    pthread_attr_init (&attr);
+    pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
+    pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
+    pthread_create (&tid, &attr, func, arg);
+    pthread_attr_destroy (&attr);
+
+    return tid;
+}
+
 static inline void darwinEvents_lock(void) {
     int err;
     if((err = pthread_mutex_lock(&mieq_lock))) {
@@ -339,18 +355,21 @@ void DarwinListenOnOpenFD(int fd) {
     else
         ErrorF("FD Addition buffer at max.  Dropping fd addition request.\n");
 
+    pthread_cond_broadcast(&fd_add_ready_cond);
     pthread_mutex_unlock(&fd_add_lock);
 #else
     xquartz_launchd_fd = fd;
 #endif
 }
 
-void DarwinProcessFDAdditionQueue() {
+static void DarwinProcessFDAdditionQueue_thread(void *args) {
     pthread_mutex_lock(&fd_add_lock);
-    while(fd_add_count) {
-        DarwinSendDDXEvent(kXquartzListenOnOpenFD, 1, fd_add[--fd_add_count]);
+    while(true) {
+        while(fd_add_count) {
+            DarwinSendDDXEvent(kXquartzListenOnOpenFD, 1, fd_add[--fd_add_count]);
+        }
+        pthread_cond_wait(&fd_add_ready_cond, &fd_add_lock);
     }
-    pthread_mutex_unlock(&fd_add_lock);
 }
 
 static void kXquartzListenOnOpenFDHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, int nevents) {
@@ -358,7 +377,8 @@ static void kXquartzListenOnOpenFDHandler(int screenNum, xEventPtr xe, DeviceInt
     TA_SERVER();
     
     for (i=0; i<nevents; i++) {
-        ListenOnOpenFD(xe[i].u.clientMessage.u.l.longs0);
+        ErrorF("Calling ListenOnOpenFD() for new fd: %d\n", (int)xe[i].u.clientMessage.u.l.longs0);
+        ListenOnOpenFD((int)xe[i].u.clientMessage.u.l.longs0);
     }
 }
 
@@ -396,6 +416,9 @@ Bool DarwinEQInit(void) {
         darwinEvents_unlock();
     }
 
+    if(!fd_add_tid)
+        fd_add_tid = create_thread(DarwinProcessFDAdditionQueue_thread, NULL);
+    
     return TRUE;
 }
 
diff --git a/hw/xquartz/darwinEvents.h b/hw/xquartz/darwinEvents.h
index 747dccb..7a1e8ca 100644
--- a/hw/xquartz/darwinEvents.h
+++ b/hw/xquartz/darwinEvents.h
@@ -41,9 +41,6 @@ void DarwinSendScrollEvents(float count_x, float count_y, int pointer_x, int poi
 void DarwinUpdateModKeys(int flags);
 void DarwinListenOnOpenFD(int fd);
 
-extern int fd_add_count;
-void DarwinProcessFDAdditionQueue(void);
-
 /*
  * Special ddx events understood by the X server
  */
diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 61c2e86..c138fe7 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -155,16 +155,18 @@ static void accept_fd_handoff(int connected_fd) {
     *((int*)CMSG_DATA(cmsg)) = -1;
     
     if(recvmsg(connected_fd, &msg, 0) < 0) {
-        fprintf(stderr, "Error receiving $DISPLAY file descriptor.  recvmsg() error: %s\n", strerror(errno));
+        fprintf(stderr, "X11.app: Error receiving $DISPLAY file descriptor.  recvmsg() error: %s\n", strerror(errno));
         return;
     }
     
     launchd_fd = *((int*)CMSG_DATA(cmsg));
     
     if(launchd_fd == -1)
-        fprintf(stderr, "Error receiving $DISPLAY file descriptor, no descriptor received? %d\n", launchd_fd);
+        fprintf(stderr, "X11.app: Error receiving $DISPLAY file descriptor, no descriptor received? %d\n", launchd_fd);
         
-    fprintf(stderr, "Received new DISPLAY fd: %d\n", launchd_fd);
+//    fprintf(stderr, "X11.app: Received new DISPLAY fd: %d ... sleeping before handoff to server thread\n", launchd_fd);
+//    sleep(5);
+    fprintf(stderr, "X11.app Handing off fd to server thread via DarwinListenOnOpenFD(%d)\n", launchd_fd);
     DarwinListenOnOpenFD(launchd_fd);
 }
 
@@ -221,7 +223,7 @@ kern_return_t do_prep_fd_handoff(mach_port_t port, string_t filename) {
     create_thread(socket_handoff_thread, &handoff_fd);
    
 #ifdef DEBUG
-    fprintf(stderr, "X11.app: Thread created for handoff.  Returning success to tell sender to push the fd.\n");
+    fprintf(stderr, "X11.app: Thread created for handoff.  Returning success to tell caller to accept our connection and push the fd.\n");
 #endif
     
     return KERN_SUCCESS;
diff --git a/hw/xquartz/mach-startup/stub.c b/hw/xquartz/mach-startup/stub.c
index 003c4dd..4288753 100644
--- a/hw/xquartz/mach-startup/stub.c
+++ b/hw/xquartz/mach-startup/stub.c
@@ -261,7 +261,7 @@ int main(int argc, char **argv, char **envp) {
         /* This forking is ugly and will be cleaned up later */
         pid_t child = fork();
         if(child == -1) {
-            fprintf(stderr, "Could not fork: %s\n", strerror(errno));
+            fprintf(stderr, "XQuartz: Could not fork: %s\n", strerror(errno));
             return EXIT_FAILURE;
         }
 
@@ -270,7 +270,7 @@ int main(int argc, char **argv, char **envp) {
             _argv[0] = x11_path;
             _argv[1] = "--listenonly";
             _argv[2] = NULL;
-            fprintf(stderr, "Starting X server: %s --listenonly\n", x11_path);
+            fprintf(stderr, "XQuartz: Starting X server: %s --listenonly\n", x11_path);
             return execvp(x11_path, _argv);
         }
 
@@ -283,7 +283,7 @@ int main(int argc, char **argv, char **envp) {
         }
 
         if(kr != KERN_SUCCESS) {
-            fprintf(stderr, "bootstrap_look_up(): Timed out: %s\n", bootstrap_strerror(kr));
+            fprintf(stderr, "XQuartz: bootstrap_look_up(): Timed out: %s\n", bootstrap_strerror(kr));
             return EXIT_FAILURE;
         }
     }
@@ -300,7 +300,7 @@ int main(int argc, char **argv, char **envp) {
             close(handoff_fd);
             unlink(handoff_socket_filename);
         } else {
-            fprintf(stderr, "Unable to hand of $DISPLAY file descriptor\n");
+            fprintf(stderr, "XQuartz: Unable to hand of $DISPLAY file descriptor\n");
         }
     }
 
@@ -314,7 +314,7 @@ int main(int argc, char **argv, char **envp) {
     newenvp = (string_array_t)alloca(envpc * sizeof(string_t));
     
     if(!newargv || !newenvp) {
-        fprintf(stderr, "Memory allocation failure\n");
+        fprintf(stderr, "XQuartz: Memory allocation failure\n");
         exit(EXIT_FAILURE);
     }
     
@@ -327,7 +327,7 @@ int main(int argc, char **argv, char **envp) {
 
     kr = start_x11_server(mp, newargv, argc, newenvp, envpc);
     if (kr != KERN_SUCCESS) {
-        fprintf(stderr, "start_x11_server: %s\n", mach_error_string(kr));
+        fprintf(stderr, "XQuartz: start_x11_server: %s\n", mach_error_string(kr));
         return EXIT_FAILURE;
     }
     return EXIT_SUCCESS;


More information about the xorg-commit mailing list