aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/xquartz/mach-startup
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-05-16 08:06:12 +0000
committermarha <marha@users.sourceforge.net>2011-05-16 08:06:12 +0000
commit08cbf3b50bfe713044f36b363c73768cd042f13c (patch)
tree6be4c5dd7f5bc2f058228b2a2fa747a4d7666dc5 /xorg-server/hw/xquartz/mach-startup
parentd8c3e3d2ba88d6b87a718aef7f4fb4627113eb52 (diff)
downloadvcxsrv-08cbf3b50bfe713044f36b363c73768cd042f13c.tar.gz
vcxsrv-08cbf3b50bfe713044f36b363c73768cd042f13c.tar.bz2
vcxsrv-08cbf3b50bfe713044f36b363c73768cd042f13c.zip
xserver xkeyboar-config mesa git update 16 May 2011
Diffstat (limited to 'xorg-server/hw/xquartz/mach-startup')
-rw-r--r--xorg-server/hw/xquartz/mach-startup/Makefile.am1
-rw-r--r--xorg-server/hw/xquartz/mach-startup/bundle-main.c56
-rw-r--r--xorg-server/hw/xquartz/mach-startup/launchd_fd.c18
-rw-r--r--xorg-server/hw/xquartz/mach-startup/stub.c69
4 files changed, 98 insertions, 46 deletions
diff --git a/xorg-server/hw/xquartz/mach-startup/Makefile.am b/xorg-server/hw/xquartz/mach-startup/Makefile.am
index 4dff45aa8..1ce54ad86 100644
--- a/xorg-server/hw/xquartz/mach-startup/Makefile.am
+++ b/xorg-server/hw/xquartz/mach-startup/Makefile.am
@@ -1,4 +1,5 @@
AM_CPPFLAGS = \
+ -I$(srcdir)/.. \
-DBUILD_DATE=\"$(BUILD_DATE)\" \
-DXSERVER_VERSION=\"$(VERSION)\" \
-DX11BINDIR=\"$(bindir)\"
diff --git a/xorg-server/hw/xquartz/mach-startup/bundle-main.c b/xorg-server/hw/xquartz/mach-startup/bundle-main.c
index 846025b44..8e3437644 100644
--- a/xorg-server/hw/xquartz/mach-startup/bundle-main.c
+++ b/xorg-server/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>
@@ -60,12 +61,14 @@
#include "mach_startup.h"
#include "mach_startupServer.h"
-#include "launchd_fd.h"
+#include "console_redirect.h"
+
/* From darwinEvents.c ... but don't want to pull in all the server cruft */
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 +105,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 *pref_app_to_run;
+static char *pref_login_shell;
+static char *pref_startx_script;
+
#ifndef HAVE_LIBDISPATCH
/*** Pthread Magics ***/
static pthread_t create_thread(void *(*func)(void *), void *arg) {
@@ -446,7 +453,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(pref_app_to_run);
}
}
@@ -457,7 +464,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(pref_startx_script);
}
/** Setup the environment we want our child processes to inherit */
@@ -475,6 +482,28 @@ static void ensure_path(const char *dir) {
}
}
+static void setup_console_redirect(const char *bundle_id) {
+ char *asl_sender;
+ char *asl_facility;
+ aslclient aslc;
+
+ asprintf(&asl_sender, "%s.server", bundle_id);
+ assert(asl_sender);
+
+ asl_facility = strdup(bundle_id);
+ assert(asl_facility);
+ if(strcmp(asl_facility + strlen(asl_facility) - 4, ".X11") == 0)
+ asl_facility[strlen(asl_facility) - 4] = '\0';
+
+ assert(aslc = asl_open(asl_sender, asl_facility, ASL_OPT_NO_DELAY));
+ free(asl_sender);
+ free(asl_facility);
+
+ asl_set_filter(aslc, ASL_FILTER_MASK_UPTO(ASL_LEVEL_WARNING));
+ xq_asl_capture_fd(aslc, NULL, ASL_LEVEL_INFO, STDOUT_FILENO);
+ xq_asl_capture_fd(aslc, NULL, ASL_LEVEL_NOTICE, STDERR_FILENO);
+}
+
static void setup_env(void) {
char *temp;
const char *pds = NULL;
@@ -497,6 +526,8 @@ static void setup_env(void) {
pds = BUNDLE_ID_PREFIX".X11";
}
+ setup_console_redirect(pds);
+
server_bootstrap_name = strdup(pds);
if(!server_bootstrap_name) {
ErrorF("X11.app: Memory allocation error.\n");
@@ -594,11 +625,20 @@ int main(int argc, char **argv, char **envp) {
pid_t child1, child2;
int status;
+ pref_app_to_run = command_from_prefs("app_to_run", DEFAULT_CLIENT);
+ assert(pref_app_to_run);
+
+ pref_login_shell = command_from_prefs("login_shell", DEFAULT_SHELL);
+ assert(pref_login_shell);
+
+ pref_startx_script = command_from_prefs("startx_script", DEFAULT_STARTX);
+ assert(pref_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 +647,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 +669,10 @@ int main(int argc, char **argv, char **envp) {
default: /* parent */
waitpid(child1, &status, 0);
}
+
+ free(pref_app_to_run);
+ free(pref_login_shell);
+ free(pref_startx_script);
}
/* Main event loop */
@@ -646,7 +690,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] = pref_login_shell;
newargv[1] = "-c";
newargv[2] = command;
newargv[3] = NULL;
diff --git a/xorg-server/hw/xquartz/mach-startup/launchd_fd.c b/xorg-server/hw/xquartz/mach-startup/launchd_fd.c
index 5c7e03cf3..8003dd177 100644
--- a/xorg-server/hw/xquartz/mach-startup/launchd_fd.c
+++ b/xorg-server/hw/xquartz/mach-startup/launchd_fd.c
@@ -31,41 +31,43 @@
#endif
#include <launch.h>
-#include <stdio.h>
+#include <asl.h>
#include <errno.h>
#include "launchd_fd.h"
+extern aslclient aslc;
+
int launchd_display_fd(void) {
launch_data_t sockets_dict, checkin_request, checkin_response;
launch_data_t listening_fd_array, listening_fd;
/* Get launchd fd */
if ((checkin_request = launch_data_new_string(LAUNCH_KEY_CHECKIN)) == NULL) {
- fprintf(stderr,"launch_data_new_string(\"" LAUNCH_KEY_CHECKIN "\") Unable to create string.\n");
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "launch_data_new_string(\"" LAUNCH_KEY_CHECKIN "\") Unable to create string.\n");
return ERROR_FD;
}
if ((checkin_response = launch_msg(checkin_request)) == NULL) {
- fprintf(stderr,"launch_msg(\"" LAUNCH_KEY_CHECKIN "\") IPC failure: %s\n",strerror(errno));
+ asl_log(aslc, NULL, ASL_LEVEL_WARNING, "launch_msg(\"" LAUNCH_KEY_CHECKIN "\") IPC failure: %s\n",strerror(errno));
return ERROR_FD;
}
if (LAUNCH_DATA_ERRNO == launch_data_get_type(checkin_response)) {
// ignore EACCES, which is common if we weren't started by launchd
if (launch_data_get_errno(checkin_response) != EACCES)
- fprintf(stderr,"launchd check-in failed: %s\n", strerror(launch_data_get_errno(checkin_response)));
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "launchd check-in failed: %s\n", strerror(launch_data_get_errno(checkin_response)));
return ERROR_FD;
}
sockets_dict = launch_data_dict_lookup(checkin_response, LAUNCH_JOBKEY_SOCKETS);
if (NULL == sockets_dict) {
- fprintf(stderr,"launchd check-in: no sockets found to answer requests on!\n");
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "launchd check-in: no sockets found to answer requests on!\n");
return ERROR_FD;
}
if (launch_data_dict_get_count(sockets_dict) > 1) {
- fprintf(stderr,"launchd check-in: some sockets will be ignored!\n");
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "launchd check-in: some sockets will be ignored!\n");
return ERROR_FD;
}
@@ -73,13 +75,13 @@ int launchd_display_fd(void) {
if (NULL == listening_fd_array) {
listening_fd_array = launch_data_dict_lookup(sockets_dict, ":0");
if (NULL == listening_fd_array) {
- fprintf(stderr,"launchd check-in: No known sockets found to answer requests on! \"%s:0\" and \":0\" failed.\n", BUNDLE_ID_PREFIX);
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "launchd check-in: No known sockets found to answer requests on! \"%s:0\" and \":0\" failed.\n", BUNDLE_ID_PREFIX);
return ERROR_FD;
}
}
if (launch_data_array_get_count(listening_fd_array)!=1) {
- fprintf(stderr,"launchd check-in: Expected 1 socket from launchd, got %u)\n",
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "launchd check-in: Expected 1 socket from launchd, got %u)\n",
(unsigned)launch_data_array_get_count(listening_fd_array));
return ERROR_FD;
}
diff --git a/xorg-server/hw/xquartz/mach-startup/stub.c b/xorg-server/hw/xquartz/mach-startup/stub.c
index c8a628311..8319dd06e 100644
--- a/xorg-server/hw/xquartz/mach-startup/stub.c
+++ b/xorg-server/hw/xquartz/mach-startup/stub.c
@@ -33,9 +33,9 @@
#endif
#include <string.h>
-#include <stdio.h>
#include <unistd.h>
#include <errno.h>
+#include <asl.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -43,8 +43,6 @@
#define kX11AppBundleId BUNDLE_ID_PREFIX".X11"
#define kX11AppBundlePath "/Contents/MacOS/X11"
-static char *server_bootstrap_name = kX11AppBundleId;
-
#include <mach/mach.h>
#include <mach/mach_error.h>
#include <servers/bootstrap.h>
@@ -57,8 +55,8 @@ static char *server_bootstrap_name = kX11AppBundleId;
#include "launchd_fd.h"
static char x11_path[PATH_MAX + 1];
-
static pid_t x11app_pid = 0;
+aslclient aslc;
static void set_x11_path(void) {
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
@@ -69,26 +67,24 @@ static void set_x11_path(void) {
switch (osstatus) {
case noErr:
if (appURL == NULL) {
- fprintf(stderr, "Xquartz: Invalid response from LSFindApplicationForInfo(%s)\n",
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Invalid response from LSFindApplicationForInfo(%s)",
kX11AppBundleId);
exit(1);
}
if (!CFURLGetFileSystemRepresentation(appURL, true, (unsigned char *)x11_path, sizeof(x11_path))) {
- fprintf(stderr, "Xquartz: Error resolving URL for %s\n", kX11AppBundleId);
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Error resolving URL for %s", kX11AppBundleId);
exit(3);
}
strlcat(x11_path, kX11AppBundlePath, sizeof(x11_path));
-#ifdef DEBUG
- fprintf(stderr, "Xquartz: X11.app = %s\n", x11_path);
-#endif
+ asl_log(aslc, NULL, ASL_LEVEL_INFO, "Xquartz: X11.app = %s", x11_path);
break;
case kLSApplicationNotFoundErr:
- fprintf(stderr, "Xquartz: Unable to find application for %s\n", kX11AppBundleId);
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Unable to find application for %s", kX11AppBundleId);
exit(10);
default:
- fprintf(stderr, "Xquartz: Unable to find application for %s, error code = %d\n",
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Unable to find application for %s, error code = %d",
kX11AppBundleId, (int)osstatus);
exit(11);
}
@@ -114,12 +110,12 @@ static int connect_to_socket(const char *filename) {
ret_fd = socket(PF_UNIX, SOCK_STREAM, 0);
if(ret_fd == -1) {
- fprintf(stderr, "Xquartz: Failed to create socket: %s - %s\n", filename, strerror(errno));
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Failed to create socket: %s - %s", filename, strerror(errno));
return -1;
}
if(connect(ret_fd, servaddr, servaddr_len) < 0) {
- fprintf(stderr, "Xquartz: Failed to connect to socket: %s - %d - %s\n", filename, errno, strerror(errno));
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Failed to connect to socket: %s - %d - %s", filename, errno, strerror(errno));
close(ret_fd);
return -1;
}
@@ -160,14 +156,11 @@ static void send_fd_handoff(int connected_fd, int launchd_fd) {
*((int*)CMSG_DATA(cmsg)) = launchd_fd;
if(sendmsg(connected_fd, &msg, 0) < 0) {
- fprintf(stderr, "Xquartz: Error sending $DISPLAY file descriptor over fd %d: %d -- %s\n", connected_fd, errno, strerror(errno));
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Error sending $DISPLAY file descriptor over fd %d: %d -- %s", connected_fd, errno, strerror(errno));
return;
}
-#ifdef DEBUG
- fprintf(stderr, "Xquartz: Message sent. Closing handoff fd.\n");
-#endif
-
+ asl_log(aslc, NULL, ASL_LEVEL_DEBUG, "Xquartz: Message sent. Closing handoff fd.");
close(connected_fd);
}
@@ -187,10 +180,25 @@ int main(int argc, char **argv, char **envp) {
int launchd_fd;
string_t handoff_socket_filename;
sig_t handler;
+ char *asl_sender;
+ char *asl_facility;
+ char *server_bootstrap_name = kX11AppBundleId;
if(getenv("X11_PREFS_DOMAIN"))
server_bootstrap_name = getenv("X11_PREFS_DOMAIN");
-
+
+ asprintf(&asl_sender, "%s.stub", server_bootstrap_name);
+ assert(asl_sender);
+
+ asl_facility = strdup(server_bootstrap_name);
+ assert(asl_facility);
+ if(strcmp(asl_facility + strlen(asl_facility) - 4, ".X11") == 0)
+ asl_facility[strlen(asl_facility) - 4] = '\0';
+
+ assert(aslc = asl_open(asl_sender, asl_facility, ASL_OPT_NO_DELAY));
+ free(asl_sender);
+ free(asl_facility);
+
/* We don't have a mechanism in place to handle this interrupt driven
* server-start notification, so just send the signal now, so xinit doesn't
* time out waiting for it and will just poll for the server.
@@ -211,13 +219,13 @@ int main(int argc, char **argv, char **envp) {
if(kr != KERN_SUCCESS) {
pid_t child;
- fprintf(stderr, "Xquartz: Unable to locate waiting server: %s\n", server_bootstrap_name);
+ asl_log(aslc, NULL, ASL_LEVEL_WARNING, "Xquartz: Unable to locate waiting server: %s", server_bootstrap_name);
set_x11_path();
/* This forking is ugly and will be cleaned up later */
child = fork();
if(child == -1) {
- fprintf(stderr, "Xquartz: Could not fork: %s\n", strerror(errno));
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Could not fork: %s", strerror(errno));
return EXIT_FAILURE;
}
@@ -226,7 +234,7 @@ int main(int argc, char **argv, char **envp) {
_argv[0] = x11_path;
_argv[1] = "--listenonly";
_argv[2] = NULL;
- fprintf(stderr, "Xquartz: Starting X server: %s --listenonly\n", x11_path);
+ asl_log(aslc, NULL, ASL_LEVEL_NOTICE, "Xquartz: Starting X server: %s --listenonly", x11_path);
return execvp(x11_path, _argv);
}
@@ -240,9 +248,9 @@ int main(int argc, char **argv, char **envp) {
if(kr != KERN_SUCCESS) {
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
- fprintf(stderr, "Xquartz: bootstrap_look_up(): %s\n", bootstrap_strerror(kr));
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: bootstrap_look_up(): %s", bootstrap_strerror(kr));
#else
- fprintf(stderr, "Xquartz: bootstrap_look_up(): %ul\n", (unsigned long)kr);
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: bootstrap_look_up(): %ul", (unsigned long)kr);
#endif
return EXIT_FAILURE;
}
@@ -258,20 +266,17 @@ int main(int argc, char **argv, char **envp) {
for(try=0, try_max=5; try < try_max; try++) {
if(request_fd_handoff_socket(mp, handoff_socket_filename) != KERN_SUCCESS) {
- fprintf(stderr, "Xquartz: Failed to request a socket from the server to send the $DISPLAY fd over (try %d of %d)\n", (int)try+1, (int)try_max);
+ asl_log(aslc, NULL, ASL_LEVEL_INFO, "Xquartz: Failed to request a socket from the server to send the $DISPLAY fd over (try %d of %d)", (int)try+1, (int)try_max);
continue;
}
handoff_fd = connect_to_socket(handoff_socket_filename);
if(handoff_fd == -1) {
- fprintf(stderr, "Xquartz: Failed to connect to socket (try %d of %d)\n", (int)try+1, (int)try_max);
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Failed to connect to socket (try %d of %d)", (int)try+1, (int)try_max);
continue;
}
-#ifdef DEBUG
- fprintf(stderr, "Xquartz: Handoff connection established (try %d of %d) on fd %d, \"%s\". Sending message.\n", (int)try+1, (int)try_max, handoff_fd, handoff_socket_filename);
-#endif
-
+ asl_log(aslc, NULL, ASL_LEVEL_INFO, "Xquartz: Handoff connection established (try %d of %d) on fd %d, \"%s\". Sending message.", (int)try+1, (int)try_max, handoff_fd, handoff_socket_filename);
send_fd_handoff(handoff_fd, launchd_fd);
close(handoff_fd);
break;
@@ -288,7 +293,7 @@ int main(int argc, char **argv, char **envp) {
newenvp = (string_array_t)calloc((1 + envpc), sizeof(string_t));
if(!newargv || !newenvp) {
- fprintf(stderr, "Xquartz: Memory allocation failure\n");
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Memory allocation failure");
return EXIT_FAILURE;
}
@@ -305,7 +310,7 @@ int main(int argc, char **argv, char **envp) {
free(newenvp);
if (kr != KERN_SUCCESS) {
- fprintf(stderr, "Xquartz: start_x11_server: %s\n", mach_error_string(kr));
+ asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: start_x11_server: %s", mach_error_string(kr));
return EXIT_FAILURE;
}
return EXIT_SUCCESS;