XQuartz: stub: Call LSOpenApplication instead of fork()/exec()

Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
This commit is contained in:
John D Pell 2021-07-13 23:46:28 -07:00 committed by Jeremy Huddleston Sequoia
parent f292fbfaac
commit 61d18bed66
Failed to extract signature

View File

@ -52,39 +52,27 @@
#include "launchd_fd.h" #include "launchd_fd.h"
static char x11_path[PATH_MAX + 1]; static CFURLRef x11appURL;
static FSRef x11_appRef;
static pid_t x11app_pid = 0; static pid_t x11app_pid = 0;
aslclient aslc; aslclient aslc;
static void static void
set_x11_path(void) set_x11_path(void)
{ {
CFURLRef appURL = NULL;
OSStatus osstatus = OSStatus osstatus =
LSFindApplicationForInfo(kLSUnknownCreator, CFSTR( LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(
kX11AppBundleId), nil, nil, &appURL); kX11AppBundleId), nil, &x11_appRef, &x11appURL);
switch (osstatus) { switch (osstatus) {
case noErr: case noErr:
if (appURL == NULL) { if (x11appURL == NULL) {
asl_log( asl_log(
aslc, NULL, ASL_LEVEL_ERR, aslc, NULL, ASL_LEVEL_ERR,
"Xquartz: Invalid response from LSFindApplicationForInfo(%s)", "Xquartz: Invalid response from LSFindApplicationForInfo(%s)",
kX11AppBundleId); kX11AppBundleId);
exit(1); exit(1);
} }
if (!CFURLGetFileSystemRepresentation(appURL, true,
(unsigned char *)x11_path,
sizeof(x11_path))) {
asl_log(aslc, NULL, ASL_LEVEL_ERR,
"Xquartz: Error resolving URL for %s",
kX11AppBundleId);
exit(3);
}
strlcat(x11_path, kX11AppBundlePath, sizeof(x11_path));
asl_log(aslc, NULL, ASL_LEVEL_INFO, "Xquartz: X11.app = %s", x11_path);
break; break;
case kLSApplicationNotFoundErr: case kLSApplicationNotFoundErr:
@ -253,24 +241,23 @@ main(int argc, char **argv, char **envp)
server_bootstrap_name); server_bootstrap_name);
set_x11_path(); set_x11_path();
/* This forking is ugly and will be cleaned up later */ char *listenOnlyArg = "--listenonly";
child = fork(); CFStringRef silentLaunchArg = CFStringCreateWithCString(NULL, listenOnlyArg, kCFStringEncodingUTF8);
if (child == -1) { CFStringRef args[] = { silentLaunchArg };
asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Could not fork: %s", CFArrayRef passArgv = CFArrayCreate(NULL, (const void**) args, 1, NULL);
strerror( LSApplicationParameters params = { 0, /* CFIndex version == 0 */
errno)); kLSLaunchDefaults, /* LSLaunchFlags flags */
return EXIT_FAILURE; &x11_appRef, /* FSRef application */
} NULL, /* void* asyncLaunchRefCon*/
NULL, /* CFDictionaryRef environment */
passArgv, /* CFArrayRef arguments */
NULL /* AppleEvent* initialEvent */
};
if (child == 0) { OSStatus status = LSOpenApplication(&params, NULL);
char *_argv[3]; if (status != noErr) {
_argv[0] = x11_path; asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Unable to launch: %d", (int)status);
_argv[1] = "--listenonly"; return EXIT_FAILURE;
_argv[2] = NULL;
asl_log(aslc, NULL, ASL_LEVEL_NOTICE,
"Xquartz: Starting X server: %s --listenonly",
x11_path);
return execvp(x11_path, _argv);
} }
/* Try connecting for 10 seconds */ /* Try connecting for 10 seconds */