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

Jeremy Huddleston jeremyhu at kemper.freedesktop.org
Mon Jul 7 16:34:55 PDT 2008


 hw/xquartz/X11Application.m           |    6 ++
 hw/xquartz/darwinEvents.c             |   49 ++++++++++++-----
 hw/xquartz/darwinEvents.h             |    3 +
 hw/xquartz/mach-startup/bundle-main.c |   96 +++++++++++++---------------------
 hw/xquartz/mach-startup/stub.c        |   33 ++++++++---
 hw/xquartz/quartzKeyboard.c           |   24 ++------
 include/servermd.h                    |    2 
 7 files changed, 115 insertions(+), 98 deletions(-)

New commits:
commit 199d2dcb708c9f9d6b9ede149ea0fe9fba6c007c
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Jul 7 16:34:47 2008 -0700

    XQuartz: More fd handoff cleanup.

diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 9894ae8..06d0db8 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -167,97 +167,63 @@ static void accept_fd_handoff(int connected_fd) {
     DarwinListenOnOpenFD(launchd_fd);
 }
 
-typedef struct {
-    string_t socket_filename;
-    pthread_mutex_t lock;
-    pthread_cond_t cond;
-    kern_return_t retval;
-} handoff_data_t;
-
-/* This thread loops accepting incoming connections and handing off the file
+/* This thread accepts an incoming connection and hands off the file
  * descriptor for the new connection to accept_fd_handoff()
  */
 static void socket_handoff_thread(void *arg) {
-    handoff_data_t *data = (handoff_data_t *)arg;
-    string_t filename;
+    int handoff_fd = *(int *)arg;
+
+    /* Now actually get the passed file descriptor from this connection */
+    accept_fd_handoff(handoff_fd);
+
+    close(handoff_fd);
+}
+
+kern_return_t do_prep_fd_handoff(mach_port_t port, string_t filename) {
     struct sockaddr_un servaddr_un;
     struct sockaddr *servaddr;
     socklen_t servaddr_len;
     int handoff_fd;
 
-    /* We need to save it since data dies after we pthread_cond_broadcast */
-    strlcpy(filename, data->socket_filename, STRING_T_SIZE); 
-    
-    /* Make sure we only run once the dispatch thread is waiting for us */
-    pthread_mutex_lock(&data->lock);
+#ifdef DEBUG
+    fprintf(stderr, "X11.app: Prepping for fd handoff.\n");
+#endif
     
+    /* Initialize our data */
+
     /* Setup servaddr_un */
     memset (&servaddr_un, 0, sizeof (struct sockaddr_un));
     servaddr_un.sun_family  = AF_UNIX;
     strlcpy(servaddr_un.sun_path, filename, sizeof(servaddr_un.sun_path));
-
+    
     servaddr = (struct sockaddr *) &servaddr_un;
     servaddr_len = sizeof(struct sockaddr_un) - sizeof(servaddr_un.sun_path) + strlen(filename);
-    
+
+    /* Get a fd for the handoff */
     handoff_fd = socket(AF_UNIX, SOCK_STREAM, 0);
     if(handoff_fd == -1) {
         fprintf(stderr, "X11.app: Failed to create socket: %d - %s\n", errno, strerror(errno));
-
-        data->retval = EXIT_FAILURE;
-        pthread_cond_broadcast(&data->cond);
-        pthread_mutex_unlock(&data->lock);
-        return;
+        return KERN_FAILURE;
     }
+#ifdef DEBUG
+    fprintf(stderr, "X11.app: socket created for fd handoff: fd=%d\n", handoff_fd);
+#endif
 
-    /* Let the dispatch thread now tell the caller that we're ready */
-    data->retval = EXIT_SUCCESS;
-    pthread_cond_broadcast(&data->cond);
-    pthread_mutex_unlock(&data->lock);
-    
     if(connect(handoff_fd, servaddr, servaddr_len) < 0) {
         fprintf(stderr, "X11.app: Failed to connect to socket: %s - %d - %s\n", filename, errno, strerror(errno));
-        return;
+        return KERN_FAILURE;
     }
-
-    /* Now actually get the passed file descriptor from this connection */
-    accept_fd_handoff(handoff_fd);
-
-    close(handoff_fd);
-}
-
-kern_return_t do_prep_fd_handoff(mach_port_t port, string_t socket_filename) {
-    handoff_data_t handoff_data;
-
 #ifdef DEBUG
-    fprintf(stderr, "X11.app: Prepping for fd handoff.\n");
-#endif
-    
-    /* Initialize our data */
-    pthread_mutex_init(&handoff_data.lock, NULL);
-    pthread_cond_init(&handoff_data.cond, NULL);
-    strlcpy(handoff_data.socket_filename, socket_filename, STRING_T_SIZE); 
-
-    pthread_mutex_lock(&handoff_data.lock);
-    
-    create_thread(socket_handoff_thread, &handoff_data);
-
-#ifdef DEBUG
-    fprintf(stderr, "X11.app: Thread created for handoff.  Waiting on return value.\n");
+    fprintf(stderr, "X11.app: Connection established for fd handoff: fd=%d\n", handoff_fd);
 #endif
     
-    /* Wait for our return value */
-    pthread_cond_wait(&handoff_data.cond, &handoff_data.lock);
-    pthread_mutex_unlock(&handoff_data.lock);
-
-    /* Cleanup */
-    pthread_cond_destroy(&handoff_data.cond);
-    pthread_mutex_destroy(&handoff_data.lock);
-
+    create_thread(socket_handoff_thread, &handoff_fd);
+   
 #ifdef DEBUG
-    fprintf(stderr, "X11.app: Sending return value: %d\n", handoff_data.retval);
+    fprintf(stderr, "X11.app: Thread created for handoff.  Returning success to tell sender to push the fd.\n");
 #endif
     
-    return handoff_data.retval;
+    return KERN_SUCCESS;
 }
 
 /*** Server Startup ***/
