[Xquartz-changes] xserver: Branch 'master'
Jeremy Huddleston
jeremyhu at freedesktop.org
Tue May 10 23:52:32 PDT 2011
hw/xquartz/mach-startup/bundle-main.c | 29 ++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)
New commits:
commit 6f7d7c5829063c19564f9312ce4fe6541189e5a4
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date: Tue May 10 23:42:46 2011 -0700
Don't call into CoreFoundation after fork() and before exec()
After fork()ing, we should just limit ourselves to setting up
the environment, file descriptors, and exec()ing.
Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 846025b..e36155c 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -36,6 +36,7 @@
#endif
#include <X11/Xlib.h>
+#include <assert.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
@@ -66,6 +67,7 @@ void DarwinListenOnOpenFD(int fd);
/* Ditto, from os/log.c */
extern void ErrorF(const char *f, ...) _X_ATTRIBUTE_PRINTF(1,2);
+extern void FatalError(const char *f, ...) _X_ATTRIBUTE_PRINTF(1,2) _X_NORETURN;
extern int noPanoramiXExtension;
@@ -102,6 +104,10 @@ 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);
+static char *_app_to_run;
+static char *_login_shell;
+static char *_startx_script;
+
#ifndef HAVE_LIBDISPATCH
/*** Pthread Magics ***/
static pthread_t create_thread(void *(*func)(void *), void *arg) {
@@ -446,7 +452,7 @@ static int startup_trigger(int argc, char **argv, char **envp) {
/* Could open the display, start the launcher */
XCloseDisplay(display);
- return execute(command_from_prefs("app_to_run", DEFAULT_CLIENT));
+ return execute(_app_to_run);
}
}
@@ -457,7 +463,7 @@ static int startup_trigger(int argc, char **argv, char **envp) {
} else {
ErrorF("X11.app: Could not connect to server (DISPLAY is not set). Starting X server.\n");
}
- return execute(command_from_prefs("startx_script", DEFAULT_STARTX));
+ return execute(_startx_script);
}
/** Setup the environment we want our child processes to inherit */
@@ -594,11 +600,20 @@ int main(int argc, char **argv, char **envp) {
pid_t child1, child2;
int status;
+ _app_to_run = command_from_prefs("app_to_run", DEFAULT_CLIENT);
+ assert(_app_to_run);
+
+ _login_shell = command_from_prefs("login_shell", DEFAULT_SHELL);
+ assert(_login_shell);
+
+ _startx_script = command_from_prefs("startx_script", DEFAULT_STARTX);
+ assert(_startx_script);
+
/* Do the fork-twice trick to avoid having to reap zombies */
child1 = fork();
switch (child1) {
case -1: /* error */
- break;
+ FatalError("fork() failed: %s\n", strerror(errno));
case 0: /* child1 */
child2 = fork();
@@ -607,7 +622,7 @@ int main(int argc, char **argv, char **envp) {
int max_files, i;
case -1: /* error */
- break;
+ FatalError("fork() failed: %s\n", strerror(errno));
case 0: /* child2 */
/* close all open files except for standard streams */
@@ -629,6 +644,10 @@ int main(int argc, char **argv, char **envp) {
default: /* parent */
waitpid(child1, &status, 0);
}
+
+ free(_app_to_run);
+ free(_login_shell);
+ free(_startx_script);
}
/* Main event loop */
@@ -646,7 +665,7 @@ static int execute(const char *command) {
const char *newargv[4];
const char **p;
- newargv[0] = command_from_prefs("login_shell", DEFAULT_SHELL);
+ newargv[0] = _login_shell;
newargv[1] = "-c";
newargv[2] = command;
newargv[3] = NULL;
More information about the Xquartz-changes
mailing list