XQuartz: Some fd handoff cleanup.
(cherry picked from commit 9c20a4804d
)
This commit is contained in:
parent
7bfdc4bd34
commit
73f41f38c5
|
@ -202,6 +202,12 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
|
|||
for_appkit = YES;
|
||||
for_x = YES;
|
||||
|
||||
// fprintf(stderr, "fd_add_count: %d\n", fd_add_count);
|
||||
if(fd_add_count) {
|
||||
DarwinProcessFDAdditionQueue();
|
||||
fprintf(stderr, "ran it - fd_add_count: %d\n", fd_add_count);
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case NSLeftMouseDown: case NSRightMouseDown: case NSOtherMouseDown:
|
||||
case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp:
|
||||
|
|
|
@ -79,6 +79,11 @@ void QuartzModeEQInit(void);
|
|||
|
||||
static int old_flags = 0; // last known modifier state
|
||||
|
||||
#define FD_ADD_MAX 128
|
||||
static int fd_add[FD_ADD_MAX];
|
||||
int fd_add_count = 0;
|
||||
static pthread_mutex_t fd_add_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static xEvent *darwinEvents = NULL;
|
||||
|
||||
static pthread_mutex_t mieq_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
@ -232,15 +237,6 @@ static void DarwinSimulateMouseClick(
|
|||
DarwinUpdateModifiers(KeyPress, modifierMask);
|
||||
}
|
||||
|
||||
static void kXquartzListenOnOpenFDHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, int nevents) {
|
||||
size_t i;
|
||||
TA_SERVER();
|
||||
|
||||
for (i=0; i<nevents; i++) {
|
||||
ListenOnOpenFD(xe[i].u.clientMessage.u.l.longs0);
|
||||
}
|
||||
}
|
||||
|
||||
/* Generic handler for Xquartz-specifc events. When possible, these should
|
||||
be moved into their own individual functions and set as handlers using
|
||||
mieqSetHandler. */
|
||||
|
@ -249,7 +245,7 @@ static void DarwinEventHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, in
|
|||
int i;
|
||||
|
||||
TA_SERVER();
|
||||
|
||||
|
||||
DEBUG_LOG("DarwinEventHandler(%d, %p, %p, %d)\n", screenNum, xe, dev, nevents);
|
||||
for (i=0; i<nevents; i++) {
|
||||
switch(xe[i].u.u.type) {
|
||||
|
@ -331,6 +327,35 @@ static void DarwinEventHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, in
|
|||
}
|
||||
}
|
||||
|
||||
void DarwinListenOnOpenFD(int fd) {
|
||||
ErrorF("DarwinListenOnOpenFD: %d\n", fd);
|
||||
|
||||
pthread_mutex_lock(&fd_add_lock);
|
||||
if(fd_add_count < FD_ADD_MAX)
|
||||
fd_add[fd_add_count++] = fd;
|
||||
else
|
||||
ErrorF("FD Addition buffer at max. Dropping fd addition request.\n");
|
||||
|
||||
pthread_mutex_unlock(&fd_add_lock);
|
||||
}
|
||||
|
||||
void DarwinProcessFDAdditionQueue() {
|
||||
pthread_mutex_lock(&fd_add_lock);
|
||||
while(fd_add_count) {
|
||||
DarwinSendDDXEvent(kXquartzListenOnOpenFD, 1, fd_add[--fd_add_count]);
|
||||
}
|
||||
pthread_mutex_unlock(&fd_add_lock);
|
||||
}
|
||||
|
||||
static void kXquartzListenOnOpenFDHandler(int screenNum, xEventPtr xe, DeviceIntPtr dev, int nevents) {
|
||||
size_t i;
|
||||
TA_SERVER();
|
||||
|
||||
for (i=0; i<nevents; i++) {
|
||||
ListenOnOpenFD(xe[i].u.clientMessage.u.l.longs0);
|
||||
}
|
||||
}
|
||||
|
||||
Bool DarwinEQInit(void) {
|
||||
mieqInit();
|
||||
mieqSetHandler(kXquartzReloadKeymap, DarwinKeyboardReloadHandler);
|
||||
|
@ -576,10 +601,6 @@ void DarwinUpdateModKeys(int flags) {
|
|||
old_flags = flags;
|
||||
}
|
||||
|
||||
void DarwinListenOnOpenFD(int fd) {
|
||||
DarwinSendDDXEvent(kXquartzListenOnOpenFD, 1, fd);
|
||||
}
|
||||
|
||||
/*
|
||||
* DarwinSendDDXEvent
|
||||
* Send the X server thread a message by placing it on the event queue.
|
||||
|
|
|
@ -41,6 +41,9 @@ void DarwinSendScrollEvents(float count_x, float count_y, int pointer_x, int poi
|
|||
void DarwinUpdateModKeys(int flags);
|
||||
void DarwinListenOnOpenFD(int fd);
|
||||
|
||||
extern int fd_add_count;
|
||||
void DarwinProcessFDAdditionQueue(void);
|
||||
|
||||
/*
|
||||
* Special ddx events understood by the X server
|
||||
*/
|
||||
|
|
|
@ -57,6 +57,8 @@ extern int noPanoramiXExtension;
|
|||
#define DEFAULT_STARTX "/usr/X11/bin/startx"
|
||||
#define DEFAULT_SHELL "/bin/sh"
|
||||
|
||||
#define DEBUG 1
|
||||
|
||||
static int execute(const char *command);
|
||||
static char *command_from_prefs(const char *key, const char *default_value);
|
||||
|
||||
|
@ -198,8 +200,8 @@ static void socket_handoff_thread(void *arg) {
|
|||
servaddr_len = sizeof(struct sockaddr_un) - sizeof(servaddr_un.sun_path) + strlen(filename);
|
||||
|
||||
handoff_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if(handoff_fd == 0) {
|
||||
fprintf(stderr, "Failed to create socket: %s - %s\n", filename, strerror(errno));
|
||||
if(handoff_fd == -1) {
|
||||
fprintf(stderr, "X11.app: Failed to create socket: %d - %s\n", errno, strerror(errno));
|
||||
|
||||
data->retval = EXIT_FAILURE;
|
||||
pthread_cond_broadcast(&data->cond);
|
||||
|
@ -213,7 +215,7 @@ static void socket_handoff_thread(void *arg) {
|
|||
pthread_mutex_unlock(&data->lock);
|
||||
|
||||
if(connect(handoff_fd, servaddr, servaddr_len) < 0) {
|
||||
fprintf(stderr, "Failed to connect to socket: %s - %s\n", filename, strerror(errno));
|
||||
fprintf(stderr, "X11.app: Failed to connect to socket: %s - %d - %s\n", filename, errno, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -226,6 +228,10 @@ static void socket_handoff_thread(void *arg) {
|
|||
kern_return_t do_prep_fd_handoff(mach_port_t port, string_t socket_filename) {
|
||||
handoff_data_t handoff_data;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "X11.app: Prepping for fd handoff.\n");
|
||||
#endif
|
||||
|
||||
/* Initialize our data */
|
||||
pthread_mutex_init(&handoff_data.lock, NULL);
|
||||
pthread_cond_init(&handoff_data.cond, NULL);
|
||||
|
@ -235,6 +241,10 @@ kern_return_t do_prep_fd_handoff(mach_port_t port, string_t socket_filename) {
|
|||
|
||||
create_thread(socket_handoff_thread, &handoff_data);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "X11.app: Thread created for handoff. Waiting on return value.\n");
|
||||
#endif
|
||||
|
||||
/* Wait for our return value */
|
||||
pthread_cond_wait(&handoff_data.cond, &handoff_data.lock);
|
||||
pthread_mutex_unlock(&handoff_data.lock);
|
||||
|
@ -242,6 +252,10 @@ kern_return_t do_prep_fd_handoff(mach_port_t port, string_t socket_filename) {
|
|||
/* Cleanup */
|
||||
pthread_cond_destroy(&handoff_data.cond);
|
||||
pthread_mutex_destroy(&handoff_data.lock);
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "X11.app: Sending return value: %d\n", handoff_data.retval);
|
||||
#endif
|
||||
|
||||
return handoff_data.retval;
|
||||
}
|
||||
|
|
|
@ -57,6 +57,8 @@
|
|||
#define XSERVER_VERSION "?"
|
||||
#endif
|
||||
|
||||
#define DEBUG 1
|
||||
|
||||
static char x11_path[PATH_MAX + 1];
|
||||
|
||||
static void set_x11_path() {
|
||||
|
@ -132,23 +134,27 @@ static int create_socket(char *filename_out) {
|
|||
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 == 0) {
|
||||
fprintf(stderr, "Failed to create socket (try %d / %d): %s - %s\n", (int)try+1, (int)try_max, filename_out, strerror(errno));
|
||||
if(ret_fd == -1) {
|
||||
fprintf(stderr, "Xquartz: 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) {
|
||||
fprintf(stderr, "Failed to bind socket: %s - %s\n", filename_out, strerror(errno));
|
||||
fprintf(stderr, "Xquartz: Failed to bind socket: %d - %s\n", errno, strerror(errno));
|
||||
close(ret_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(listen(ret_fd, 10) != 0) {
|
||||
fprintf(stderr, "Failed to listen to socket: %s - %s\n", filename_out, strerror(errno));
|
||||
fprintf(stderr, "Xquartz: Failed to listen to socket: %s - %d - %s\n", filename_out, errno, strerror(errno));
|
||||
close(ret_fd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Xquartz: Listening on socket for fd handoff: %s\n", filename_out);
|
||||
#endif
|
||||
|
||||
return ret_fd;
|
||||
}
|
||||
|
||||
|
@ -186,19 +192,30 @@ static void send_fd_handoff(int handoff_fd, int launchd_fd) {
|
|||
|
||||
*((int*)CMSG_DATA(cmsg)) = launchd_fd;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Xquartz: Waiting for fd handoff connection.\n");
|
||||
#endif
|
||||
connected_fd = accept(handoff_fd, NULL, NULL);
|
||||
if(connected_fd == -1) {
|
||||
fprintf(stderr, "Failed to accept incoming connection on socket: %s\n", strerror(errno));
|
||||
fprintf(stderr, "Xquartz: Failed to accept incoming connection on socket: %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Xquartz: Handoff connection established. Sending message.\n");
|
||||
#endif
|
||||
if(sendmsg(connected_fd, &msg, 0) < 0) {
|
||||
fprintf(stderr, "Error sending $DISPLAY file descriptor: %s\n", strerror(errno));
|
||||
fprintf(stderr, "Xquartz: Error sending $DISPLAY file descriptor: %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Xquartz: Message sent. Closing.\n");
|
||||
#endif
|
||||
close(connected_fd);
|
||||
fprintf(stderr, "send %d %d %d %s\n", handoff_fd, launchd_fd, errno, strerror(errno));
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Xquartz: end of send debug: %d %d %d %s\n", handoff_fd, launchd_fd, errno, strerror(errno));
|
||||
#endif
|
||||
}
|
||||
|
||||
int main(int argc, char **argv, char **envp) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user