@@ -427,7 +393,7 @@ static int execute(const char *command) {
     
     fprintf(stderr, "X11.app: Launching %s:\n", command);
     for(s=newargv; *s; s++) {
-        fprintf(stderr, "\targv[%d] = %s\n", s - newargv, *s);
+        fprintf(stderr, "\targv[%ld] = %s\n", s - newargv, *s);
     }
 
     execvp (newargv[0], (char * const *) newargv);
commit 9c20a4804d97e67a988f00f49866997209cce518
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon Jul 7 10:55:58 2008 -0700

    XQuartz: Some fd handoff cleanup.

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index f9222fe..552683e 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -201,6 +201,12 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
 	for_appkit = YES;
 	for_x = YES;
   
+//    fprintf(stderr, "fd_add_count: %d\n", fd_add_count);
+    if(fd_add_count) {
+        DarwinProcessFDAdditionQueue();
+        fprintf(stderr, "ran it - fd_add_count: %d\n", fd_add_count);
+    }
+    
 	switch (type) {
 		case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown:
 		case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp:
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 911aac7..900ee43 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -79,6 +79,11 @@ void QuartzModeEQInit(void);
 
 static int old_flags = 0;  // last known modifier state
 
+#define FD_ADD_MAX 128
+static int fd_add[FD_ADD_MAX];
+int fd_add_count = 0;
+static pthread_mutex_t fd_add_lock = PTHREAD_MUTEX_INITIALIZER;
+
 static xEvent *darwinEvents = NULL;
 
 static pthread_mutex_t mieq_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -232,15 +237,6 @@ static void DarwinSimulateMouseClick(
     DarwinUpdateModifiers(KeyPress, modifierMask);
 }
 
-static void kXquartzListenOnOpenFDHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, int nevents) {
-    size_t i;
-    TA_SERVER();
-
-    for (i=0; i<nevents; i++) {
-        ListenOnOpenFD(xe[i].u.clientMessage.u.l.longs0);
-    }
-}
-
 /* Generic handler for Xquartz-specifc events.  When possible, these should
    be moved into their own individual functions and set as handlers using
    mieqSetHandler. */
@@ -249,7 +245,7 @@ static void DarwinEventHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, in
     int i;
     
     TA_SERVER();
-    
+
     DEBUG_LOG("DarwinEventHandler(%d, %p, %p, %d)\n", screenNum, xe, dev, nevents);
     for (i=0; i<nevents; i++) {
         switch(xe[i].u.u.type) {
@@ -331,6 +327,35 @@ static void DarwinEventHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, in
     }
 }
 
+void DarwinListenOnOpenFD(int fd) {
+    ErrorF("DarwinListenOnOpenFD: %d\n", fd);
+    
+    pthread_mutex_lock(&fd_add_lock);
+    if(fd_add_count < FD_ADD_MAX)
+        fd_add[fd_add_count++] = fd;
+    else
+        ErrorF("FD Addition buffer at max.  Dropping fd addition request.\n");
+
+    pthread_mutex_unlock(&fd_add_lock);
+}
+
+void DarwinProcessFDAdditionQueue() {
+    pthread_mutex_lock(&fd_add_lock);
+    while(fd_add_count) {
+        DarwinSendDDXEvent(kXquartzListenOnOpenFD, 1, fd_add[--fd_add_count]);
+    }
+    pthread_mutex_unlock(&fd_add_lock);
+}
+
+static void kXquartzListenOnOpenFDHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, int nevents) {
+    size_t i;
+    TA_SERVER();
+    
+    for (i=0; i<nevents; i++) {
+        ListenOnOpenFD(xe[i].u.clientMessage.u.l.longs0);
+    }
+}
+
 Bool DarwinEQInit(void) { 
     mieqInit();
     mieqSetHandler(kXquartzReloadKeymap, DarwinKeyboardReloadHandler);
@@ -576,10 +601,6 @@ void DarwinUpdateModKeys(int flags) {
 	old_flags = flags;
 }
 
-void DarwinListenOnOpenFD(int fd) {
-    DarwinSendDDXEvent(kXquartzListenOnOpenFD, 1, fd);
-}
-
 /*
  * DarwinSendDDXEvent
  *  Send the X server thread a message by placing it on the event queue.
diff --git a/hw/xquartz/darwinEvents.h b/hw/xquartz/darwinEvents.h
index 7a1e8ca..747dccb 100644
--- a/hw/xquartz/darwinEvents.h
+++ b/hw/xquartz/darwinEvents.h
@@ -41,6 +41,9 @@ 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 de92361..9894ae8 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -57,6 +57,8 @@ extern int noPanoramiXExtension;
 #define DEFAULT_STARTX "/usr/X11/bin/startx"
 #define DEFAULT_SHELL  "/bin/sh"
 
+#define DEBUG 1
+
 static int execute(const char *command);
 static char *command_from_prefs(const char *key, const char *default_value);
 
@@ -198,8 +200,8 @@ static void socket_handoff_thread(void *arg) {
     servaddr_len = sizeof(struct sockaddr_un) - sizeof(servaddr_un.sun_path) + strlen(filename);
     
     handoff_fd = socket(AF_UNIX, SOCK_STREAM, 0);
-    if(handoff_fd == 0) {
-        fprintf(stderr, "Failed to create socket: %s - %s\n", filename, strerror(errno));
+    if(handoff_fd == -1) {
+        fprintf(stderr, "X11.app: Failed to create socket: %d - %s\n", errno, strerror(errno));
 
         data->retval = EXIT_FAILURE;
         pthread_cond_broadcast(&data->cond);
@@ -213,7 +215,7 @@ static void socket_handoff_thread(void *arg) {
     pthread_mutex_unlock(&data->lock);
     
     if(connect(handoff_fd, servaddr, servaddr_len) < 0) {
-        fprintf(stderr, "Failed to connect to socket: %s - %s\n", filename, strerror(errno));
+        fprintf(stderr, "X11.app: Failed to connect to socket: %s - %d - %s\n", filename, errno, strerror(errno));
         return;
     }
 
@@ -226,6 +228,10 @@ static void socket_handoff_thread(void *arg) {
 kern_return_t do_prep_fd_handoff(mach_port_t port, string_t socket_filename) {
     handoff_data_t handoff_data;
 
+#ifdef DEBUG
+    fprintf(stderr, "X11.app: Prepping for fd handoff.\n");
+#endif
+    
     /* Initialize our data */
     pthread_mutex_init(&handoff_data.lock, NULL);
     pthread_cond_init(&handoff_data.cond, NULL);
@@ -235,6 +241,10 @@ kern_return_t do_prep_fd_handoff(mach_port_t port, string_t socket_filename) {
     
     create_thread(socket_handoff_thread, &handoff_data);
 
+#ifdef DEBUG
+    fprintf(stderr, "X11.app: Thread created for handoff.  Waiting on return value.\n");
+#endif
+    
     /* Wait for our return value */
     pthread_cond_wait(&handoff_data.cond, &handoff_data.lock);
     pthread_mutex_unlock(&handoff_data.lock);
@@ -242,6 +252,10 @@ kern_return_t do_prep_fd_handoff(mach_port_t port, string_t socket_filename) {
     /* Cleanup */
     pthread_cond_destroy(&handoff_data.cond);
     pthread_mutex_destroy(&handoff_data.lock);
+
+#ifdef DEBUG
+    fprintf(stderr, "X11.app: Sending return value: %d\n", handoff_data.retval);
+#endif
     
     return handoff_data.retval;
 }
diff --git a/hw/xquartz/mach-startup/stub.c b/hw/xquartz/mach-startup/stub.c
index d7b248b..9928aa9 100644
--- a/hw/xquartz/mach-startup/stub.c
+++ b/hw/xquartz/mach-startup/stub.c
@@ -57,6 +57,8 @@
 #define XSERVER_VERSION "?"
 #endif
 
+#define DEBUG 1
+
 static char x11_path[PATH_MAX + 1];
 
 static void set_x11_path() {
@@ -132,23 +134,27 @@ static int create_socket(char *filename_out) {
         servaddr_len = sizeof(struct sockaddr_un) - sizeof(servaddr_un.sun_path) + strlen(filename_out);
         
         ret_fd = socket(PF_UNIX, SOCK_STREAM, 0);
-        if(ret_fd == 0) {
-            fprintf(stderr, "Failed to create socket (try %d / %d): %s - %s\n", (int)try+1, (int)try_max, filename_out, strerror(errno));
+        if(ret_fd == -1) {
+            fprintf(stderr, "Xquartz: Failed to create socket (try %d / %d): %s - %s\n", (int)try+1, (int)try_max, filename_out, strerror(errno));
             continue;
         }
         
         if(bind(ret_fd, servaddr, servaddr_len) != 0) {
-            fprintf(stderr, "Failed to bind socket: %s - %s\n", filename_out, strerror(errno));
+            fprintf(stderr, "Xquartz: Failed to bind socket: %d - %s\n", errno, strerror(errno));
             close(ret_fd);
             return 0;
         }
 
         if(listen(ret_fd, 10) != 0) {
-            fprintf(stderr, "Failed to listen to socket: %s - %s\n", filename_out, strerror(errno));
+            fprintf(stderr, "Xquartz: Failed to listen to socket: %s - %d - %s\n", filename_out, errno, strerror(errno));
             close(ret_fd);
             return 0;
         }
-        
+
+#ifdef DEBUG
+        fprintf(stderr, "Xquartz: Listening on socket for fd handoff:  %s\n", filename_out);
+#endif
+
         return ret_fd;
     }
     
@@ -186,19 +192,30 @@ static void send_fd_handoff(int handoff_fd, int launchd_fd) {
     
     *((int*)CMSG_DATA(cmsg)) = launchd_fd;
     
+#ifdef DEBUG
+    fprintf(stderr, "Xquartz: Waiting for fd handoff connection.\n");
+#endif
     connected_fd = accept(handoff_fd, NULL, NULL);
     if(connected_fd == -1) {
-        fprintf(stderr, "Failed to accept incoming connection on socket: %s\n", strerror(errno));
+        fprintf(stderr, "Xquartz: Failed to accept incoming connection on socket: %s\n", strerror(errno));
         return;
     }
     
+#ifdef DEBUG
+    fprintf(stderr, "Xquartz: Handoff connection established.  Sending message.\n");
+#endif
     if(sendmsg(connected_fd, &msg, 0) < 0) {
-        fprintf(stderr, "Error sending $DISPLAY file descriptor: %s\n", strerror(errno));
+        fprintf(stderr, "Xquartz: Error sending $DISPLAY file descriptor: %s\n", strerror(errno));
         return;
     }
 
+#ifdef DEBUG
+    fprintf(stderr, "Xquartz: Message sent.  Closing.\n");
+#endif
     close(connected_fd);
-    fprintf(stderr, "send %d %d %d %s\n", handoff_fd, launchd_fd, errno, strerror(errno));
+#ifdef DEBUG
+    fprintf(stderr, "Xquartz: end of send debug: %d %d %d %s\n", handoff_fd, launchd_fd, errno, strerror(errno));
+#endif
 }
 
 int main(int argc, char **argv, char **envp) {
commit 69cfc1a21e12bb38a6130dea2e5f20f1e6a3ee7c
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Fri Jul 4 19:23:21 2008 -0700

    XQuartz: Remove deprecated keyboard code.

diff --git a/hw/xquartz/quartzKeyboard.c b/hw/xquartz/quartzKeyboard.c
index 5b8d32d..40d8cbb 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -891,6 +891,7 @@ void DarwinKeyboardInit(DeviceIntPtr pDev) {
 #ifdef XQUARTZ_USE_XKB
 	XkbComponentNamesRec names;
 	bzero(&names, sizeof(names));
+    /* We need to really have rules... or something... */
     XkbSetRulesDflts("base", "pc105", "us", NULL, NULL);
     assert(XkbInitKeyboardDeviceStruct(pDev, &names, &keySyms, keyInfo.modMap,
                                         QuartzBell, DarwinChangeKeyboardControl));
@@ -1088,13 +1089,14 @@ Bool LegalModifier(unsigned int key, DeviceIntPtr pDev)
 
 unsigned int QuartzSystemKeymapSeed(void) {
     static unsigned int seed;
-    static KeyboardLayoutRef last_key_layout;
-    KeyboardLayoutRef key_layout;
+    static TISInputSourceRef last_key_layout;
+    TISInputSourceRef key_layout;
+
+    key_layout = TISCopyCurrentKeyboardLayoutInputSource();
 
-    KLGetCurrentKeyboardLayout (&key_layout);
     if (key_layout != last_key_layout) seed++;
     last_key_layout = key_layout;
-
+    
     return seed;
 }
 
@@ -1136,7 +1138,6 @@ static KeySym make_dead_key(KeySym in) {
 }
 
 Bool QuartzReadSystemKeymap(darwinKeyboardInfo *info) {
-    KeyboardLayoutRef key_layout;
     const void *chr_data = NULL;
     int num_keycodes = NUM_KEYCODES;
     UInt32 keyboard_type = 0;
@@ -1150,18 +1151,7 @@ Bool QuartzReadSystemKeymap(darwinKeyboardInfo *info) {
       CFDataRef currentKeyLayoutDataRef = (CFDataRef )TISGetInputSourceProperty(currentKeyLayoutRef, kTISPropertyUnicodeKeyLayoutData);
       if (currentKeyLayoutDataRef) chr_data = CFDataGetBytePtr(currentKeyLayoutDataRef);
     }
-    
-    if (chr_data == NULL) {
-      KLGetCurrentKeyboardLayout (&key_layout);
-      KLGetKeyboardLayoutProperty (key_layout, kKLuchrData, &chr_data);
-    }
-    
-    if (chr_data == NULL) {
-      KLGetKeyboardLayoutProperty (key_layout, kKLKCHRData, &chr_data);
-      is_uchr = 0;
-      num_keycodes = 128;
-    }
-    
+
     if (chr_data == NULL) {
       ErrorF ( "Couldn't get uchr or kchr resource\n");
       return FALSE;
commit 0733ef2e8abda99cfd62966e73017949e9cd507f
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Wed Jul 2 00:47:08 2008 -0700

    Set machine dependent defaults for ppc64

diff --git a/include/servermd.h b/include/servermd.h
index 74b90b3..4c3f43d 100644
--- a/include/servermd.h
+++ b/include/servermd.h
@@ -165,7 +165,7 @@ SOFTWARE.
 
 #endif /* hpux || __hppa__ */
 
-#if defined(__powerpc__) || defined(__ppc__)
+#if defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__)
 
 #define IMAGE_BYTE_ORDER        MSBFirst
 #define BITMAP_BIT_ORDER        MSBFirst


More information about the xorg-commit mailing list