summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@freedesktop.org>2009-09-28 17:47:31 -0700
committerJeremy Huddleston <jeremyhu@freedesktop.org>2009-10-01 23:33:18 -0700
commit3808ecc99a8d64cdbe3fb4a3b57c59e7545e362c (patch)
tree4e0f0a0b33857ac85942b9f874bb762561fd5ec9
parent80735dbf560ba156e53cd2a46190b334de281dd6 (diff)
XQuartz: Query the BundleIdentifier from the bundle in X11.bin rather than using the configure option.
This lets X11.bin drop into any .app ... the Info.plist and Xquartz binary need to have it hardcoded still. (cherry picked from commit 9ad16b8e50b13eb6d0cd20386d07aa8d7320f671)
-rw-r--r--hw/xquartz/mach-startup/bundle-main.c77
1 files changed, 45 insertions, 32 deletions
diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 917bbafbe..146ea11d8 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -80,7 +80,8 @@ 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 = LAUNCHD_ID_PREFIX".X11";
+static char *launchd_id_prefix = NULL;
+static char *server_bootstrap_name = NULL;
#define DEBUG 1
@@ -456,6 +457,7 @@ static void setup_env(void) {
char *temp;
const char *pds = NULL;
const char *disp = getenv("DISPLAY");
+ size_t len;
/* Pass on our prefs domain to startx and its inheritors (mainly for
* quartz-wm and the Xquartz stub's MachIPC)
@@ -465,45 +467,56 @@ static void setup_env(void) {
CFStringRef pd = CFBundleGetIdentifier(bundle);
if(pd) {
pds = CFStringGetCStringPtr(pd, 0);
- if(pds) {
- server_bootstrap_name = malloc(sizeof(char) * (strlen(pds) + 1));
- strcpy(server_bootstrap_name, pds);
- setenv("X11_PREFS_DOMAIN", pds, 1);
- }
}
}
+
+ /* fallback to hardcoded value if we can't discover it */
+ if(!pds) {
+ pds = LAUNCHD_ID_PREFIX".X11";
+ }
+
+ server_bootstrap_name = malloc(sizeof(char) * (strlen(pds) + 1));
+ if(!server_bootstrap_name) {
+ fprintf(stderr, "Memory allocation error.\n");
+ exit(1);
+ }
+ strcpy(server_bootstrap_name, pds);
+ setenv("X11_PREFS_DOMAIN", server_bootstrap_name, 1);
+
+ len = strlen(server_bootstrap_name);
+ launchd_id_prefix = malloc(sizeof(char) * (len - 3));
+ if(!launchd_id_prefix) {
+ fprintf(stderr, "Memory allocation error.\n");
+ exit(1);
+ }
+ strlcpy(launchd_id_prefix, server_bootstrap_name, len - 3);
+
/* 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;
+ /* s = basename(disp) */
+ const char *d, *s;
for(s = NULL, d = disp; *d; d++) {
- if(*d == '/')
- s = d + 1;
- }
-
- if(s && *s) {
- size_t pds_len = strlen(pds);
- temp = (char *)malloc(sizeof(char) * pds_len);
- if(!temp) {
- fprintf(stderr, "Memory allocation error creating space for socket name test.\n");
- }
- strlcpy(temp, pds, pds_len - 3);
- strlcat(temp, ":0", pds_len);
+ if(*d == '/')
+ s = d + 1;
+ }
- if(strcmp(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. */
+ if(s && *s) {
+ temp = (char *)malloc(sizeof(char) * len);
+ if(!temp) {
+ fprintf(stderr, "Memory allocation error creating space for socket name test.\n");
+ exit(1);
+ }
+ strlcpy(temp, launchd_id_prefix, len);
+ strlcat(temp, ":0", len);
+
+ if(strcmp(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");
}
}