aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/hw/xquartz/mach-startup
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2012-03-28 09:11:07 +0200
committermarha <marha@users.sourceforge.net>2012-03-28 09:11:07 +0200
commit9b51c6da8bffdd67353b1e1245698a7eac478481 (patch)
treecde44c263cb1756fae5b4a83facb3c0cdfa474e4 /xorg-server/hw/xquartz/mach-startup
parentfb2b04331b6ae2cd11f6132cf16f6fcd848fb6b8 (diff)
parentec617f09d07e32d6f57c0da133f53ad3d43a568a (diff)
downloadvcxsrv-9b51c6da8bffdd67353b1e1245698a7eac478481.tar.gz
vcxsrv-9b51c6da8bffdd67353b1e1245698a7eac478481.tar.bz2
vcxsrv-9b51c6da8bffdd67353b1e1245698a7eac478481.zip
Merge remote-tracking branch 'origin/released'
Diffstat (limited to 'xorg-server/hw/xquartz/mach-startup')
-rw-r--r--xorg-server/hw/xquartz/mach-startup/bundle-main.c254
-rw-r--r--xorg-server/hw/xquartz/mach-startup/launchd_fd.c39
-rw-r--r--xorg-server/hw/xquartz/mach-startup/launchd_fd.h5
-rw-r--r--xorg-server/hw/xquartz/mach-startup/stub.c102
4 files changed, 214 insertions, 186 deletions
diff --git a/xorg-server/hw/xquartz/mach-startup/bundle-main.c b/xorg-server/hw/xquartz/mach-startup/bundle-main.c
index 7a53803da..d1ad6f7e3 100644
--- a/xorg-server/hw/xquartz/mach-startup/bundle-main.c
+++ b/xorg-server/hw/xquartz/mach-startup/bundle-main.c
@@ -1,32 +1,32 @@
/* main.c -- X application launcher
-
- Copyright (c) 2007 Jeremy Huddleston
- Copyright (c) 2007 Apple Inc
-
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation files
- (the "Software"), to deal in the Software without restriction,
- including without limitation the rights to use, copy, modify, merge,
- publish, distribute, sublicense, and/or sell copies of the Software,
- and to permit persons to whom the Software is furnished to do so,
- subject to the following conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
- HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- DEALINGS IN THE SOFTWARE.
-
- Except as contained in this notice, the name(s) of the above
- copyright holders shall not be used in advertising or otherwise to
- promote the sale, use or other dealings in this Software without
- prior written authorization. */
+ * Copyright (c) 2007 Jeremy Huddleston
+ * Copyright (c) 2007-2012 Apple Inc. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
+ * HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name(s) of the above
+ * copyright holders shall not be used in advertising or otherwise to
+ * promote the sale, use or other dealings in this Software without
+ * prior written authorization.
+ */
#include <CoreFoundation/CoreFoundation.h>
#include <AvailabilityMacros.h>
@@ -64,18 +64,16 @@
#include "console_redirect.h"
/* From darwinEvents.c ... but don't want to pull in all the server cruft */
-void DarwinListenOnOpenFD(int fd);
+void
+DarwinListenOnOpenFD(int fd);
extern aslclient aslc;
/* Ditto, from os/log.c */
extern void
-ErrorF(const char *f, ...)
-_X_ATTRIBUTE_PRINTF(1, 2);
+ErrorF(const char *f, ...) _X_ATTRIBUTE_PRINTF(1, 2);
extern void
-FatalError(const char *f, ...)
-_X_ATTRIBUTE_PRINTF(1, 2)
- _X_NORETURN;
+FatalError(const char *f, ...) _X_ATTRIBUTE_PRINTF(1, 2) _X_NORETURN;
extern int noPanoramiXExtension;
@@ -91,14 +89,13 @@ extern int noPanoramiXExtension;
#endif
static char __crashreporter_info_buff__[4096] = { 0 };
-
-static const char *__crashreporter_info__ __attribute__ ((__used__)) =
+static const char *__crashreporter_info__ __attribute__((__used__)) =
&__crashreporter_info_buff__[0];
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
// This is actually a toolchain requirement, but I'm not sure the correct check,
// but it should be fine to just only include it for Leopard and later. This line
// just tells the linker to never strip this symbol (such as for space optimization)
-asm(".desc ___crashreporter_info__, 0x10");
+asm (".desc ___crashreporter_info__, 0x10");
#endif
static const char *__crashreporter_info__base =
@@ -110,10 +107,13 @@ static char *server_bootstrap_name = NULL;
#define DEBUG 1
/* This is in quartzStartup.c */
-int server_main(int argc, char **argv, char **envp);
+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 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;
@@ -122,7 +122,7 @@ static char *pref_startx_script;
#ifndef HAVE_LIBDISPATCH
/*** Pthread Magics ***/
static pthread_t
-create_thread(void *(*func) (void *), void *arg)
+create_thread(void *(*func)(void *), void *arg)
{
pthread_attr_t attr;
pthread_t tid;
@@ -162,8 +162,8 @@ checkin_or_register(char *bname)
exit(EXIT_FAILURE);
}
- kr = mach_port_insert_right(mach_task_self(), mp, mp,
- MACH_MSG_TYPE_MAKE_SEND);
+ kr = mach_port_insert_right(
+ mach_task_self(), mp, mp, MACH_MSG_TYPE_MAKE_SEND);
if (kr != KERN_SUCCESS) {
ErrorF("mach_port_insert_right(): %s\n", mach_error_string(kr));
exit(EXIT_FAILURE);
@@ -171,7 +171,7 @@ checkin_or_register(char *bname)
#ifdef __clang__
#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations" // bootstrap_register
+#pragma clang diagnostic ignored "-Wdeprecated-declarations" // bootstrap_register
#endif
kr = bootstrap_register(bootstrap_port, bname, mp);
#ifdef __clang__
@@ -221,16 +221,16 @@ accept_fd_handoff(int connected_fd)
msg.msg_controllen = cmsg->cmsg_len;
- *((int *) CMSG_DATA(cmsg)) = -1;
+ *((int *)CMSG_DATA(cmsg)) = -1;
if (recvmsg(connected_fd, &msg, 0) < 0) {
- ErrorF
- ("X11.app: Error receiving $DISPLAY file descriptor. recvmsg() error: %s\n",
- strerror(errno));
+ ErrorF(
+ "X11.app: Error receiving $DISPLAY file descriptor. recvmsg() error: %s\n",
+ strerror(errno));
return -1;
}
- launchd_fd = *((int *) CMSG_DATA(cmsg));
+ launchd_fd = *((int *)CMSG_DATA(cmsg));
return launchd_fd;
}
@@ -245,13 +245,13 @@ typedef struct {
*/
#ifdef HAVE_LIBDISPATCH
static void
-socket_handoff(socket_handoff_t * handoff_data)
+socket_handoff(socket_handoff_t *handoff_data)
{
#else
static void *
socket_handoff_thread(void *arg)
{
- socket_handoff_t *handoff_data = (socket_handoff_t *) arg;
+ socket_handoff_t *handoff_data = (socket_handoff_t *)arg;
#endif
int launchd_fd = -1;
@@ -263,17 +263,17 @@ socket_handoff_thread(void *arg)
while (launchd_fd == -1) {
connected_fd = accept(handoff_data->fd, NULL, NULL);
if (connected_fd == -1) {
- ErrorF
- ("X11.app: Failed to accept incoming connection on socket (fd=%d): %s\n",
- handoff_data->fd, strerror(errno));
+ ErrorF(
+ "X11.app: Failed to accept incoming connection on socket (fd=%d): %s\n",
+ handoff_data->fd, strerror(errno));
sleep(2);
continue;
}
launchd_fd = accept_fd_handoff(connected_fd);
if (launchd_fd == -1)
- ErrorF
- ("X11.app: Error receiving $DISPLAY file descriptor, no descriptor received? Waiting for another connection.\n");
+ ErrorF(
+ "X11.app: Error receiving $DISPLAY file descriptor, no descriptor received? Waiting for another connection.\n");
close(connected_fd);
}
@@ -282,9 +282,9 @@ socket_handoff_thread(void *arg)
unlink(handoff_data->filename);
free(handoff_data);
- ErrorF
- ("X11.app Handing off fd to server thread via DarwinListenOnOpenFD(%d)\n",
- launchd_fd);
+ ErrorF(
+ "X11.app Handing off fd to server thread via DarwinListenOnOpenFD(%d)\n",
+ launchd_fd);
DarwinListenOnOpenFD(launchd_fd);
#ifndef HAVE_LIBDISPATCH
@@ -310,35 +310,38 @@ create_socket(char *filename_out)
strlcpy(servaddr_un.sun_path, filename_out,
sizeof(servaddr_un.sun_path));
- servaddr = (struct sockaddr *) &servaddr_un;
- servaddr_len =
- sizeof(struct sockaddr_un) - sizeof(servaddr_un.sun_path) +
- strlen(filename_out);
+ servaddr = (struct sockaddr *)&servaddr_un;
+ servaddr_len = sizeof(struct sockaddr_un) -
+ sizeof(servaddr_un.sun_path) + strlen(filename_out);
ret_fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (ret_fd == -1) {
- ErrorF("X11.app: Failed to create socket (try %d / %d): %s - %s\n",
- (int) try + 1, (int) try_max, filename_out, strerror(errno));
+ ErrorF(
+ "X11.app: Failed to create socket (try %d / %d): %s - %s\n",
+ (int)try + 1, (int)try_max, filename_out, strerror(errno));
continue;
}
if (bind(ret_fd, servaddr, servaddr_len) != 0) {
ErrorF("X11.app: Failed to bind socket: %d - %s\n", errno,
- strerror(errno));
+ strerror(
+ errno));
close(ret_fd);
return 0;
}
if (listen(ret_fd, 10) != 0) {
ErrorF("X11.app: Failed to listen to socket: %s - %d - %s\n",
- filename_out, errno, strerror(errno));
+ filename_out, errno, strerror(
+ errno));
close(ret_fd);
return 0;
}
#ifdef DEBUG
ErrorF("X11.app: Listening on socket for fd handoff: (%d) %s\n",
- ret_fd, filename_out);
+ ret_fd,
+ filename_out);
#endif
return ret_fd;
@@ -356,7 +359,7 @@ do_request_fd_handoff_socket(mach_port_t port, string_t filename)
launchd_socket_handed_off = 1;
- handoff_data = (socket_handoff_t *) calloc(1, sizeof(socket_handoff_t));
+ handoff_data = (socket_handoff_t *)calloc(1, sizeof(socket_handoff_t));
if (!handoff_data) {
ErrorF("X11.app: Error allocating memory for handoff_data\n");
return KERN_FAILURE;
@@ -371,17 +374,17 @@ do_request_fd_handoff_socket(mach_port_t port, string_t filename)
strlcpy(filename, handoff_data->filename, STRING_T_SIZE);
#ifdef HAVE_LIBDISPATCH
- dispatch_async(dispatch_get_global_queue
- (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ {
- socket_handoff(handoff_data);}
- );
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
+ 0), ^ {
+ socket_handoff(handoff_data);
+ });
#else
create_thread(socket_handoff_thread, handoff_data);
#endif
#ifdef DEBUG
- ErrorF
- ("X11.app: Thread created for handoff. Returning success to tell caller to connect and push the fd.\n");
+ ErrorF(
+ "X11.app: Thread created for handoff. Returning success to tell caller to connect and push the fd.\n");
#endif
return KERN_SUCCESS;
@@ -398,7 +401,8 @@ do_request_pid(mach_port_t port, int *my_pid)
kern_return_t
do_start_x11_server(mach_port_t port, string_array_t argv,
mach_msg_type_number_t argvCnt,
- string_array_t envp, mach_msg_type_number_t envpCnt)
+ string_array_t envp,
+ mach_msg_type_number_t envpCnt)
{
/* And now back to char ** */
char **_argv = alloca((argvCnt + 1) * sizeof(char *));
@@ -420,7 +424,7 @@ do_start_x11_server(mach_port_t port, string_array_t argv,
ErrorF("X11.app: do_start_x11_server(): argc=%d\n", argvCnt);
for (i = 0; i < argvCnt; i++) {
_argv[i] = argv[i];
- ErrorF("\targv[%u] = %s\n", (unsigned) i, argv[i]);
+ ErrorF("\targv[%u] = %s\n", (unsigned)i, argv[i]);
}
_argv[argvCnt] = NULL;
@@ -451,14 +455,13 @@ startup_trigger(int argc, char **argv, char **envp)
/* We need to count envp */
int envpc;
-
- for (envpc = 0; envp[envpc]; envpc++);
+ for (envpc = 0; envp[envpc]; envpc++) ;
/* We have fixed-size string lengths due to limitations in IPC,
* so we need to copy our argv and envp.
*/
- newargv = (string_array_t) alloca(argc * sizeof(string_t));
- newenvp = (string_array_t) alloca(envpc * sizeof(string_t));
+ newargv = (string_array_t)alloca(argc * sizeof(string_t));
+ newenvp = (string_array_t)alloca(envpc * sizeof(string_t));
if (!newargv || !newenvp) {
ErrorF("Memory allocation failure\n");
@@ -476,10 +479,11 @@ startup_trigger(int argc, char **argv, char **envp)
if (kr != KERN_SUCCESS) {
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
ErrorF("bootstrap_look_up(%s): %s\n", server_bootstrap_name,
- bootstrap_strerror(kr));
+ bootstrap_strerror(
+ kr));
#else
ErrorF("bootstrap_look_up(%s): %ul\n", server_bootstrap_name,
- (unsigned long) kr);
+ (unsigned long)kr);
#endif
exit(EXIT_FAILURE);
}
@@ -508,14 +512,14 @@ startup_trigger(int argc, char **argv, char **envp)
/* Start the server */
if ((s = getenv("DISPLAY"))) {
- ErrorF
- ("X11.app: Could not connect to server (DISPLAY=\"%s\", unsetting). Starting X server.\n",
- s);
+ ErrorF(
+ "X11.app: Could not connect to server (DISPLAY=\"%s\", unsetting). Starting X server.\n",
+ s);
unsetenv("DISPLAY");
}
else {
- ErrorF
- ("X11.app: Could not connect to server (DISPLAY is not set). Starting X server.\n");
+ ErrorF(
+ "X11.app: Could not connect to server (DISPLAY is not set). Starting X server.\n");
}
return execute(pref_startx_script);
}
@@ -530,7 +534,8 @@ ensure_path(const char *dir)
temp = getenv("PATH");
if (temp == NULL || temp[0] == 0) {
snprintf(buf, sizeof(buf),
- "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:%s", dir);
+ "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:%s",
+ dir);
setenv("PATH", buf, TRUE);
}
else if (strnstr(temp, X11BINDIR, sizeof(temp)) == NULL) {
@@ -574,10 +579,8 @@ setup_env(void)
* quartz-wm and the Xquartz stub's MachIPC)
*/
CFBundleRef bundle = CFBundleGetMainBundle();
-
if (bundle) {
CFStringRef pd = CFBundleGetIdentifier(bundle);
-
if (pd) {
pds = CFStringGetCStringPtr(pd, 0);
}
@@ -609,22 +612,22 @@ setup_env(void)
if (disp) {
/* s = basename(disp) */
const char *d, *s;
-
for (s = NULL, d = disp; *d; d++) {
if (*d == '/')
s = d + 1;
}
if (s && *s) {
- if (strcmp(bundle_id_prefix, "org.x") == 0 && strcmp(s, ":0") == 0) {
- ErrorF
- ("X11.app: Detected old style launchd DISPLAY, please update xinit.\n");
+ if (strcmp(bundle_id_prefix,
+ "org.x") == 0 && strcmp(s, ":0") == 0) {
+ ErrorF(
+ "X11.app: Detected old style launchd DISPLAY, please update xinit.\n");
}
else {
- temp = (char *) malloc(sizeof(char) * len);
+ temp = (char *)malloc(sizeof(char) * len);
if (!temp) {
- ErrorF
- ("X11.app: Memory allocation error creating space for socket name test.\n");
+ ErrorF(
+ "X11.app: Memory allocation error creating space for socket name test.\n");
exit(1);
}
strlcpy(temp, bundle_id_prefix, len);
@@ -632,9 +635,9 @@ setup_env(void)
if (strcmp(temp, s) != 0) {
/* If we don't have a match, unset it. */
- ErrorF
- ("X11.app: DISPLAY (\"%s\") does not match our id (\"%s\"), unsetting.\n",
- disp, bundle_id_prefix);
+ ErrorF(
+ "X11.app: DISPLAY (\"%s\") does not match our id (\"%s\"), unsetting.\n",
+ disp, bundle_id_prefix);
unsetenv("DISPLAY");
}
free(temp);
@@ -642,8 +645,8 @@ setup_env(void)
}
else {
/* The DISPLAY environment variable is not formatted like a launchd socket, so reset. */
- ErrorF
- ("X11.app: DISPLAY does not look like a launchd set variable, unsetting.\n");
+ ErrorF(
+ "X11.app: DISPLAY does not look like a launchd set variable, unsetting.\n");
unsetenv("DISPLAY");
}
}
@@ -679,7 +682,7 @@ main(int argc, char **argv, char **envp)
ErrorF("X11.app: main(): argc=%d\n", argc);
for (i = 0; i < argc; i++) {
- ErrorF("\targv[%u] = %s\n", (unsigned) i, argv[i]);
+ ErrorF("\targv[%u] = %s\n", (unsigned)i, argv[i]);
if (!strcmp(argv[i], "--listenonly")) {
listenOnly = TRUE;
}
@@ -704,26 +707,26 @@ main(int argc, char **argv, char **envp)
pref_login_shell = command_from_prefs("login_shell", DEFAULT_SHELL);
assert(pref_login_shell);
- pref_startx_script =
- command_from_prefs("startx_script", DEFAULT_STARTX);
+ 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 */
+ case -1: /* error */
FatalError("fork() failed: %s\n", strerror(errno));
- case 0: /* child1 */
+ case 0: /* child1 */
child2 = fork();
switch (child2) {
int max_files;
- case -1: /* error */
+ case -1: /* error */
FatalError("fork() failed: %s\n", strerror(errno));
- case 0: /* child2 */
+ case 0: /* child2 */
/* close all open files except for standard streams */
max_files = sysconf(_SC_OPEN_MAX);
for (i = 3; i < max_files; i++)
@@ -735,12 +738,12 @@ main(int argc, char **argv, char **envp)
return startup_trigger(argc, argv, envp);
- default: /* parent (child1) */
+ default: /* parent (child1) */
_exit(0);
}
break;
- default: /* parent */
+ default: /* parent */
waitpid(child1, &status, 0);
}
@@ -773,10 +776,10 @@ execute(const char *command)
ErrorF("X11.app: Launching %s:\n", command);
for (p = newargv; *p; p++) {
- ErrorF("\targv[%ld] = %s\n", (long int) (p - newargv), *p);
+ ErrorF("\targv[%ld] = %s\n", (long int)(p - newargv), *p);
}
- execvp(newargv[0], (char *const *) newargv);
+ execvp(newargv[0], (char *const *)newargv);
perror("X11.app: Couldn't exec.");
return 1;
}
@@ -797,13 +800,13 @@ command_from_prefs(const char *key, const char *default_value)
if (!cfKey)
return NULL;
- PlistRef =
- CFPreferencesCopyAppValue(cfKey, kCFPreferencesCurrentApplication);
+ PlistRef = CFPreferencesCopyAppValue(cfKey,
+ kCFPreferencesCurrentApplication);
- if ((PlistRef == NULL) || (CFGetTypeID(PlistRef) != CFStringGetTypeID())) {
- CFStringRef cfDefaultValue =
- CFStringCreateWithCString(NULL, default_value,
- kCFStringEncodingASCII);
+ if ((PlistRef == NULL) ||
+ (CFGetTypeID(PlistRef) != CFStringGetTypeID())) {
+ CFStringRef cfDefaultValue = CFStringCreateWithCString(
+ NULL, default_value, kCFStringEncodingASCII);
int len = strlen(default_value) + 1;
if (!cfDefaultValue)
@@ -814,22 +817,21 @@ command_from_prefs(const char *key, const char *default_value)
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
CFRelease(cfDefaultValue);
- command = (char *) malloc(len * sizeof(char));
+ command = (char *)malloc(len * sizeof(char));
if (!command)
goto command_from_prefs_out;
strcpy(command, default_value);
}
else {
- int len = CFStringGetLength((CFStringRef) PlistRef) + 1;
-
- command = (char *) malloc(len * sizeof(char));
+ int len = CFStringGetLength((CFStringRef)PlistRef) + 1;
+ command = (char *)malloc(len * sizeof(char));
if (!command)
goto command_from_prefs_out;
- CFStringGetCString((CFStringRef) PlistRef, command, len,
+ CFStringGetCString((CFStringRef)PlistRef, command, len,
kCFStringEncodingASCII);
}
- command_from_prefs_out:
+command_from_prefs_out:
if (PlistRef)
CFRelease(PlistRef);
if (cfKey)
diff --git a/xorg-server/hw/xquartz/mach-startup/launchd_fd.c b/xorg-server/hw/xquartz/mach-startup/launchd_fd.c
index fd1d276e3..15866cc42 100644
--- a/xorg-server/hw/xquartz/mach-startup/launchd_fd.c
+++ b/xorg-server/hw/xquartz/mach-startup/launchd_fd.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008 Apple Inc.
+/* Copyright (c) 2008-2012 Apple Inc.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@@ -45,30 +45,35 @@ launchd_display_fd(void)
launch_data_t listening_fd_array, listening_fd;
/* Get launchd fd */
- if ((checkin_request = launch_data_new_string(LAUNCH_KEY_CHECKIN)) == NULL) {
- asl_log(aslc, NULL, ASL_LEVEL_ERR,
- "launch_data_new_string(\"" LAUNCH_KEY_CHECKIN
- "\") Unable to create string.\n");
+ if ((checkin_request = launch_data_new_string(LAUNCH_KEY_CHECKIN)) ==
+ NULL) {
+ 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) {
asl_log(aslc, NULL, ASL_LEVEL_WARNING,
"launch_msg(\"" LAUNCH_KEY_CHECKIN "\") IPC failure: %s\n",
- strerror(errno));
+ 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)
- asl_log(aslc, NULL, ASL_LEVEL_ERR, "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);
+ sockets_dict = launch_data_dict_lookup(checkin_response,
+ LAUNCH_JOBKEY_SOCKETS);
if (NULL == sockets_dict) {
asl_log(aslc, NULL, ASL_LEVEL_ERR,
"launchd check-in: no sockets found to answer requests on!\n");
@@ -81,14 +86,15 @@ launchd_display_fd(void)
return ERROR_FD;
}
- listening_fd_array =
- launch_data_dict_lookup(sockets_dict, BUNDLE_ID_PREFIX ":0");
+ listening_fd_array = launch_data_dict_lookup(sockets_dict,
+ BUNDLE_ID_PREFIX ":0");
if (NULL == listening_fd_array) {
listening_fd_array = launch_data_dict_lookup(sockets_dict, ":0");
if (NULL == listening_fd_array) {
- 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);
+ 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;
}
}
@@ -96,7 +102,8 @@ launchd_display_fd(void)
if (launch_data_array_get_count(listening_fd_array) != 1) {
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));
+ (unsigned)launch_data_array_get_count(
+ listening_fd_array));
return ERROR_FD;
}
diff --git a/xorg-server/hw/xquartz/mach-startup/launchd_fd.h b/xorg-server/hw/xquartz/mach-startup/launchd_fd.h
index 12caf7193..6af03a81d 100644
--- a/xorg-server/hw/xquartz/mach-startup/launchd_fd.h
+++ b/xorg-server/hw/xquartz/mach-startup/launchd_fd.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008 Apple Inc.
+/* Copyright (c) 2008-2012 Apple Inc.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@@ -31,6 +31,7 @@
#define ERROR_FD -1
-int launchd_display_fd(void);
+int
+launchd_display_fd(void);
#endif /* _XQUARTZ_LAUNCHD_FD_H_ */
diff --git a/xorg-server/hw/xquartz/mach-startup/stub.c b/xorg-server/hw/xquartz/mach-startup/stub.c
index f457aaba0..b5a3168ca 100644
--- a/xorg-server/hw/xquartz/mach-startup/stub.c
+++ b/xorg-server/hw/xquartz/mach-startup/stub.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008 Apple Inc.
+/* Copyright (c) 2008-2012 Apple Inc.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation files
@@ -40,7 +40,7 @@
#include <sys/socket.h>
#include <sys/un.h>
-#define kX11AppBundleId BUNDLE_ID_PREFIX".X11"
+#define kX11AppBundleId BUNDLE_ID_PREFIX ".X11"
#define kX11AppBundlePath "/Contents/MacOS/X11"
#include <mach/mach.h>
@@ -65,36 +65,43 @@ set_x11_path(void)
CFURLRef appURL = NULL;
OSStatus osstatus =
- LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(kX11AppBundleId), nil,
- nil, &appURL);
+ LSFindApplicationForInfo(kLSUnknownCreator, CFSTR(
+ kX11AppBundleId), nil, nil, &appURL);
switch (osstatus) {
case noErr:
if (appURL == NULL) {
- asl_log(aslc, NULL, ASL_LEVEL_ERR,
- "Xquartz: Invalid response from LSFindApplicationForInfo(%s)",
- kX11AppBundleId);
+ 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))) {
+ 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);
+ "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;
+
case kLSApplicationNotFoundErr:
asl_log(aslc, NULL, ASL_LEVEL_ERR,
- "Xquartz: Unable to find application for %s", kX11AppBundleId);
+ "Xquartz: Unable to find application for %s",
+ kX11AppBundleId);
exit(10);
+
default:
asl_log(aslc, NULL, ASL_LEVEL_ERR,
"Xquartz: Unable to find application for %s, error code = %d",
- kX11AppBundleId, (int) osstatus);
+ kX11AppBundleId,
+ (int)osstatus);
exit(11);
}
#else
@@ -117,23 +124,25 @@ connect_to_socket(const char *filename)
servaddr_un.sun_family = AF_UNIX;
strlcpy(servaddr_un.sun_path, filename, sizeof(servaddr_un.sun_path));
- servaddr = (struct sockaddr *) &servaddr_un;
- servaddr_len =
- sizeof(struct sockaddr_un) - sizeof(servaddr_un.sun_path) +
- strlen(filename);
+ servaddr = (struct sockaddr *)&servaddr_un;
+ servaddr_len = sizeof(struct sockaddr_un) -
+ sizeof(servaddr_un.sun_path) + strlen(filename);
ret_fd = socket(PF_UNIX, SOCK_STREAM, 0);
if (ret_fd == -1) {
asl_log(aslc, NULL, ASL_LEVEL_ERR,
"Xquartz: Failed to create socket: %s - %s", filename,
- strerror(errno));
+ strerror(
+ errno));
return -1;
}
if (connect(ret_fd, servaddr, servaddr_len) < 0) {
asl_log(aslc, NULL, ASL_LEVEL_ERR,
- "Xquartz: Failed to connect to socket: %s - %d - %s", filename,
- errno, strerror(errno));
+ "Xquartz: Failed to connect to socket: %s - %d - %s",
+ filename, errno,
+ strerror(
+ errno));
close(ret_fd);
return -1;
}
@@ -173,12 +182,13 @@ send_fd_handoff(int connected_fd, int launchd_fd)
msg.msg_controllen = cmsg->cmsg_len;
- *((int *) CMSG_DATA(cmsg)) = launchd_fd;
+ *((int *)CMSG_DATA(cmsg)) = launchd_fd;
if (sendmsg(connected_fd, &msg, 0) < 0) {
- asl_log(aslc, NULL, ASL_LEVEL_ERR,
- "Xquartz: Error sending $DISPLAY file descriptor over fd %d: %d -- %s",
- 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;
}
@@ -187,7 +197,7 @@ send_fd_handoff(int connected_fd, int launchd_fd)
close(connected_fd);
}
-__attribute__ ((__noreturn__))
+__attribute__((__noreturn__))
static void
signal_handler(int sig)
{
@@ -256,18 +266,19 @@ main(int argc, char **argv, char **envp)
child = fork();
if (child == -1) {
asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: Could not fork: %s",
- strerror(errno));
+ strerror(
+ errno));
return EXIT_FAILURE;
}
if (child == 0) {
char *_argv[3];
-
_argv[0] = x11_path;
_argv[1] = "--listenonly";
_argv[2] = NULL;
asl_log(aslc, NULL, ASL_LEVEL_NOTICE,
- "Xquartz: Starting X server: %s --listenonly", x11_path);
+ "Xquartz: Starting X server: %s --listenonly",
+ x11_path);
return execvp(x11_path, _argv);
}
@@ -282,10 +293,12 @@ main(int argc, char **argv, char **envp)
if (kr != KERN_SUCCESS) {
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
asl_log(aslc, NULL, ASL_LEVEL_ERR,
- "Xquartz: bootstrap_look_up(): %s", bootstrap_strerror(kr));
+ "Xquartz: bootstrap_look_up(): %s", bootstrap_strerror(
+ kr));
#else
asl_log(aslc, NULL, ASL_LEVEL_ERR,
- "Xquartz: bootstrap_look_up(): %ul", (unsigned long) kr);
+ "Xquartz: bootstrap_look_up(): %ul",
+ (unsigned long)kr);
#endif
return EXIT_FAILURE;
}
@@ -300,11 +313,13 @@ main(int argc, char **argv, char **envp)
int handoff_fd = -1;
for (try = 0, try_max = 5; try < try_max; try++) {
- if (request_fd_handoff_socket(mp, handoff_socket_filename) !=
+ if (request_fd_handoff_socket(mp,
+ handoff_socket_filename) !=
KERN_SUCCESS) {
- 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);
+ 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;
}
@@ -312,14 +327,16 @@ main(int argc, char **argv, char **envp)
if (handoff_fd == -1) {
asl_log(aslc, NULL, ASL_LEVEL_ERR,
"Xquartz: Failed to connect to socket (try %d of %d)",
- (int) try + 1, (int) try_max);
+ (int)try + 1,
+ (int)try_max);
continue;
}
- 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);
+ 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;
@@ -327,13 +344,13 @@ main(int argc, char **argv, char **envp)
}
/* Count envp */
- for (envpc = 0; envp[envpc]; envpc++);
+ for (envpc = 0; envp[envpc]; envpc++) ;
/* We have fixed-size string lengths due to limitations in IPC,
* so we need to copy our argv and envp.
*/
- newargv = (string_array_t) calloc((1 + argc), sizeof(string_t));
- newenvp = (string_array_t) calloc((1 + envpc), sizeof(string_t));
+ newargv = (string_array_t)calloc((1 + argc), sizeof(string_t));
+ newenvp = (string_array_t)calloc((1 + envpc), sizeof(string_t));
if (!newargv || !newenvp) {
asl_log(aslc, NULL, ASL_LEVEL_ERR,
@@ -355,7 +372,8 @@ main(int argc, char **argv, char **envp)
if (kr != KERN_SUCCESS) {
asl_log(aslc, NULL, ASL_LEVEL_ERR, "Xquartz: start_x11_server: %s",
- mach_error_string(kr));
+ mach_error_string(
+ kr));
return EXIT_FAILURE;
}
return EXIT_SUCCESS;