summaryrefslogtreecommitdiff
path: root/hw/xquartz/mach-startup/bundle-main.c
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@freedesktop.org>2008-05-23 01:39:02 -0700
committerJeremy Huddleston <jeremyhu@freedesktop.org>2008-05-23 02:31:41 -0700
commit225dddbaeded4d64fcc104da538449e5c4dedd2d (patch)
tree197a5b10b022e32c9af49a35303ccf424fd9f832 /hw/xquartz/mach-startup/bundle-main.c
parent3a22190061c7ebefee85564b0def5e1112c07ae8 (diff)
XQuartz: Move the launchd display grabbing into mach_startup
(cherry picked from commit c3866c98d23020d2151977ee1177b6054d05832e)
Diffstat (limited to 'hw/xquartz/mach-startup/bundle-main.c')
-rw-r--r--hw/xquartz/mach-startup/bundle-main.c53
1 files changed, 33 insertions, 20 deletions
diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 0fab99044..73c0483ab 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -47,6 +47,10 @@
#include "mach_startup.h"
#include "mach_startupServer.h"
+#include "launchd_fd.h"
+void DarwinListenOnOpenFD(int fd);
+
+
#define DEFAULT_CLIENT "/usr/X11/bin/xterm"
#define DEFAULT_STARTX "/usr/X11/bin/startx"
#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 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 {
int argc;
char **argv;
@@ -106,20 +123,6 @@ static mach_port_t checkin_or_register(char *bname) {
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 ***/
/* From darwinEvents.c ... but don't want to pull in all the server cruft */
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) {
#else
+void *add_launchd_display_thread(void *data);
+
int main(int argc, char **argv, char **envp) {
#endif
Display *display;
@@ -345,6 +350,7 @@ int main(int argc, char **argv, char **envp) {
}
exit(EXIT_SUCCESS);
#else
+ create_thread(add_launchd_display_thread, NULL);
return server_main(argc, argv, envp);
#endif
}
@@ -356,14 +362,9 @@ int main(int argc, char **argv, char **envp) {
/* Now, try to open a display, if so, run the launcher */
display = XOpenDisplay(NULL);
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 */
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));
}
}
@@ -434,6 +435,18 @@ int main(int argc, char **argv, char **envp) {
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
static int execute(const char *command) {