xserver: Branch 'master' - 5 commits

Jeremy Huddleston jeremyhu at kemper.freedesktop.org
Fri May 23 02:33:07 PDT 2008


 configure.ac                          |   16 -------
 hw/xquartz/X11Application.m           |   11 -----
 hw/xquartz/mach-startup/bundle-main.c |   69 ++++++++++++++++++++--------------
 hw/xquartz/mach-startup/stub.c        |   15 +++----
 include/dix-config.h.in               |    3 -
 os/connection.c                       |   14 +++---
 6 files changed, 57 insertions(+), 71 deletions(-)

New commits:
commit 7082929ef7db20b507dce5a8cec043e787d0b55e
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Fri May 23 02:27:58 2008 -0700

    XQuartz: A 2 second delay for launchd socket connections should be sufficient.
    (cherry picked from commit 2bb4251b3c6b30dbf1a556e1b51e6f03f02d2529)

diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 73c0483..0068e02 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -437,8 +437,10 @@ int main(int argc, char **argv, char **envp) {
 }
 #else
 void *add_launchd_display_thread(void *data) {
-    /* TODO: Really fix this race */
-    sleep(5);
+    /* TODO: Really fix this race... we want xinitrc to finish before connections
+     *       are accepted on the launchd socket.
+     */
+    sleep(2);
     
     /* Start listening on the launchd fd */
     int launchd_fd = launchd_display_fd();
commit 5a388b27a094c71b4214aa744b2ba0fdda7fd607
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Fri May 23 02:10:14 2008 -0700

    XQuartz: Add the launchd fd to AllSockets as well
    (cherry picked from commit 83f72529394be5871671d73b6ef4f8bc83708f8a)

diff --git a/os/connection.c b/os/connection.c
index 316e347..38521e6 100644
--- a/os/connection.c
+++ b/os/connection.c
@@ -1324,15 +1324,17 @@ _X_EXPORT void ListenOnOpenFD(int fd) {
     ListenTransFds[ListenTransCount] = fd;
 
     FD_SET(fd, &WellKnownConnections);
+    FD_SET(fd, &AllSockets);
     
-    /* It is always local
-    if (!_XSERVTransIsLocal(ciptr)) {
-    //    DefineSelf (fd);
-    }
-    */
-
     /* Increment the count */
     ListenTransCount++;
+
+    /* This *might* be needed, but it seems to be working fine without it... */
+    //ResetAuthorization();
+    //ResetHosts(display);
+#ifdef XDMCP
+    //XdmcpReset();
+#endif
 }
 
 #endif
commit 77b688a73025238ed9fe286a2bae8f78da65fce3
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Fri May 23 02:32:28 2008 -0700

    XQuartz: Don't need launchd checking in configure.ac anymore since its functionality has been removed from libxtrans and into the mach startup code.
    (cherry picked from commit 1e1f4fb717d2f3a3227be2a034d28d6a4f29b5d1)

diff --git a/configure.ac b/configure.ac
index 3cec454..21a7cb7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -493,7 +493,6 @@ AC_ARG_WITH(apple-applications-dir,AS_HELP_STRING([--with-apple-applications-dir
 				[ APPLE_APPLICATIONS_DIR="${withval}" ],
 				[ APPLE_APPLICATIONS_DIR="/Applications/Utilities" ])
 AC_SUBST([APPLE_APPLICATIONS_DIR])
-AC_ARG_WITH(launchd,          AS_HELP_STRING([--with-launchd], [Build with support for Apple's launchd (default: auto)]), [LAUNCHD=$withval], [LAUNCHD=auto])
 AC_ARG_WITH(launchagents-dir,AS_HELP_STRING([--with-launchagents-dir=PATH], [Path to launchd's LaunchAgents directory (default: /Library/LaunchAgents)]),
 				[ launchagentsdir="${withval}" ],
 				[ launchagentsdir="/Library/LaunchAgents" ])
@@ -1686,21 +1685,6 @@ AM_CONDITIONAL(HAVE_XPLUGIN, [test "x$ac_cv_lib_Xplugin_xp_init" = xyes])
 AM_CONDITIONAL(HAVE_AGL_FRAMEWORK, [test "x$xorg_cv_AGL_framework" = xyes])
 AM_CONDITIONAL(XQUARTZ, [test "x$XQUARTZ" = xyes])
 
-if test "x$LAUNCHD" = "xauto"; then
-	if test "x$XQUARTZ" = "xyes" ; then
-		LAUNCHD=yes
-	else
-		unset LAUNCHD
-		AC_CHECK_PROG(LAUNCHD, [launchd], [yes], [no])
-	fi
-fi
-
-if test "x$LAUNCHD" = "xyes" ; then
-	AC_DEFINE(HAVE_LAUNCHD, 1, [launchd support available])
-fi
-AM_CONDITIONAL(LAUNCHD, [test "x$LAUNCHD" = "xyes"])
-
-
 dnl DMX DDX
 
 AC_MSG_CHECKING([whether to build Xdmx DDX])
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 914ce49..6b9b896 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -148,9 +148,6 @@
 /* Define to 1 if you have version 2.2 (or newer) of the drm library */
 #undef HAVE_LIBDRM_2_2
 
-/* Define to 1 if launchd is available. */
-#undef HAVE_LAUNCHD
-
 /* Have Quartz */
 #undef XQUARTZ
 
commit 225dddbaeded4d64fcc104da538449e5c4dedd2d
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Fri May 23 01:39:02 2008 -0700

    XQuartz: Move the launchd display grabbing into mach_startup
    (cherry picked from commit c3866c98d23020d2151977ee1177b6054d05832e)

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index d687c1f..c6c9c59 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -45,9 +45,6 @@
 #include "X11/extensions/applewm.h"
 #include "micmap.h"
 
-#include "os.h"
-#include "mach-startup/launchd_fd.h"
-
 #include <mach/mach.h>
 #include <unistd.h>
 
@@ -815,14 +812,6 @@ void X11ApplicationMain (int argc, char **argv, char **envp) {
     /* Tell the server thread that it can proceed */
     QuartzInitServer(argc, argv, envp);
     
-#ifndef NEW_LAUNCH_METHOD
-    /* Start listening on the launchd fd */
-    int launchd_fd = launchd_display_fd();
-    if(launchd_fd != -1) {
-        DarwinListenOnOpenFD(launchd_fd);
-    }
-#endif
-
     [NSApp run];
     /* not reached */
 }
diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 0fab990..73c0483 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -47,6 +47,10 @@
 #include "mach_startup.h"
 #include "mach_startupServer.h"
 
+#include "launchd_fd.h"
+void DarwinListenOnOpenFD(int fd);
+
+
 #define DEFAULT_CLIENT "/usr/X11/bin/xterm"
 #define DEFAULT_STARTX "/usr/X11/bin/startx"
 #define DEFAULT_SHELL  "/bin/sh"
@@ -60,8 +64,21 @@ int server_main(int argc, char **argv, char **envp);
 static int execute(const char *command);
 static char *command_from_prefs(const char *key, const char *default_value);
 
-#ifdef NEW_LAUNCH_METHOD
+/*** 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;
+}
 
+#ifdef NEW_LAUNCH_METHOD
 struct arg {
     int argc;
     char **argv;
@@ -106,20 +123,6 @@ static mach_port_t checkin_or_register(char *bname) {
     return mp;
 }
 
-/*** 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;
-}
-
 /*** $DISPLAY handoff ***/
 /* From darwinEvents.c ... but don't want to pull in all the server cruft */
 void DarwinListenOnOpenFD(int fd);
@@ -289,6 +292,8 @@ kern_return_t do_start_x11_server(mach_port_t port, string_array_t argv,
 
 int startup_trigger(int argc, char **argv, char **envp) {
 #else
+void *add_launchd_display_thread(void *data);
+    
 int main(int argc, char **argv, char **envp) {
 #endif
     Display *display;
@@ -345,6 +350,7 @@ int main(int argc, char **argv, char **envp) {
         }
         exit(EXIT_SUCCESS);
 #else
+        create_thread(add_launchd_display_thread, NULL);
         return server_main(argc, argv, envp);
 #endif
     }
@@ -356,14 +362,9 @@ int main(int argc, char **argv, char **envp) {
         /* Now, try to open a display, if so, run the launcher */
         display = XOpenDisplay(NULL);
         if(display) {
-            fprintf(stderr, "X11.app: Closing the display and sleeping for 2s to allow the X server to start up.\n");
             /* Could open the display, start the launcher */
             XCloseDisplay(display);
             
-            /* Give 2 seconds for the server to start... 
-             * TODO: *Really* fix this race condition
-             */
-            usleep(2000);
             return execute(command_from_prefs("app_to_run", DEFAULT_CLIENT));
         }
     }
@@ -434,6 +435,18 @@ int main(int argc, char **argv, char **envp) {
     
     return EXIT_SUCCESS;
 }
+#else
+void *add_launchd_display_thread(void *data) {
+    /* TODO: Really fix this race */
+    sleep(5);
+    
+    /* Start listening on the launchd fd */
+    int launchd_fd = launchd_display_fd();
+    if(launchd_fd != -1) {
+        DarwinListenOnOpenFD(launchd_fd);
+    }
+    return NULL;
+}
 #endif
     
 static int execute(const char *command) {
commit 3a22190061c7ebefee85564b0def5e1112c07ae8
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Mon May 19 03:13:09 2008 -0700

    XQuartz: Fixed a few issues with fd passing... still not working =(
    (cherry picked from commit 7dd351271522b475d8017e4bd1618f12817ee2fa)

diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index c975123..0fab990 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -163,10 +163,11 @@ static void accept_fd_handoff(int connected_fd) {
     
     launchd_fd = *((int*)CMSG_DATA(cmsg));
     
-    if(launchd_fd > 0)
-        DarwinListenOnOpenFD(launchd_fd);
-    else
+    if(launchd_fd == -1)
         fprintf(stderr, "Error receiving $DISPLAY file descriptor, no descriptor received? %d\n", launchd_fd);
+        
+    fprintf(stderr, "Received new DISPLAY fd: %d\n", launchd_fd);
+    DarwinListenOnOpenFD(launchd_fd);
 }
 
 typedef struct {
@@ -227,9 +228,6 @@ static void socket_handoff_thread(void *arg) {
     
     connected_fd = accept(handoff_fd, NULL, NULL);
     
-    /* We delete this temporary socket after we get the connection */
-    unlink(filename);
-
     if(connected_fd == -1) {
         fprintf(stderr, "Failed to accept incoming connection on socket: %s - %s\n", filename, strerror(errno));
         return;
@@ -237,8 +235,10 @@ static void socket_handoff_thread(void *arg) {
 
     /* Now actually get the passed file descriptor from this connection */
     accept_fd_handoff(connected_fd);
-    
+
+    close(connected_fd);
     close(handoff_fd);
+    unlink(filename);
 }
 
 kern_return_t do_prep_fd_handoff(mach_port_t port, string_t socket_filename) {
diff --git a/hw/xquartz/mach-startup/stub.c b/hw/xquartz/mach-startup/stub.c
index 0a9ab66..854b71c 100644
--- a/hw/xquartz/mach-startup/stub.c
+++ b/hw/xquartz/mach-startup/stub.c
@@ -113,7 +113,7 @@ static void set_x11_path() {
     }
 }
 
-static void send_fd_handoff(int connected_fd, int launchd_fd) {
+static void send_fd_handoff(int handoff_fd, int launchd_fd) {
     char databuf[] = "display";
     struct iovec iov[1];
     
@@ -143,19 +143,19 @@ static void send_fd_handoff(int connected_fd, int launchd_fd) {
     
     *((int*)CMSG_DATA(cmsg)) = launchd_fd;
     
-    if (sendmsg(connected_fd, &msg, 0) < 0) {
+    if (sendmsg(handoff_fd, &msg, 0) < 0) {
         fprintf(stderr, "Error sending $DISPLAY file descriptor: %s\n", strerror(errno));
         return;
     }
 
-    fprintf(stderr, "send %d %d %d %s\n", connected_fd, launchd_fd, errno, strerror(errno));
+    fprintf(stderr, "send %d %d %d %s\n", handoff_fd, launchd_fd, errno, strerror(errno));
 }
 
 static void handoff_fd(const char *filename, int launchd_fd) {
     struct sockaddr_un servaddr_un;
     struct sockaddr *servaddr;
     socklen_t servaddr_len;
-    int handoff_fd, connected_fd;
+    int handoff_fd;
 
     /* Setup servaddr_un */
     memset (&servaddr_un, 0, sizeof (struct sockaddr_un));
@@ -171,15 +171,14 @@ static void handoff_fd(const char *filename, int launchd_fd) {
         return;
     }
 
-    connected_fd = connect(handoff_fd, servaddr, servaddr_len);
-
-    if(connected_fd == -1) {
+    if(connect(handoff_fd, servaddr, servaddr_len) < 0) {
         fprintf(stderr, "Failed to establish connection on socket: %s - %s\n", filename, strerror(errno));
         return;
     }
 
-    send_fd_handoff(connected_fd, launchd_fd);
+    fprintf(stderr, "Socket: %s\n", filename);
 
+    send_fd_handoff(handoff_fd, launchd_fd);
     close(handoff_fd);
 }
 


More information about the xorg-commit mailing list