summaryrefslogtreecommitdiff
path: root/hw/xquartz/mach-startup
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@freedesktop.org>2008-10-28 12:38:05 -0700
committerJeremy Huddleston <jeremyhu@freedesktop.org>2008-10-28 22:01:40 -0700
commitf12d7ad1647d12ccf92291ebc0607defe6a634a1 (patch)
tree54e1cf7aff4c324dda2b3e292b32c6489bcedd20 /hw/xquartz/mach-startup
parent273df54685768f74ed29926e88a63dc9f86744f1 (diff)
XQuartz: Pass along SIGINT and SIGTERM from the stub to X11.app
(cherry picked from commit 183ca5d68b4f34e248749f304ce140de11bd451b)
Diffstat (limited to 'hw/xquartz/mach-startup')
-rw-r--r--hw/xquartz/mach-startup/Makefile.am4
-rw-r--r--hw/xquartz/mach-startup/bundle-main.c29
-rw-r--r--hw/xquartz/mach-startup/mach_startup.defs4
-rw-r--r--hw/xquartz/mach-startup/stub.c26
4 files changed, 27 insertions, 36 deletions
diff --git a/hw/xquartz/mach-startup/Makefile.am b/hw/xquartz/mach-startup/Makefile.am
index 97539e18f..800fb0c21 100644
--- a/hw/xquartz/mach-startup/Makefile.am
+++ b/hw/xquartz/mach-startup/Makefile.am
@@ -1,14 +1,12 @@
AM_CPPFLAGS = \
-DBUILD_DATE=\"$(BUILD_DATE)\" \
- -DXSERVER_VERSION=\"$(VERSION)\" \
- -DMACHO_STARTUP
+ -DXSERVER_VERSION=\"$(VERSION)\"
x11appdir = $(APPLE_APPLICATIONS_DIR)/X11.app/Contents/MacOS
x11app_PROGRAMS = X11
dist_X11_SOURCES = \
bundle-main.c
-# launchd_fd.c
nodist_X11_SOURCES = \
mach_startupServer.c \
diff --git a/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 576a37057..9f03647d2 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -37,6 +37,7 @@
#include <stdlib.h>
#include <pthread.h>
#include <stdbool.h>
+#include <signal.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -96,7 +97,6 @@ static pthread_t create_thread(void *func, void *arg) {
return tid;
}
-#ifdef MACHO_STARTUP
/*** Mach-O IPC Stuffs ***/
union MaxMsgSize {
@@ -303,6 +303,11 @@ kern_return_t do_request_fd_handoff_socket(mach_port_t port, string_t filename)
return KERN_SUCCESS;
}
+kern_return_t do_request_pid(mach_port_t port, int *my_pid) {
+ *my_pid = getpid();
+ return KERN_SUCCESS;
+}
+
/*** Server Startup ***/
kern_return_t do_start_x11_server(mach_port_t port, string_array_t argv,
mach_msg_type_number_t argvCnt,
@@ -336,17 +341,11 @@ 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;
const char *s;
/* Take care of the case where we're called like a normal DDX */
if(argc > 1 && argv[1][0] == ':') {
-#ifdef MACHO_STARTUP
size_t i;
kern_return_t kr;
mach_port_t mp;
@@ -387,10 +386,6 @@ int main(int argc, char **argv, char **envp) {
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
-#else
- create_thread(add_launchd_display_thread, NULL);
- return server_main(argc, argv, envp);
-#endif
}
/* If we have a process serial number and it's our only arg, act as if
@@ -424,7 +419,6 @@ int main(int argc, char **argv, char **envp) {
return execute(command_from_prefs("startx_script", DEFAULT_STARTX));
}
-#ifdef MACHO_STARTUP
/*** Main ***/
int main(int argc, char **argv, char **envp) {
Bool listenOnly = FALSE;
@@ -472,17 +466,6 @@ int main(int argc, char **argv, char **envp) {
return EXIT_SUCCESS;
}
-#else
-
-void *add_launchd_display_thread(void *data) {
- /* 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) {
const char *newargv[7];
diff --git a/hw/xquartz/mach-startup/mach_startup.defs b/hw/xquartz/mach-startup/mach_startup.defs
index 76c8edfd5..e47f49c3c 100644
--- a/hw/xquartz/mach-startup/mach_startup.defs
+++ b/hw/xquartz/mach-startup/mach_startup.defs
@@ -44,3 +44,7 @@ routine start_x11_server(
routine request_fd_handoff_socket (
port : mach_port_t;
out socket_filename : string_t);
+
+routine request_pid (
+ port : mach_port_t;
+ out pid : int);
diff --git a/hw/xquartz/mach-startup/stub.c b/hw/xquartz/mach-startup/stub.c
index 192a4328f..8bbd4d90e 100644
--- a/hw/xquartz/mach-startup/stub.c
+++ b/hw/xquartz/mach-startup/stub.c
@@ -48,6 +48,8 @@
#include <servers/bootstrap.h>
#include "mach_startup.h"
+#include <signal.h>
+
#include "launchd_fd.h"
#ifndef BUILD_DATE
@@ -61,6 +63,8 @@
static char x11_path[PATH_MAX + 1];
+static pid_t x11app_pid = 0;
+
static void set_x11_path() {
CFURLRef appURL = NULL;
CFBundleRef bundle = NULL;
@@ -115,7 +119,6 @@ static void set_x11_path() {
}
}
-#ifdef MACHO_STARTUP
static int connect_to_socket(const char *filename) {
struct sockaddr_un servaddr_un;
struct sockaddr *servaddr;
@@ -189,10 +192,13 @@ static void send_fd_handoff(int connected_fd, int launchd_fd) {
close(connected_fd);
}
-#endif
+static void signal_handler(int sig) {
+ if(x11app_pid)
+ kill(x11app_pid, sig);
+ _exit(0);
+}
int main(int argc, char **argv, char **envp) {
-#ifdef MACHO_STARTUP
int envpc;
kern_return_t kr;
mach_port_t mp;
@@ -201,7 +207,6 @@ int main(int argc, char **argv, char **envp) {
size_t i;
int launchd_fd;
string_t handoff_socket_filename;
-#endif
sig_t handler;
if(argc == 2 && !strcmp(argv[1], "-version")) {
@@ -220,7 +225,10 @@ int main(int argc, char **argv, char **envp) {
kill(getppid(), SIGUSR1);
signal(SIGUSR1, handler);
-#ifdef MACHO_STARTUP
+ /* Pass on SIGs to X11.app */
+ signal(SIGINT, signal_handler);
+ signal(SIGTERM, signal_handler);
+
/* Get the $DISPLAY FD */
launchd_fd = launchd_display_fd();
@@ -258,6 +266,9 @@ int main(int argc, char **argv, char **envp) {
}
}
+ /* Get X11.app's pid */
+ request_pid(mp, &x11app_pid);
+
/* Handoff the $DISPLAY FD */
if(launchd_fd != -1) {
size_t try, try_max;
@@ -308,9 +319,4 @@ int main(int argc, char **argv, char **envp) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
-#else
- set_x11_path();
- argv[0] = x11_path;
- return execvp(x11_path, argv);
-#endif
}