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)
This commit is contained in:
parent
0a361d0e5f
commit
1f61bbeffd
|
@ -355,7 +355,7 @@ kern_return_t do_start_x11_server(mach_port_t port, string_array_t argv,
|
||||||
return KERN_FAILURE;
|
return KERN_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int startup_trigger(int argc, char **argv, char **envp) {
|
static int startup_trigger(int argc, char **argv, char **envp) {
|
||||||
Display *display;
|
Display *display;
|
||||||
const char *s;
|
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);
|
kr = bootstrap_look_up(bootstrap_port, server_bootstrap_name, &mp);
|
||||||
if (kr != KERN_SUCCESS) {
|
if (kr != KERN_SUCCESS) {
|
||||||
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
|
#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
|
#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
|
#endif
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
@ -452,6 +452,7 @@ static void ensure_path(const char *dir) {
|
||||||
static void setup_env() {
|
static void setup_env() {
|
||||||
char *temp;
|
char *temp;
|
||||||
const char *pds = NULL;
|
const char *pds = NULL;
|
||||||
|
const char *disp = getenv("DISPLAY");
|
||||||
|
|
||||||
/* Pass on our prefs domain to startx and its inheritors (mainly for
|
/* Pass on our prefs domain to startx and its inheritors (mainly for
|
||||||
* quartz-wm and the Xquartz stub's MachIPC)
|
* 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
|
if(s && *s) {
|
||||||
* use the launchd DISPLAY socket.
|
temp = (char *)malloc(sizeof(char) * (strlen(pds) + 3));
|
||||||
*/
|
if(!temp) {
|
||||||
if(pds == NULL || strcmp(pds, "org.x.X11") != 0)
|
fprintf(stderr, "Memory allocation error creating space for socket name test.\n");
|
||||||
unsetenv("DISPLAY");
|
}
|
||||||
|
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 */
|
/* Make sure PATH is right */
|
||||||
ensure_path(X11BINDIR);
|
ensure_path(X11BINDIR);
|
||||||
|
|
|
@ -26,6 +26,10 @@
|
||||||
* prior written authorization.
|
* prior written authorization.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_DIX_CONFIG_H
|
||||||
|
#include <dix-config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <launch.h>
|
#include <launch.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -65,9 +69,9 @@ int launchd_display_fd() {
|
||||||
return ERROR_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) {
|
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;
|
return ERROR_FD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue