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

Jeremy Huddleston jeremyhu at kemper.freedesktop.org
Fri Sep 4 00:43:13 PDT 2009


 configure.ac                          |    9 +++--
 hw/xquartz/bundle/Info.plist.cpp      |    4 +-
 hw/xquartz/bundle/Makefile.am         |    2 -
 hw/xquartz/mach-startup/Makefile.am   |    4 +-
 hw/xquartz/mach-startup/bundle-main.c |   52 +++++++++++++++++++++++++++-------
 hw/xquartz/mach-startup/launchd_fd.c  |    8 +++--
 hw/xquartz/mach-startup/stub.c        |   10 +-----
 include/dix-config.h.in               |    3 +
 8 files changed, 65 insertions(+), 27 deletions(-)

New commits:
commit c06834cdff76f630e4c20d5e0b28e5c98e526a01
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Fri Sep 4 00:38:58 2009 -0700

    XQuartz: Check the DISPLAY environment variable to see if the socket at startup is ours.  If not, ignore it and fork/exec startx.
    (cherry picked from commit 3d5e10cce360a04bf917227615fb9b825675124f)

diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 583d67e..be5d24b 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -355,7 +355,7 @@ kern_return_t do_start_x11_server(mach_port_t port, string_array_t argv,
         return KERN_FAILURE;
 }
 
