XQuartz: Move the launchd display grabbing into mach_startup
(cherry picked from commit c3866c98d23020d2151977ee1177b6054d05832e)
This commit is contained in:
parent
3a22190061
commit
225dddbaed
|
@ -45,9 +45,6 @@
|
||||||
#include "X11/extensions/applewm.h"
|
#include "X11/extensions/applewm.h"
|
||||||
#include "micmap.h"
|
#include "micmap.h"
|
||||||
|
|
||||||
#include "os.h"
|
|
||||||
#include "mach-startup/launchd_fd.h"
|
|
||||||
|
|
||||||
#include <mach/mach.h>
|
#include <mach/mach.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -815,14 +812,6 @@ void X11ApplicationMain (int argc, char **argv, char **envp) {
|
||||||
/* Tell the server thread that it can proceed */
|
/* Tell the server thread that it can proceed */
|
||||||
QuartzInitServer(argc, argv, envp);
|
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];
|
[NSApp run];
|
||||||
/* not reached */
|
/* not reached */
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,10 @@
|
||||||
#include "mach_startup.h"
|
#include "mach_startup.h"
|
||||||
#include "mach_startupServer.h"
|
#include "mach_startupServer.h"
|
||||||
|
|
||||||
|
#include "launchd_fd.h"
|
||||||
|
void DarwinListenOnOpenFD(int fd);
|
||||||
|
|
||||||
|
|
||||||
#define DEFAULT_CLIENT "/usr/X11/bin/xterm"
|
#define DEFAULT_CLIENT "/usr/X11/bin/xterm"
|
||||||
#define DEFAULT_STARTX "/usr/X11/bin/startx"
|
#define DEFAULT_STARTX "/usr/X11/bin/startx"
|
||||||
#define DEFAULT_SHELL "/bin/sh"
|
#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 int execute(const char *command);
|
||||||
static char *command_from_prefs(const char *key, const char *default_value);
|
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 {
|
struct arg {
|
||||||
int argc;
|
int argc;
|
||||||
char **argv;
|
char **argv;
|
||||||
|
@ -106,20 +123,6 @@ static mach_port_t checkin_or_register(char *bname) {
|
||||||
return mp;
|
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 ***/
|
/*** $DISPLAY handoff ***/
|
||||||
/* From darwinEvents.c ... but don't want to pull in all the server cruft */
|
/* From darwinEvents.c ... but don't want to pull in all the server cruft */
|
||||||
void DarwinListenOnOpenFD(int fd);
|
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) {
|
int startup_trigger(int argc, char **argv, char **envp) {
|
||||||
#else
|
#else
|
||||||
|
void *add_launchd_display_thread(void *data);
|
||||||
|
|
||||||
int main(int argc, char **argv, char **envp) {
|
int main(int argc, char **argv, char **envp) {
|
||||||
#endif
|
#endif
|
||||||
Display *display;
|
Display *display;
|
||||||
|
@ -345,6 +350,7 @@ int main(int argc, char **argv, char **envp) {
|
||||||
}
|
}
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
#else
|
#else
|
||||||
|
create_thread(add_launchd_display_thread, NULL);
|
||||||
return server_main(argc, argv, envp);
|
return server_main(argc, argv, envp);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -356,14 +362,9 @@ int main(int argc, char **argv, char **envp) {
|
||||||
/* Now, try to open a display, if so, run the launcher */
|
/* Now, try to open a display, if so, run the launcher */
|
||||||
display = XOpenDisplay(NULL);
|
display = XOpenDisplay(NULL);
|
||||||
if(display) {
|
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 */
|
/* Could open the display, start the launcher */
|
||||||
XCloseDisplay(display);
|
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));
|
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;
|
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
|
#endif
|
||||||
|
|
||||||
static int execute(const char *command) {
|
static int execute(const char *command) {
|
||||||
|
|
Loading…
Reference in New Issue