-int startup_trigger(int argc, char **argv, char **envp) {
+static int startup_trigger(int argc, char **argv, char **envp) {
     Display *display;
     const char *s;
     
@@ -392,9 +392,9 @@ int startup_trigger(int argc, char **argv, char **envp) {
         kr = bootstrap_look_up(bootstrap_port, server_bootstrap_name, &mp);
         if (kr != KERN_SUCCESS) {
 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
-            fprintf(stderr, "bootstrap_look_up(): %s\n", bootstrap_strerror(kr));
+            fprintf(stderr, "bootstrap_look_up(%s): %s\n", server_bootstrap_name, bootstrap_strerror(kr));
 #else
-            fprintf(stderr, "bootstrap_look_up(): %ul\n", (unsigned long)kr);
+            fprintf(stderr, "bootstrap_look_up(%s): %ul\n", server_bootstrap_name, (unsigned long)kr);
 #endif
             exit(EXIT_FAILURE);
         }
@@ -452,6 +452,7 @@ static void ensure_path(const char *dir) {
 static void setup_env() {
     char *temp;
     const char *pds = NULL;
+    const char *disp = getenv("DISPLAY");
 
     /* Pass on our prefs domain to startx and its inheritors (mainly for
      * quartz-wm and the Xquartz stub's MachIPC)
@@ -468,12 +469,39 @@ static void setup_env() {
             }
         }
     }
+    /* We need to unset DISPLAY if it is not our socket */
+    if(disp) {
+        if(!pds) {
+            /* If we can't detet our id, we are beyond hope and need to just
+             * revert to the non-launchd startup */
+            unsetenv("DISPLAY");
+        } else {
+            /* s = basename(disp) */
+            const char *d, *s;
+	    for(s = NULL, d = disp; *d; d++) {
+                if(*d == '/')
+                     s = d + 1;
+            }
 
-    /* If we're not org.x.X11, we want to unset DISPLAY, so we don't
-     * use the launchd DISPLAY socket.
-     */
-    if(pds == NULL || strcmp(pds, "org.x.X11") != 0)
-        unsetenv("DISPLAY");
+            if(s && *s) {
+                temp = (char *)malloc(sizeof(char) * (strlen(pds) + 3));
+                if(!temp) {
+                    fprintf(stderr, "Memory allocation error creating space for socket name test.\n");
+                }
+                strcpy(temp, pds);
+                strcat(temp, ":0");
+
+                if(strcpy(temp, s) != 0) {
+                    /* If we don't have a match, unset it. */
+                    unsetenv("DISPLAY");
+                }
+                free(temp);
+            } else {
+                /* The DISPLAY environment variable is not formatted like a launchd socket, so reset. */
+                unsetenv("DISPLAY");
+            }
+        }
+    }
 
     /* Make sure PATH is right */
     ensure_path(X11BINDIR);
diff --git a/hw/xquartz/mach-startup/launchd_fd.c b/hw/xquartz/mach-startup/launchd_fd.c
index 44a243a..51017d6 100644
--- a/hw/xquartz/mach-startup/launchd_fd.c
+++ b/hw/xquartz/mach-startup/launchd_fd.c
@@ -26,6 +26,10 @@
  * prior written authorization.
  */
 
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
 #include <launch.h>
 #include <stdio.h>
 #include <errno.h>
@@ -65,9 +69,9 @@ int launchd_display_fd() {
         return ERROR_FD;
     }
     
-    listening_fd_array = launch_data_dict_lookup(sockets_dict, ":0");
+    listening_fd_array = launch_data_dict_lookup(sockets_dict, LAUNCHD_ID_PREFIX":0");
     if (NULL == listening_fd_array) {
-        fprintf(stderr,"launchd check-in: No known sockets found to answer requests on!\n");
+        fprintf(stderr,"launchd check-in: No known sockets found to answer requests on!  %s failed.\n", LAUNCHD_ID_PREFIX".startx:0");
         return ERROR_FD;
     }
     
commit 2f0c992103c863809505fc585098d307d6453519
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Thu Sep 3 19:40:11 2009 -0700

    XQuartz: Use --with-launchd-id-prefix for consistency with xinit
    
    Also actually honor LAUNCHD_ID_PREFIX and APPLE_APPLICATION_NAME
    (cherry picked from commit 990038ab006b2f5e03dcef385514ba4e4584bd25)

diff --git a/configure.ac b/configure.ac
index 1ab51e9..bd884fe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -477,10 +477,11 @@ AC_ARG_WITH(apple-application-name,AS_HELP_STRING([--with-apple-application-name
 				[ APPLE_APPLICATION_NAME="${withval}" ],
 				[ APPLE_APPLICATION_NAME="X11" ])
 AC_SUBST([APPLE_APPLICATION_NAME])
-AC_ARG_WITH(apple-application-id,AS_HELP_STRING([--with-apple-application-id=VALUE], [CFBundleIdentification for the .app (default: org.x.X11)]),
-				[ APPLE_APPLICATION_ID="${withval}" ],
-				[ APPLE_APPLICATION_ID="org.x.X11" ])
-AC_SUBST([APPLE_APPLICATION_ID])
+AC_ARG_WITH(launchd-id-prefix,  AS_HELP_STRING([--with-launchd-id-prefix=PATH], [Prefix to use for launchd identifiers (default: org.x)]),
+                                [ LAUNCHD_ID_PREFIX="${withval}" ],
+                                [ LAUNCHD_ID_PREFIX="org.x" ])
+AC_SUBST([LAUNCHD_ID_PREFIX])
+AC_DEFINE_UNQUOTED(LAUNCHD_ID_PREFIX, "$LAUNCHD_ID_PREFIX", [Prefix to use for launchd identifiers])
 AC_ARG_ENABLE(sparkle,AS_HELP_STRING([--enable-sparkle], [Enable updating of X11.app using the Sparkle Framework (default: disabled)]),
 				[ XQUARTZ_SPARKLE="${enableval}" ],
 				[ XQUARTZ_SPARKLE="no" ])
diff --git a/hw/xquartz/bundle/Info.plist.cpp b/hw/xquartz/bundle/Info.plist.cpp
index 854a560..2e4e737 100644
--- a/hw/xquartz/bundle/Info.plist.cpp
+++ b/hw/xquartz/bundle/Info.plist.cpp
@@ -7,11 +7,11 @@
 	<key>CFBundleExecutable</key>
 		<string>X11</string>
 	<key>CFBundleGetInfoString</key>
-		<string>APPLE_APPLICATION_NAME</string>
+		<string>LAUNCHD_ID_PREFIX.X11</string>
 	<key>CFBundleIconFile</key>
 		<string>X11.icns</string>
 	<key>CFBundleIdentifier</key>
-		<string>APPLE_APPLICATION_ID</string>
+		<string>LAUNCHD_ID_PREFIX.X11</string>
 	<key>CFBundleInfoDictionaryVersion</key>
 		<string>6.0</string>
 	<key>CFBundleName</key>
diff --git a/hw/xquartz/bundle/Makefile.am b/hw/xquartz/bundle/Makefile.am
index ea02cd6..f8b96d8 100644
--- a/hw/xquartz/bundle/Makefile.am
+++ b/hw/xquartz/bundle/Makefile.am
@@ -1,7 +1,7 @@
 include cpprules.in
 
 CPP_FILES_FLAGS = \
-	-DAPPLE_APPLICATION_ID="$(APPLE_APPLICATION_ID)" \
+	-DLAUNCHD_ID_PREFIX="$(LAUNCHD_ID_PREFIX)" \
 	-DAPPLE_APPLICATION_NAME="$(APPLE_APPLICATION_NAME)"
 
 if XQUARTZ_SPARKLE
diff --git a/hw/xquartz/mach-startup/Makefile.am b/hw/xquartz/mach-startup/Makefile.am
index 3380d99..50efc8f 100644
--- a/hw/xquartz/mach-startup/Makefile.am
+++ b/hw/xquartz/mach-startup/Makefile.am
@@ -3,7 +3,9 @@ AM_CPPFLAGS = \
 	-DXSERVER_VERSION=\"$(VERSION)\" \
 	-DX11BINDIR=\"$(bindir)\"
 
-x11appdir = $(APPLE_APPLICATIONS_DIR)/X11.app/Contents/MacOS
+AM_CFLAGS = $(XSERVER_CFLAGS) $(DIX_CFLAGS)
+
+x11appdir = $(APPLE_APPLICATIONS_DIR)/$(APPLE_APPLICATION_NAME).app/Contents/MacOS
 x11app_PROGRAMS = X11.bin
 
 dist_X11_bin_SOURCES = \
diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index ef5d757..583d67e 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -31,6 +31,10 @@
 #include <CoreFoundation/CoreFoundation.h>
 #include <AvailabilityMacros.h>
 
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
 #include <X11/Xlib.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -76,7 +80,7 @@ const char *__crashreporter_info__base = "X.Org X Server " XSERVER_VERSION " Bui
 char __crashreporter_info__buf[4096];
 char *__crashreporter_info__ = __crashreporter_info__buf;
 
-static char *server_bootstrap_name = "org.x.X11";
+static char *server_bootstrap_name = LAUNCHD_ID_PREFIX".X11";
 
 #define DEBUG 1
 
@@ -559,7 +563,7 @@ int main(int argc, char **argv, char **envp) {
     fprintf(stderr, "Waiting for startup parameters via Mach IPC.\n");
     kr = mach_msg_server(mach_startup_server, mxmsgsz, mp, 0);
     if (kr != KERN_SUCCESS) {
-        fprintf(stderr, "org.x.X11(mp): %s\n", mach_error_string(kr));
+        fprintf(stderr, "%s.X11(mp): %s\n", LAUNCHD_ID_PREFIX, mach_error_string(kr));
         return EXIT_FAILURE;
     }
     
diff --git a/hw/xquartz/mach-startup/stub.c b/hw/xquartz/mach-startup/stub.c
index 7eb894c..5e436a9 100644
--- a/hw/xquartz/mach-startup/stub.c
+++ b/hw/xquartz/mach-startup/stub.c
@@ -40,15 +40,11 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 
-static char *server_bootstrap_name = "org.x.X11";
-
-/* The launchd startup is only designed for the primary X11.app that is
- * org.x.X11... server_bootstrap_name might be differnet if we were triggered to
- * start by another X11.app.
- */
-#define kX11AppBundleId "org.x.X11"
+#define kX11AppBundleId LAUNCHD_ID_PREFIX".X11"
 #define kX11AppBundlePath "/Contents/MacOS/X11"
 
+static char *server_bootstrap_name = kX11AppBundleId;
+
 #include <mach/mach.h>
 #include <mach/mach_error.h>
 #include <servers/bootstrap.h>
diff --git a/include/dix-config.h.in b/include/dix-config.h.in
index 10df85c..ac6d8b7 100644
--- a/include/dix-config.h.in
+++ b/include/dix-config.h.in
@@ -145,6 +145,9 @@
 /* Support application updating through sparkle. */
 #undef XQUARTZ_SPARKLE
 
+/* Prefix to use for launchd identifiers */
+#undef LAUNCHD_ID_PREFIX
+
 /* Build a standalone xpbproxy */
 #undef STANDALONE_XPBPROXY
 


More information about the xorg-commit mailing list