diff options
author | marha <marha@users.sourceforge.net> | 2011-05-23 12:38:03 +0000 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2011-05-23 12:38:03 +0000 |
commit | 98a78a31883c4b5d63dd1465b4208bcc7c12bfcb (patch) | |
tree | fdb125ad89bd8b0fae5c3580558989367f666f2b | |
parent | 215417a52a66f9a2252c64f24e417297eba2331f (diff) | |
parent | ae87f2594b9439cb63a6b52e42e09504b687aea3 (diff) | |
download | vcxsrv-98a78a31883c4b5d63dd1465b4208bcc7c12bfcb.tar.gz vcxsrv-98a78a31883c4b5d63dd1465b4208bcc7c12bfcb.tar.bz2 vcxsrv-98a78a31883c4b5d63dd1465b4208bcc7c12bfcb.zip |
merge ^/branches/released .
-rw-r--r-- | xorg-server/dix/main.c | 25 | ||||
-rw-r--r-- | xorg-server/hw/xquartz/X11Application.m | 6 | ||||
-rw-r--r-- | xorg-server/hw/xquartz/console_redirect.c | 836 | ||||
-rw-r--r-- | xorg-server/hw/xquartz/darwin.c | 33 | ||||
-rw-r--r-- | xorg-server/hw/xquartz/darwin.h | 15 | ||||
-rw-r--r-- | xorg-server/hw/xquartz/mach-startup/bundle-main.c | 5 | ||||
-rw-r--r-- | xorg-server/hw/xquartz/mach-startup/stub.c | 1 | ||||
-rw-r--r-- | xorg-server/hw/xquartz/man/Xquartz.man | 6 | ||||
-rw-r--r-- | xorg-server/hw/xquartz/pbproxy/app-main.m | 6 | ||||
-rw-r--r-- | xorg-server/hw/xquartz/pbproxy/main.m | 16 | ||||
-rw-r--r-- | xorg-server/hw/xquartz/quartz.c | 15 | ||||
-rw-r--r-- | xorg-server/hw/xquartz/quartzRandR.c | 219 | ||||
-rw-r--r-- | xorg-server/hw/xquartz/quartzStartup.c | 1 | ||||
-rw-r--r-- | xorg-server/hw/xquartz/xpr/xprScreen.c | 3 | ||||
-rw-r--r-- | xorg-server/mi/mieq.c | 16 |
15 files changed, 627 insertions, 576 deletions
diff --git a/xorg-server/dix/main.c b/xorg-server/dix/main.c index 0be753742..542f2607a 100644 --- a/xorg-server/dix/main.c +++ b/xorg-server/dix/main.c @@ -125,9 +125,9 @@ extern void Dispatch(void); #ifdef XQUARTZ
#include <pthread.h>
-BOOL serverInitComplete = FALSE;
-pthread_mutex_t serverInitCompleteMutex = PTHREAD_MUTEX_INITIALIZER;
-pthread_cond_t serverInitCompleteCond = PTHREAD_COND_INITIALIZER;
+BOOL serverRunning = FALSE;
+pthread_mutex_t serverRunningMutex = PTHREAD_MUTEX_INITIALIZER;
+pthread_cond_t serverRunningCond = PTHREAD_COND_INITIALIZER;
int dix_main(int argc, char *argv[], char *envp[]);
@@ -321,11 +321,11 @@ int main(int argc, char *argv[], char *envp[]) }
#ifdef XQUARTZ
- /* Let the other threads know the server is done with its init */
- pthread_mutex_lock(&serverInitCompleteMutex);
- serverInitComplete = TRUE;
- pthread_cond_broadcast(&serverInitCompleteCond);
- pthread_mutex_unlock(&serverInitCompleteMutex);
+ /* Let the other threads know the server is done with its init */
+ pthread_mutex_lock(&serverRunningMutex);
+ serverRunning = TRUE;
+ pthread_cond_broadcast(&serverRunningCond);
+ pthread_mutex_unlock(&serverRunningMutex);
#endif
NotifyParentProcess();
@@ -337,7 +337,14 @@ int main(int argc, char *argv[], char *envp[]) Dispatch();
- UndisplayDevices();
+#ifdef XQUARTZ
+ /* Let the other threads know the server is no longer running */
+ pthread_mutex_lock(&serverRunningMutex);
+ serverRunning = FALSE;
+ pthread_mutex_unlock(&serverRunningMutex);
+#endif
+
+ UndisplayDevices();
/* Now free up whatever must be freed */
if (screenIsSaved == SCREEN_SAVER_ON)
diff --git a/xorg-server/hw/xquartz/X11Application.m b/xorg-server/hw/xquartz/X11Application.m index 3d845d914..f9928345f 100644 --- a/xorg-server/hw/xquartz/X11Application.m +++ b/xorg-server/hw/xquartz/X11Application.m @@ -1269,7 +1269,7 @@ static const char *untrusted_str(NSEvent *e) { #if defined(XPLUGIN_VERSION) && XPLUGIN_VERSION > 0
/* Older libXplugin (Tiger/"Stock" Leopard) aren't thread safe, so we can't call xp_find_window from the Appkit thread */
xp_window_id wid = 0;
- xp_error e;
+ xp_error err;
/* Sigh. Need to check that we're really over one of
* our windows. (We need to receive pointer events while
@@ -1277,9 +1277,9 @@ static const char *untrusted_str(NSEvent *e) { * when another window is over us or we might show a tooltip)
*/
- e = xp_find_window(location.x, location.y, 0, &wid);
+ err = xp_find_window(location.x, location.y, 0, &wid);
- if (e != XP_Success || (e == XP_Success && wid == 0))
+ if (err != XP_Success || (err == XP_Success && wid == 0))
#endif
{
bgMouseLocation = location;
diff --git a/xorg-server/hw/xquartz/console_redirect.c b/xorg-server/hw/xquartz/console_redirect.c index cdd2b8960..f7b95df2b 100644 --- a/xorg-server/hw/xquartz/console_redirect.c +++ b/xorg-server/hw/xquartz/console_redirect.c @@ -1,418 +1,418 @@ -/* Copyright (c) 2011 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. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#else -#define DEBUG_CONSOLE_REDIRECT 1 -#define HAVE_LIBDISPATCH 1 -#endif - -#include <assert.h> -#include <unistd.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <sys/types.h> -#include <sys/event.h> -#include <asl.h> -#include <errno.h> -#include <fcntl.h> - -#include "console_redirect.h" - -#define BUF_SIZE 512 - -#ifdef HAVE_LIBDISPATCH -#include <dispatch/dispatch.h> - -static dispatch_queue_t redirect_serial_q; -static dispatch_group_t read_source_group; -#else -#include <pthread.h> - -static pthread_t redirect_pthread; -static pthread_mutex_t redirect_fds_lock = PTHREAD_MUTEX_INITIALIZER; - -static int kq; - -/* Notifications to our reader thread */ -#define ASL_REDIRECT_TERMINATE ((void *)(uintptr_t)1) -#endif - -typedef struct { - int level; - aslclient asl; - aslmsg msg; - - /* Buffered reading */ - char *buf; - char *w; - -#ifdef HAVE_LIBDISPATCH - dispatch_source_t read_source; -#endif -} asl_redirect; - -static asl_redirect *redirect_fds = NULL; -static int n_redirect_fds = 0; - -/* Read from the FD until there is no more to read and redirect to ASL. - * Preconditions: - * 1: pthread_mutex_lock lock is held (pthreads) or called - * from the appropriate serial queue for operating on - * redirect_fds - * 2: fd corresponds to a valid entry in redirect_fds - * - * Return values: - * If the pipe is closed, EOF is returned regardless of how many bytes - * were processed. If the pipe is still open, the number of read bytes - * is returned. - */ -static inline int _read_redirect(int fd, int flush) { - int total_read = 0; - int nbytes; - asl_redirect *aslr = &redirect_fds[fd]; - - while((nbytes = read(fd, aslr->w, BUF_SIZE - (aslr->w - aslr->buf) - 1)) > 0) { - char *s, *p; - - /* Increment our returned number read */ - total_read += nbytes; - - nbytes += (aslr->w - aslr->buf); - aslr->buf[nbytes] = '\0'; - - /* One line at a time */ - for(p=aslr->buf; *p && (p - aslr->buf) < nbytes; p = s + 1) { - // Find null or \n - for(s=p; *s && *s != '\n'; s++); - if(*s == '\n') { - *s='\0'; - asl_log(aslr->asl, aslr->msg, aslr->level, "%s", p); - } else if(aslr->buf != p) { - memmove(aslr->buf, p, BUF_SIZE); - aslr->w = aslr->buf + (s - p); - break; - } else if(nbytes == BUF_SIZE - 1) { - asl_log(aslr->asl, aslr->msg, aslr->level, "%s", p); - aslr->w = aslr->buf; - break; - } - } - } - - /* Flush if requested or we're at EOF */ - if(flush || nbytes == 0) { - if(aslr->w > aslr->buf) { - *aslr->w = '\0'; - asl_log(aslr->asl, aslr->msg, aslr->level, "%s", aslr->buf); - } - } - - if(nbytes == 0) - return EOF; - return total_read; -} - -#ifdef HAVE_LIBDISPATCH -static void read_from_source(void *_source) { - dispatch_source_t source = (dispatch_source_t)_source; - int fd = dispatch_source_get_handle(source); - if(_read_redirect(fd, 0) == EOF) { - dispatch_source_cancel(source); - } -} - -static void cancel_source(void *_source) { - dispatch_source_t source = (dispatch_source_t)_source; - int fd = dispatch_source_get_handle(source); - asl_redirect *aslr = &redirect_fds[fd]; - - /* Flush the buffer */ - _read_redirect(fd, 1); - - close(fd); - free(aslr->buf); - memset(aslr, 0, sizeof(*aslr)); - dispatch_release(source); - dispatch_group_leave(read_source_group); -} - -#else /* !HAVE_LIBDISPATCH */ -static void *redirect_thread(void *ctx __unused) { - struct kevent ev; - int n; - - while(1) { - n = kevent(kq, NULL, 0, &ev, 1, NULL); - - /* Bail on errors */ - if(n < 0) { - asl_log(NULL, NULL, ASL_LEVEL_ERR, "kevent failure: %s", strerror(errno)); - break; - } - - /* This should not happen */ - if(n == 0) - continue; - - switch(ev.filter) { - case EVFILT_READ: - pthread_mutex_lock(&redirect_fds_lock); - { - int fd = ev.ident; - int close_fd = 0; - asl_redirect *aslr = &redirect_fds[fd]; - - if(fd < 0 || fd >= n_redirect_fds || aslr->buf == NULL) { - asl_log(NULL, NULL, ASL_LEVEL_ERR, "Unexpected file descriptor: %d", fd); - goto next; - } - - if(ev.flags & EV_EOF) { - close_fd = 1; - if(EOF != _read_redirect(fd, 1)) { - asl_log(NULL, NULL, ASL_LEVEL_ERR, "kevent reported EOF on %d, but read doesn't concur.", fd); - } - } else { - close_fd = (EOF == _read_redirect(fd, 0)); - } - - if(close_fd) { - EV_SET(&ev, fd, EVFILT_READ, EV_DELETE, 0, 0, 0); - kevent(kq, &ev, 1, NULL, 0, NULL); - close(fd); - free(aslr->buf); - memset(aslr, 0, sizeof(*aslr)); - } - } - next: - pthread_mutex_unlock(&redirect_fds_lock); - - case EVFILT_TIMER: - if(ev.udata == ASL_REDIRECT_TERMINATE) - return NULL; - - default: - ;; - } - } - - return NULL; -} -#endif - -static void redirect_atexit(void) { - /* stdout is linebuffered, so flush the buffer */ - if(redirect_fds[STDOUT_FILENO].buf) - fflush(stdout); - -#ifdef HAVE_LIBDISPATCH - { - int i; - - /* Cancel all of our dispatch sources, so they flush to ASL */ - for(i=0; i < n_redirect_fds; i++) - if(redirect_fds[i].read_source) - dispatch_source_cancel(redirect_fds[i].read_source); - - /* Wait at least three seconds for our sources to flush to ASL */ - dispatch_group_wait(read_source_group, dispatch_time(DISPATCH_TIME_NOW, 3LL * NSEC_PER_SEC)); - } -#else - { - struct kevent ev; - - /* Tell our reader thread it is time to pack up and go home */ - EV_SET(&ev, 0, EVFILT_TIMER, EV_ADD | EV_ONESHOT, 0, 0, ASL_REDIRECT_TERMINATE); - kevent(kq, &ev, 1, NULL, 0, NULL); - - pthread_join(redirect_pthread, NULL); - } -#endif -} - -#ifdef HAVE_LIBDISPATCH -static void xq_asl_init(void *ctx __unused) -#else -static void xq_asl_init(void) -#endif -{ - assert((redirect_fds = calloc(16, sizeof(*redirect_fds))) != NULL); - n_redirect_fds = 16; - -#ifdef HAVE_LIBDISPATCH - redirect_serial_q = dispatch_queue_create("com.apple.asl-redirect", NULL); - assert(redirect_serial_q != NULL); - - read_source_group = dispatch_group_create(); - assert(read_source_group != NULL); -#else - assert((kq = kqueue()) != -1); - assert(pthread_create(&redirect_pthread, NULL, redirect_thread, NULL) == 0); -#endif - - atexit(redirect_atexit); -} - -int xq_asl_log_fd(aslclient asl, aslmsg msg, int level, int fd) { -#ifdef HAVE_LIBDISPATCH - int err __block = 0; - static dispatch_once_t once_control; - dispatch_once_f(&once_control, NULL, xq_asl_init); -#else - int err = 0; - static pthread_once_t once_control = PTHREAD_ONCE_INIT; - assert(pthread_once(&once_control, xq_asl_init) == 0); -#endif - - if(fd < 0) - return EBADF; - -#ifdef HAVE_LIBDISPATCH -#define BLOCK_DONE return - dispatch_sync(redirect_serial_q, ^ -#else -#define BLOCK_DONE goto done - assert(pthread_mutex_lock(&redirect_fds_lock) == 0); -#endif - { - /* Reallocate if we need more space */ - if(fd >= n_redirect_fds) { - size_t new_n = 1 << (ffs(fd) + 1); - asl_redirect *new_array = realloc(redirect_fds, new_n * sizeof(*redirect_fds)); - if(!new_array) { - err = errno; - BLOCK_DONE; - } - redirect_fds = new_array; - memset(redirect_fds + n_redirect_fds, 0, new_n - n_redirect_fds); - n_redirect_fds = new_n; - } - - /* If we're already listening on it, return error. */ - if(redirect_fds[fd].buf != NULL) { - err = EBADF; - BLOCK_DONE; - } - - /* Initialize our buffer */ - redirect_fds[fd].buf = (char *)malloc(BUF_SIZE); - if(redirect_fds[fd].buf == NULL) { - err = errno; - BLOCK_DONE; - } - redirect_fds[fd].w = redirect_fds[fd].buf; - - /* Store our ASL settings */ - redirect_fds[fd].level = level; - redirect_fds[fd].asl = asl; - redirect_fds[fd].msg = msg; - - /* Don't block on reads from this fd */ - fcntl(fd, F_SETFL, O_NONBLOCK); - - /* Start listening */ -#ifdef HAVE_LIBDISPATCH - { - dispatch_source_t read_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, fd, 0, redirect_serial_q); - redirect_fds[fd].read_source = read_source; - dispatch_set_context(read_source, read_source); - dispatch_source_set_event_handler_f(read_source, read_from_source); - dispatch_source_set_cancel_handler_f(read_source, cancel_source); - dispatch_group_enter(read_source_group); - dispatch_resume(read_source); - } -#else - { - struct kevent ev; - EV_SET(&ev, fd, EVFILT_READ, EV_ADD, 0, 0, 0); - kevent(kq, &ev, 1, NULL, 0, NULL); - } -#endif - } -#ifdef HAVE_LIBDISPATCH - ); -#else -done: - assert(pthread_mutex_unlock(&redirect_fds_lock) == 0); -#endif -#undef BLOCK_DONE - - return err; -} - -int xq_asl_capture_fd(aslclient asl, aslmsg msg, int level, int fd) { - int pipepair[2]; - - /* Create pipe */ - if(pipe(pipepair) == -1) - return errno; - - /* Close the read fd but not the write fd on exec */ - if(fcntl(pipepair[0], F_SETFD, FD_CLOEXEC) == -1) - return errno; - - /* Replace the existing fd */ - if(dup2(pipepair[1], fd) == -1) { - close(pipepair[0]); - close(pipepair[1]); - return errno; - } - - /* If we capture STDOUT_FILENO, make sure we linebuffer stdout */ - if(fd == STDOUT_FILENO) - setlinebuf(stdout); - - /* Close the duplicate fds since they've been reassigned */ - close(pipepair[1]); - - /* Hand off the read end of our pipe to xq_asl_log_fd */ - return xq_asl_log_fd(asl, msg, level, pipepair[0]); -} - -#ifdef DEBUG_CONSOLE_REDIRECT -int main(int argc __unused, char **argv __unused) { - xq_asl_capture_fd(NULL, NULL, ASL_LEVEL_NOTICE, STDOUT_FILENO); - xq_asl_capture_fd(NULL, NULL, ASL_LEVEL_ERR, STDERR_FILENO); - - fprintf(stderr, "TEST ERR1\n"); - fprintf(stdout, "TEST OUT1\n"); - fprintf(stderr, "TEST ERR2\n"); - fprintf(stdout, "TEST OUT2\n"); - system("/bin/echo SYST OUT"); - system("/bin/echo SYST ERR >&2"); - fprintf(stdout, "TEST OUT3\n"); - fprintf(stdout, "TEST OUT4\n"); - fprintf(stderr, "TEST ERR3\n"); - fprintf(stderr, "TEST ERR4\n"); - - exit(0); -} -#endif +/* Copyright (c) 2011 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.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#else
+#define DEBUG_CONSOLE_REDIRECT 1
+#define HAVE_LIBDISPATCH 1
+#endif
+
+#include <assert.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/event.h>
+#include <asl.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include "console_redirect.h"
+
+#define BUF_SIZE 512
+
+#ifdef HAVE_LIBDISPATCH
+#include <dispatch/dispatch.h>
+
+static dispatch_queue_t redirect_serial_q;
+static dispatch_group_t read_source_group;
+#else
+#include <pthread.h>
+
+static pthread_t redirect_pthread;
+static pthread_mutex_t redirect_fds_lock = PTHREAD_MUTEX_INITIALIZER;
+
+static int kq;
+
+/* Notifications to our reader thread */
+#define ASL_REDIRECT_TERMINATE ((void *)(uintptr_t)1)
+#endif
+
+typedef struct {
+ int level;
+ aslclient asl;
+ aslmsg msg;
+
+ /* Buffered reading */
+ char *buf;
+ char *w;
+
+#ifdef HAVE_LIBDISPATCH
+ dispatch_source_t read_source;
+#endif
+} asl_redirect;
+
+static asl_redirect *redirect_fds = NULL;
+static int n_redirect_fds = 0;
+
+/* Read from the FD until there is no more to read and redirect to ASL.
+ * Preconditions:
+ * 1: pthread_mutex_lock lock is held (pthreads) or called
+ * from the appropriate serial queue for operating on
+ * redirect_fds
+ * 2: fd corresponds to a valid entry in redirect_fds
+ *
+ * Return values:
+ * If the pipe is closed, EOF is returned regardless of how many bytes
+ * were processed. If the pipe is still open, the number of read bytes
+ * is returned.
+ */
+static inline int _read_redirect(int fd, int flush) {
+ int total_read = 0;
+ int nbytes;
+ asl_redirect *aslr = &redirect_fds[fd];
+
+ while((nbytes = read(fd, aslr->w, BUF_SIZE - (aslr->w - aslr->buf) - 1)) > 0) {
+ char *s, *p;
+
+ /* Increment our returned number read */
+ total_read += nbytes;
+
+ nbytes += (aslr->w - aslr->buf);
+ aslr->buf[nbytes] = '\0';
+
+ /* One line at a time */
+ for(p=aslr->buf; *p && (p - aslr->buf) < nbytes; p = s + 1) {
+ // Find null or \n
+ for(s=p; *s && *s != '\n'; s++);
+ if(*s == '\n') {
+ *s='\0';
+ asl_log(aslr->asl, aslr->msg, aslr->level, "%s", p);
+ } else if(aslr->buf != p) {
+ memmove(aslr->buf, p, BUF_SIZE - (p - aslr->buf));
+ aslr->w = aslr->buf + (s - p);
+ break;
+ } else if(nbytes == BUF_SIZE - 1) {
+ asl_log(aslr->asl, aslr->msg, aslr->level, "%s", p);
+ aslr->w = aslr->buf;
+ break;
+ }
+ }
+ }
+
+ /* Flush if requested or we're at EOF */
+ if(flush || nbytes == 0) {
+ if(aslr->w > aslr->buf) {
+ *aslr->w = '\0';
+ asl_log(aslr->asl, aslr->msg, aslr->level, "%s", aslr->buf);
+ }
+ }
+
+ if(nbytes == 0)
+ return EOF;
+ return total_read;
+}
+
+#ifdef HAVE_LIBDISPATCH
+static void read_from_source(void *_source) {
+ dispatch_source_t source = (dispatch_source_t)_source;
+ int fd = dispatch_source_get_handle(source);
+ if(_read_redirect(fd, 0) == EOF) {
+ dispatch_source_cancel(source);
+ }
+}
+
+static void cancel_source(void *_source) {
+ dispatch_source_t source = (dispatch_source_t)_source;
+ int fd = dispatch_source_get_handle(source);
+ asl_redirect *aslr = &redirect_fds[fd];
+
+ /* Flush the buffer */
+ _read_redirect(fd, 1);
+
+ close(fd);
+ free(aslr->buf);
+ memset(aslr, 0, sizeof(*aslr));
+ dispatch_release(source);
+ dispatch_group_leave(read_source_group);
+}
+
+#else /* !HAVE_LIBDISPATCH */
+static void *redirect_thread(void *ctx __unused) {
+ struct kevent ev;
+ int n;
+
+ while(1) {
+ n = kevent(kq, NULL, 0, &ev, 1, NULL);
+
+ /* Bail on errors */
+ if(n < 0) {
+ asl_log(NULL, NULL, ASL_LEVEL_ERR, "kevent failure: %s", strerror(errno));
+ break;
+ }
+
+ /* This should not happen */
+ if(n == 0)
+ continue;
+
+ switch(ev.filter) {
+ case EVFILT_READ:
+ pthread_mutex_lock(&redirect_fds_lock);
+ {
+ int fd = ev.ident;
+ int close_fd = 0;
+ asl_redirect *aslr = &redirect_fds[fd];
+
+ if(fd < 0 || fd >= n_redirect_fds || aslr->buf == NULL) {
+ asl_log(NULL, NULL, ASL_LEVEL_ERR, "Unexpected file descriptor: %d", fd);
+ goto next;
+ }
+
+ if(ev.flags & EV_EOF) {
+ close_fd = 1;
+ if(EOF != _read_redirect(fd, 1)) {
+ asl_log(NULL, NULL, ASL_LEVEL_ERR, "kevent reported EOF on %d, but read doesn't concur.", fd);
+ }
+ } else {
+ close_fd = (EOF == _read_redirect(fd, 0));
+ }
+
+ if(close_fd) {
+ EV_SET(&ev, fd, EVFILT_READ, EV_DELETE, 0, 0, 0);
+ kevent(kq, &ev, 1, NULL, 0, NULL);
+ close(fd);
+ free(aslr->buf);
+ memset(aslr, 0, sizeof(*aslr));
+ }
+ }
+ next:
+ pthread_mutex_unlock(&redirect_fds_lock);
+
+ case EVFILT_TIMER:
+ if(ev.udata == ASL_REDIRECT_TERMINATE)
+ return NULL;
+
+ default:
+ ;;
+ }
+ }
+
+ return NULL;
+}
+#endif
+
+static void redirect_atexit(void) {
+ /* stdout is linebuffered, so flush the buffer */
+ if(redirect_fds[STDOUT_FILENO].buf)
+ fflush(stdout);
+
+#ifdef HAVE_LIBDISPATCH
+ {
+ int i;
+
+ /* Cancel all of our dispatch sources, so they flush to ASL */
+ for(i=0; i < n_redirect_fds; i++)
+ if(redirect_fds[i].read_source)
+ dispatch_source_cancel(redirect_fds[i].read_source);
+
+ /* Wait at least three seconds for our sources to flush to ASL */
+ dispatch_group_wait(read_source_group, dispatch_time(DISPATCH_TIME_NOW, 3LL * NSEC_PER_SEC));
+ }
+#else
+ {
+ struct kevent ev;
+
+ /* Tell our reader thread it is time to pack up and go home */
+ EV_SET(&ev, 0, EVFILT_TIMER, EV_ADD | EV_ONESHOT, 0, 0, ASL_REDIRECT_TERMINATE);
+ kevent(kq, &ev, 1, NULL, 0, NULL);
+
+ pthread_join(redirect_pthread, NULL);
+ }
+#endif
+}
+
+#ifdef HAVE_LIBDISPATCH
+static void xq_asl_init(void *ctx __unused)
+#else
+static void xq_asl_init(void)
+#endif
+{
+ assert((redirect_fds = calloc(16, sizeof(*redirect_fds))) != NULL);
+ n_redirect_fds = 16;
+
+#ifdef HAVE_LIBDISPATCH
+ redirect_serial_q = dispatch_queue_create("com.apple.asl-redirect", NULL);
+ assert(redirect_serial_q != NULL);
+
+ read_source_group = dispatch_group_create();
+ assert(read_source_group != NULL);
+#else
+ assert((kq = kqueue()) != -1);
+ assert(pthread_create(&redirect_pthread, NULL, redirect_thread, NULL) == 0);
+#endif
+
+ atexit(redirect_atexit);
+}
+
+int xq_asl_log_fd(aslclient asl, aslmsg msg, int level, int fd) {
+#ifdef HAVE_LIBDISPATCH
+ int err __block = 0;
+ static dispatch_once_t once_control;
+ dispatch_once_f(&once_control, NULL, xq_asl_init);
+#else
+ int err = 0;
+ static pthread_once_t once_control = PTHREAD_ONCE_INIT;
+ assert(pthread_once(&once_control, xq_asl_init) == 0);
+#endif
+
+ if(fd < 0)
+ return EBADF;
+
+#ifdef HAVE_LIBDISPATCH
+#define BLOCK_DONE return
+ dispatch_sync(redirect_serial_q, ^
+#else
+#define BLOCK_DONE goto done
+ assert(pthread_mutex_lock(&redirect_fds_lock) == 0);
+#endif
+ {
+ /* Reallocate if we need more space */
+ if(fd >= n_redirect_fds) {
+ size_t new_n = 1 << (ffs(fd) + 1);
+ asl_redirect *new_array = realloc(redirect_fds, new_n * sizeof(*redirect_fds));
+ if(!new_array) {
+ err = errno;
+ BLOCK_DONE;
+ }
+ redirect_fds = new_array;
+ memset(redirect_fds + n_redirect_fds, 0, new_n - n_redirect_fds);
+ n_redirect_fds = new_n;
+ }
+
+ /* If we're already listening on it, return error. */
+ if(redirect_fds[fd].buf != NULL) {
+ err = EBADF;
+ BLOCK_DONE;
+ }
+
+ /* Initialize our buffer */
+ redirect_fds[fd].buf = (char *)malloc(BUF_SIZE);
+ if(redirect_fds[fd].buf == NULL) {
+ err = errno;
+ BLOCK_DONE;
+ }
+ redirect_fds[fd].w = redirect_fds[fd].buf;
+
+ /* Store our ASL settings */
+ redirect_fds[fd].level = level;
+ redirect_fds[fd].asl = asl;
+ redirect_fds[fd].msg = msg;
+
+ /* Don't block on reads from this fd */
+ fcntl(fd, F_SETFL, O_NONBLOCK);
+
+ /* Start listening */
+#ifdef HAVE_LIBDISPATCH
+ {
+ dispatch_source_t read_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, fd, 0, redirect_serial_q);
+ redirect_fds[fd].read_source = read_source;
+ dispatch_set_context(read_source, read_source);
+ dispatch_source_set_event_handler_f(read_source, read_from_source);
+ dispatch_source_set_cancel_handler_f(read_source, cancel_source);
+ dispatch_group_enter(read_source_group);
+ dispatch_resume(read_source);
+ }
+#else
+ {
+ struct kevent ev;
+ EV_SET(&ev, fd, EVFILT_READ, EV_ADD, 0, 0, 0);
+ kevent(kq, &ev, 1, NULL, 0, NULL);
+ }
+#endif
+ }
+#ifdef HAVE_LIBDISPATCH
+ );
+#else
+done:
+ assert(pthread_mutex_unlock(&redirect_fds_lock) == 0);
+#endif
+#undef BLOCK_DONE
+
+ return err;
+}
+
+int xq_asl_capture_fd(aslclient asl, aslmsg msg, int level, int fd) {
+ int pipepair[2];
+
+ /* Create pipe */
+ if(pipe(pipepair) == -1)
+ return errno;
+
+ /* Close the read fd but not the write fd on exec */
+ if(fcntl(pipepair[0], F_SETFD, FD_CLOEXEC) == -1)
+ return errno;
+
+ /* Replace the existing fd */
+ if(dup2(pipepair[1], fd) == -1) {
+ close(pipepair[0]);
+ close(pipepair[1]);
+ return errno;
+ }
+
+ /* If we capture STDOUT_FILENO, make sure we linebuffer stdout */
+ if(fd == STDOUT_FILENO)
+ setlinebuf(stdout);
+
+ /* Close the duplicate fds since they've been reassigned */
+ close(pipepair[1]);
+
+ /* Hand off the read end of our pipe to xq_asl_log_fd */
+ return xq_asl_log_fd(asl, msg, level, pipepair[0]);
+}
+
+#ifdef DEBUG_CONSOLE_REDIRECT
+int main(int argc __unused, char **argv __unused) {
+ xq_asl_capture_fd(NULL, NULL, ASL_LEVEL_NOTICE, STDOUT_FILENO);
+ xq_asl_capture_fd(NULL, NULL, ASL_LEVEL_ERR, STDERR_FILENO);
+
+ fprintf(stderr, "TEST ERR1\n");
+ fprintf(stdout, "TEST OUT1\n");
+ fprintf(stderr, "TEST ERR2\n");
+ fprintf(stdout, "TEST OUT2\n");
+ system("/bin/echo SYST OUT");
+ system("/bin/echo SYST ERR >&2");
+ fprintf(stdout, "TEST OUT3\n");
+ fprintf(stdout, "TEST OUT4\n");
+ fprintf(stderr, "TEST ERR3\n");
+ fprintf(stderr, "TEST ERR4\n");
+
+ exit(0);
+}
+#endif
diff --git a/xorg-server/hw/xquartz/darwin.c b/xorg-server/hw/xquartz/darwin.c index e12d7786b..53d590508 100644 --- a/xorg-server/hw/xquartz/darwin.c +++ b/xorg-server/hw/xquartz/darwin.c @@ -60,6 +60,7 @@ #include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
+#include <stdarg.h>
#define HAS_UTSNAME 1
#include <sys/utsname.h>
@@ -76,9 +77,31 @@ #include "quartzKeyboard.h"
#include "quartz.h"
-#ifdef ENABLE_DEBUG_LOG
-FILE *debug_log_fp = NULL;
-#endif
+aslclient aslc;
+
+void debug_asl (const char *file, const char *function, int line, const char *fmt, ...) {
+ va_list args;
+ aslmsg msg = asl_new(ASL_TYPE_MSG);
+
+ if(msg) {
+ char *_line;
+
+ asl_set(msg, "File", file);
+ asl_set(msg, "Function", function);
+ asprintf(&_line, "%d", line);
+ if(_line) {
+ asl_set(msg, "Line", _line);
+ free(_line);
+ }
+ }
+
+ va_start(args, fmt);
+ asl_vlog(aslc, msg, ASL_LEVEL_DEBUG, fmt, args);
+ va_end(args);
+
+ if(msg)
+ asl_free(msg);
+}
/*
* X server shared global variables
@@ -749,8 +772,8 @@ void ddxGiveUp( void ) * made to restore all original setting of the displays. Also all devices
* are closed.
*/
-void AbortDDX( void )
-{
+_X_NORETURN
+void AbortDDX( void ) {
ErrorF( " AbortDDX\n" );
OsAbort();
}
diff --git a/xorg-server/hw/xquartz/darwin.h b/xorg-server/hw/xquartz/darwin.h index da53a261d..e9b6efd9a 100644 --- a/xorg-server/hw/xquartz/darwin.h +++ b/xorg-server/hw/xquartz/darwin.h @@ -32,7 +32,7 @@ #include "inputstr.h"
#include "scrnintstr.h"
#include <X11/extensions/XKB.h>
-#include <assert.h>
+#include <asl.h>
#include "darwinfb.h"
@@ -76,16 +76,9 @@ extern int darwinMainScreenY; // bundle-main.c
extern char *bundle_id_prefix;
-#define ENABLE_DEBUG_LOG 1
+extern void debug_asl (const char *file, const char *function, int line, const char *fmt, ...) _X_ATTRIBUTE_PRINTF(4,5);
-#ifdef ENABLE_DEBUG_LOG
-extern FILE *debug_log_fp;
-#define DEBUG_LOG_NAME "x11-debug.txt"
-#define DEBUG_LOG(msg, args...) if (debug_log_fp) fprintf(debug_log_fp, "%s:%s:%d " msg, __FILE__, __FUNCTION__, __LINE__, ##args ); fflush(debug_log_fp);
-#else
-#define DEBUG_LOG(msg, args...)
-#endif
-
-#define TRACE() DEBUG_LOG("\n")
+#define DEBUG_LOG(msg, args...) debug_asl(__FILE__, __FUNCTION__, __LINE__, msg, ##args);
+#define TRACE() DEBUG_LOG("TRACE")
#endif /* _DARWIN_H */
diff --git a/xorg-server/hw/xquartz/mach-startup/bundle-main.c b/xorg-server/hw/xquartz/mach-startup/bundle-main.c index 1a97d78b2..323ad0907 100644 --- a/xorg-server/hw/xquartz/mach-startup/bundle-main.c +++ b/xorg-server/hw/xquartz/mach-startup/bundle-main.c @@ -66,6 +66,8 @@ /* From darwinEvents.c ... but don't want to pull in all the server cruft */
void DarwinListenOnOpenFD(int fd);
+extern aslclient aslc;
+
/* 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;
@@ -485,7 +487,6 @@ 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);
@@ -644,7 +645,7 @@ int main(int argc, char **argv, char **envp) { child2 = fork();
switch (child2) {
- int max_files, i;
+ int max_files;
case -1: /* error */
FatalError("fork() failed: %s\n", strerror(errno));
diff --git a/xorg-server/hw/xquartz/mach-startup/stub.c b/xorg-server/hw/xquartz/mach-startup/stub.c index 8122e3c91..f6dda98e9 100644 --- a/xorg-server/hw/xquartz/mach-startup/stub.c +++ b/xorg-server/hw/xquartz/mach-startup/stub.c @@ -164,6 +164,7 @@ static void send_fd_handoff(int connected_fd, int launchd_fd) { close(connected_fd);
}
+__attribute__((__noreturn__))
static void signal_handler(int sig) {
if(x11app_pid)
kill(x11app_pid, sig);
diff --git a/xorg-server/hw/xquartz/man/Xquartz.man b/xorg-server/hw/xquartz/man/Xquartz.man index 1465ec3cb..13db0823c 100644 --- a/xorg-server/hw/xquartz/man/Xquartz.man +++ b/xorg-server/hw/xquartz/man/Xquartz.man @@ -111,7 +111,11 @@ In addition to this server log, XQuartz sends messages to syslogd(8) using asl(3). These logs are sent to the __bundle_id_prefix__ facility, and you can
watch these logs using the following syslog(1) command:
.TP 8
-.B $ syslog -w -k Facility __bundle_id_prefix__
+.B $ syslog -w -k Facility eq __bundle_id_prefix__
+.PP
+or you can include extra information such as the file, line, and function where the message originated:
+.TP 8
+.B $ syslog -w -F '$(Time) $(Sender) <$(Level)> $(File):$(Line) $(Function) :: $(Message)' -k Facility eq __bundle_id_prefix__
.PP
By default, XQaurtz sets an ASL mask which prevents it from logging messages
below the ASL_LEVEL_WARNING level (meaning almost all logging is done strictly
diff --git a/xorg-server/hw/xquartz/pbproxy/app-main.m b/xorg-server/hw/xquartz/pbproxy/app-main.m index 4e61c05a3..097994555 100644 --- a/xorg-server/hw/xquartz/pbproxy/app-main.m +++ b/xorg-server/hw/xquartz/pbproxy/app-main.m @@ -39,9 +39,9 @@ CFStringRef app_prefs_domain_cfstr; /* Stubs */
char *display = NULL;
-BOOL serverInitComplete = YES;
-pthread_mutex_t serverInitCompleteMutex = PTHREAD_MUTEX_INITIALIZER;
-pthread_cond_t serverInitCompleteCond = PTHREAD_COND_INITIALIZER;
+BOOL serverRunning = YES;
+pthread_mutex_t serverRunningMutex = PTHREAD_MUTEX_INITIALIZER;
+pthread_cond_t serverRunningCond = PTHREAD_COND_INITIALIZER;
static void signal_handler (int sig) {
switch(sig) {
diff --git a/xorg-server/hw/xquartz/pbproxy/main.m b/xorg-server/hw/xquartz/pbproxy/main.m index bae23dada..f8450587e 100644 --- a/xorg-server/hw/xquartz/pbproxy/main.m +++ b/xorg-server/hw/xquartz/pbproxy/main.m @@ -47,17 +47,17 @@ BOOL xpbproxy_is_standalone = NO; x_selection *_selection_object;
-extern BOOL serverInitComplete;
-extern pthread_mutex_t serverInitCompleteMutex;
-extern pthread_cond_t serverInitCompleteCond;
+extern BOOL serverRunning;
+extern pthread_mutex_t serverRunningMutex;
+extern pthread_cond_t serverRunningCond;
static inline void wait_for_server_init(void) {
/* If the server hasn't finished initializing, wait for it... */
- if(!serverInitComplete) {
- pthread_mutex_lock(&serverInitCompleteMutex);
- while(!serverInitComplete)
- pthread_cond_wait(&serverInitCompleteCond, &serverInitCompleteMutex);
- pthread_mutex_unlock(&serverInitCompleteMutex);
+ if(!serverRunning) {
+ pthread_mutex_lock(&serverRunningMutex);
+ while(!serverRunning)
+ pthread_cond_wait(&serverRunningCond, &serverRunningMutex);
+ pthread_mutex_unlock(&serverRunningMutex);
}
}
diff --git a/xorg-server/hw/xquartz/quartz.c b/xorg-server/hw/xquartz/quartz.c index 4fdf40c89..45ea725b4 100644 --- a/xorg-server/hw/xquartz/quartz.c +++ b/xorg-server/hw/xquartz/quartz.c @@ -239,8 +239,6 @@ void QuartzUpdateScreens(void) { AppleWMSetScreenOrigin(pRoot);
pScreen->ResizeWindow(pRoot, x - sx, y - sy, width, height, NULL);
- miPaintWindow(pRoot, &pRoot->borderClip, PW_BACKGROUND);
-
/* <rdar://problem/7770779> pointer events are clipped to old display region after display reconfiguration
* http://xquartz.macosforge.org/trac/ticket/346
*/
@@ -268,6 +266,9 @@ void QuartzUpdateScreens(void) { quartzProcs->UpdateScreen(pScreen);
+ /* miPaintWindow needs to be called after RootlessUpdateScreenPixmap (from xprUpdateScreen) */
+ miPaintWindow(pRoot, &pRoot->borderClip, PW_BACKGROUND);
+
/* Tell RandR about the new size, so new connections get the correct info */
RRScreenSizeNotify(pScreen);
}
@@ -464,11 +465,15 @@ void QuartzSpaceChanged(uint32_t space_id) { void QuartzCopyDisplayIDs(ScreenPtr pScreen,
int displayCount, CGDirectDisplayID *displayIDs) {
QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
- int size = displayCount * sizeof(CGDirectDisplayID);
free(pQuartzScreen->displayIDs);
- pQuartzScreen->displayIDs = malloc(size);
- memcpy(pQuartzScreen->displayIDs, displayIDs, size);
+ if(displayCount) {
+ size_t size = displayCount * sizeof(CGDirectDisplayID);
+ pQuartzScreen->displayIDs = malloc(size);
+ memcpy(pQuartzScreen->displayIDs, displayIDs, size);
+ } else {
+ pQuartzScreen->displayIDs = NULL;
+ }
pQuartzScreen->displayCount = displayCount;
}
diff --git a/xorg-server/hw/xquartz/quartzRandR.c b/xorg-server/hw/xquartz/quartzRandR.c index 54e099c06..651352b79 100644 --- a/xorg-server/hw/xquartz/quartzRandR.c +++ b/xorg-server/hw/xquartz/quartzRandR.c @@ -3,7 +3,7 @@ *
* Copyright (c) 2001-2004 Greg Parker and Torrey T. Lyons,
* 2010 Jan Hauffa.
- * 2010 Apple Inc.
+ * 2010-2011 Apple Inc.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
@@ -124,44 +124,48 @@ static Bool QuartzRandRSetCGMode (CGDirectDisplayID screenId, static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
QuartzModeCallback callback,
void *data) {
- CFDictionaryRef curModeRef, modeRef;
- long curBpp;
- CFArrayRef modes;
- QuartzModeInfo modeInfo;
- int i;
- BOOL retval = FALSE;
+ Bool retval = FALSE;
QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
- CGDirectDisplayID screenId = pQuartzScreen->displayIDs[0];
- curModeRef = CGDisplayCurrentMode(screenId);
- if (!curModeRef)
- return FALSE;
- curBpp = getDictLong(curModeRef, kCGDisplayBitsPerPixel);
+ /* Just an 800x600 fallback if we have no attached heads */
+ if(pQuartzScreen->displayIDs) {
+ CFDictionaryRef curModeRef, modeRef;
+ long curBpp;
+ CFArrayRef modes;
+ QuartzModeInfo modeInfo;
+ int i;
+ CGDirectDisplayID screenId = pQuartzScreen->displayIDs[0];
+
+ curModeRef = CGDisplayCurrentMode(screenId);
+ if (!curModeRef)
+ return FALSE;
+ curBpp = getDictLong(curModeRef, kCGDisplayBitsPerPixel);
- modes = CGDisplayAvailableModes(screenId);
- if (!modes)
- return FALSE;
- for (i = 0; i < CFArrayGetCount(modes); i++) {
- int cb;
- modeRef = (CFDictionaryRef) CFArrayGetValueAtIndex(modes, i);
-
- /* Skip modes that are not usable on the current display or have a
- different pixel encoding than the current mode. */
- if (((unsigned long) getDictLong(modeRef, kCGDisplayIOFlags) &
- kDisplayModeUsableFlags) != kDisplayModeUsableFlags)
- continue;
- if (getDictLong(modeRef, kCGDisplayBitsPerPixel) != curBpp)
- continue;
-
- QuartzRandRGetModeInfo(modeRef, &modeInfo);
- modeInfo.ref = (void *)modeRef;
- cb = callback(pScreen, &modeInfo, data);
- if (cb == CALLBACK_CONTINUE)
- retval = TRUE;
- else if (cb == CALLBACK_SUCCESS)
- return TRUE;
- else if (cb == CALLBACK_ERROR)
+ modes = CGDisplayAvailableModes(screenId);
+ if (!modes)
return FALSE;
+ for (i = 0; i < CFArrayGetCount(modes); i++) {
+ int cb;
+ modeRef = (CFDictionaryRef) CFArrayGetValueAtIndex(modes, i);
+
+ /* Skip modes that are not usable on the current display or have a
+ different pixel encoding than the current mode. */
+ if (((unsigned long) getDictLong(modeRef, kCGDisplayIOFlags) &
+ kDisplayModeUsableFlags) != kDisplayModeUsableFlags)
+ continue;
+ if (getDictLong(modeRef, kCGDisplayBitsPerPixel) != curBpp)
+ continue;
+
+ QuartzRandRGetModeInfo(modeRef, &modeInfo);
+ modeInfo.ref = (void *)modeRef;
+ cb = callback(pScreen, &modeInfo, data);
+ if (cb == CALLBACK_CONTINUE)
+ retval = TRUE;
+ else if (cb == CALLBACK_SUCCESS)
+ return TRUE;
+ else if (cb == CALLBACK_ERROR)
+ return FALSE;
+ }
}
switch(callback(pScreen, &pQuartzScreen->rootlessMode, data)) {
@@ -225,61 +229,64 @@ static Bool QuartzRandRSetCGMode (CGDirectDisplayID screenId, static Bool QuartzRandREnumerateModes (ScreenPtr pScreen,
QuartzModeCallback callback,
void *data) {
- CGDisplayModeRef curModeRef, modeRef;
- CFStringRef curPixelEnc, pixelEnc;
- CFComparisonResult pixelEncEqual;
- CFArrayRef modes;
- QuartzModeInfo modeInfo;
- int i;
Bool retval = FALSE;
-
QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
- CGDirectDisplayID screenId = pQuartzScreen->displayIDs[0];
- curModeRef = CGDisplayCopyDisplayMode(screenId);
- if (!curModeRef)
- return FALSE;
- curPixelEnc = CGDisplayModeCopyPixelEncoding(curModeRef);
- CGDisplayModeRelease(curModeRef);
+ /* Just an 800x600 fallback if we have no attached heads */
+ if(pQuartzScreen->displayIDs) {
+ CGDisplayModeRef curModeRef, modeRef;
+ CFStringRef curPixelEnc, pixelEnc;
+ CFComparisonResult pixelEncEqual;
+ CFArrayRef modes;
+ QuartzModeInfo modeInfo;
+ int i;
+ CGDirectDisplayID screenId = pQuartzScreen->displayIDs[0];
+
+ curModeRef = CGDisplayCopyDisplayMode(screenId);
+ if (!curModeRef)
+ return FALSE;
+ curPixelEnc = CGDisplayModeCopyPixelEncoding(curModeRef);
+ CGDisplayModeRelease(curModeRef);
- modes = CGDisplayCopyAllDisplayModes(screenId, NULL);
- if (!modes) {
- CFRelease(curPixelEnc);
- return FALSE;
- }
- for (i = 0; i < CFArrayGetCount(modes); i++) {
- int cb;
- modeRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
-
- /* Skip modes that are not usable on the current display or have a
- different pixel encoding than the current mode. */
- if ((CGDisplayModeGetIOFlags(modeRef) & kDisplayModeUsableFlags) !=
- kDisplayModeUsableFlags)
- continue;
- pixelEnc = CGDisplayModeCopyPixelEncoding(modeRef);
- pixelEncEqual = CFStringCompare(pixelEnc, curPixelEnc, 0);
- CFRelease(pixelEnc);
- if (pixelEncEqual != kCFCompareEqualTo)
- continue;
-
- QuartzRandRGetModeInfo(modeRef, &modeInfo);
- modeInfo.ref = modeRef;
- cb = callback(pScreen, &modeInfo, data);
- if (cb == CALLBACK_CONTINUE) {
- retval = TRUE;
- } else if (cb == CALLBACK_SUCCESS) {
- CFRelease(modes);
- CFRelease(curPixelEnc);
- return TRUE;
- } else if (cb == CALLBACK_ERROR) {
- CFRelease(modes);
+ modes = CGDisplayCopyAllDisplayModes(screenId, NULL);
+ if (!modes) {
CFRelease(curPixelEnc);
return FALSE;
}
- }
+ for (i = 0; i < CFArrayGetCount(modes); i++) {
+ int cb;
+ modeRef = (CGDisplayModeRef) CFArrayGetValueAtIndex(modes, i);
+
+ /* Skip modes that are not usable on the current display or have a
+ different pixel encoding than the current mode. */
+ if ((CGDisplayModeGetIOFlags(modeRef) & kDisplayModeUsableFlags) !=
+ kDisplayModeUsableFlags)
+ continue;
+ pixelEnc = CGDisplayModeCopyPixelEncoding(modeRef);
+ pixelEncEqual = CFStringCompare(pixelEnc, curPixelEnc, 0);
+ CFRelease(pixelEnc);
+ if (pixelEncEqual != kCFCompareEqualTo)
+ continue;
+
+ QuartzRandRGetModeInfo(modeRef, &modeInfo);
+ modeInfo.ref = modeRef;
+ cb = callback(pScreen, &modeInfo, data);
+ if (cb == CALLBACK_CONTINUE) {
+ retval = TRUE;
+ } else if (cb == CALLBACK_SUCCESS) {
+ CFRelease(modes);
+ CFRelease(curPixelEnc);
+ return TRUE;
+ } else if (cb == CALLBACK_ERROR) {
+ CFRelease(modes);
+ CFRelease(curPixelEnc);
+ return FALSE;
+ }
+ }
- CFRelease(modes);
- CFRelease(curPixelEnc);
+ CFRelease(modes);
+ CFRelease(curPixelEnc);
+ }
switch(callback(pScreen, &pQuartzScreen->rootlessMode, data)) {
case CALLBACK_SUCCESS:
@@ -347,9 +354,13 @@ static int QuartzRandRRegisterModeCallback (ScreenPtr pScreen, static Bool QuartzRandRSetMode(ScreenPtr pScreen, QuartzModeInfoPtr pMode, BOOL doRegister) {
QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
- CGDirectDisplayID screenId = pQuartzScreen->displayIDs[0];
Bool captureDisplay = (pMode->refresh != FAKE_REFRESH_FULLSCREEN && pMode->refresh != FAKE_REFRESH_ROOTLESS);
+ CGDirectDisplayID screenId;
+
+ if(pQuartzScreen->displayIDs == NULL)
+ return FALSE;
+ screenId = pQuartzScreen->displayIDs[0];
if(XQuartzShieldingWindowLevel == 0 && captureDisplay) {
if(!X11ApplicationCanEnterRandR())
return FALSE;
@@ -379,7 +390,8 @@ static Bool QuartzRandRSetMode(ScreenPtr pScreen, QuartzModeInfoPtr pMode, BOOL if(pQuartzScreen->currentMode.ref)
CFRelease(pQuartzScreen->currentMode.ref);
pQuartzScreen->currentMode = *pMode;
- CFRetain(pQuartzScreen->currentMode.ref);
+ if(pQuartzScreen->currentMode.ref)
+ CFRetain(pQuartzScreen->currentMode.ref);
if(XQuartzShieldingWindowLevel != 0 && !captureDisplay) {
CGReleaseAllDisplays();
@@ -406,13 +418,8 @@ static int QuartzRandRSetModeCallback (ScreenPtr pScreen, }
static Bool QuartzRandRGetInfo (ScreenPtr pScreen, Rotation *rotations) {
- QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
-
*rotations = RR_Rotate_0; /* TODO: support rotation */
- if (pQuartzScreen->displayCount == 0)
- return FALSE;
-
return QuartzRandREnumerateModes(pScreen, QuartzRandRRegisterModeCallback, NULL);
}
@@ -427,9 +434,6 @@ static Bool QuartzRandRSetConfig (ScreenPtr pScreen, reqMode.height = pSize->height;
reqMode.refresh = rate;
- if (pQuartzScreen->displayCount == 0)
- return FALSE;
-
/* Do not switch modes if requested mode is equal to current mode. */
if (QuartzRandRModesEqual(&reqMode, &pQuartzScreen->currentMode))
return TRUE;
@@ -444,26 +448,36 @@ static Bool QuartzRandRSetConfig (ScreenPtr pScreen, static Bool _QuartzRandRUpdateFakeModes (ScreenPtr pScreen) {
QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
+ QuartzModeInfo activeMode;
+
+ if(pQuartzScreen->displayCount > 0) {
+ if(!QuartzRandRCopyCurrentModeInfo(pQuartzScreen->displayIDs[0], &activeMode)) {
+ ErrorF("Unable to determine current display mode.\n");
+ return FALSE;
+ }
+ } else {
+ memset(&activeMode, 0, sizeof(activeMode));
+ activeMode.width = 800;
+ activeMode.height = 600;
+ activeMode.refresh = 60;
+ }
if(pQuartzScreen->fullscreenMode.ref)
CFRelease(pQuartzScreen->fullscreenMode.ref);
if(pQuartzScreen->currentMode.ref)
CFRelease(pQuartzScreen->currentMode.ref);
-
- if (!QuartzRandRCopyCurrentModeInfo(pQuartzScreen->displayIDs[0],
- &pQuartzScreen->fullscreenMode))
- return FALSE;
- if (pQuartzScreen->displayCount > 1) {
- pQuartzScreen->fullscreenMode.width = pScreen->width;
- pQuartzScreen->fullscreenMode.height = pScreen->height;
+ if(pQuartzScreen->displayCount > 1) {
+ activeMode.width = pScreen->width;
+ activeMode.height = pScreen->height;
if(XQuartzIsRootless)
- pQuartzScreen->fullscreenMode.height += aquaMenuBarHeight;
+ activeMode.height += aquaMenuBarHeight;
}
+ pQuartzScreen->fullscreenMode = activeMode;
pQuartzScreen->fullscreenMode.refresh = FAKE_REFRESH_FULLSCREEN;
- pQuartzScreen->rootlessMode = pQuartzScreen->fullscreenMode;
+ pQuartzScreen->rootlessMode = activeMode;
pQuartzScreen->rootlessMode.refresh = FAKE_REFRESH_ROOTLESS;
pQuartzScreen->rootlessMode.height -= aquaMenuBarHeight;
@@ -476,7 +490,8 @@ static Bool _QuartzRandRUpdateFakeModes (ScreenPtr pScreen) { /* This extra retain is for currentMode's copy.
* fullscreen and rootless share a retain.
*/
- CFRetain(pQuartzScreen->currentMode.ref);
+ if(pQuartzScreen->currentMode.ref)
+ CFRetain(pQuartzScreen->currentMode.ref);
DEBUG_LOG("rootlessMode: %d x %d\n", (int)pQuartzScreen->rootlessMode.width, (int)pQuartzScreen->rootlessMode.height);
DEBUG_LOG("fullscreenMode: %d x %d\n", (int)pQuartzScreen->fullscreenMode.width, (int)pQuartzScreen->fullscreenMode.height);
diff --git a/xorg-server/hw/xquartz/quartzStartup.c b/xorg-server/hw/xquartz/quartzStartup.c index bc1aa4f68..e70194948 100644 --- a/xorg-server/hw/xquartz/quartzStartup.c +++ b/xorg-server/hw/xquartz/quartzStartup.c @@ -56,6 +56,7 @@ struct arg { char **envp;
};
+_X_NORETURN
static void server_thread (void *arg) {
struct arg args = *((struct arg *)arg);
free(arg);
diff --git a/xorg-server/hw/xquartz/xpr/xprScreen.c b/xorg-server/hw/xquartz/xpr/xprScreen.c index c8b1e45bd..d1a44ea82 100644 --- a/xorg-server/hw/xquartz/xpr/xprScreen.c +++ b/xorg-server/hw/xquartz/xpr/xprScreen.c @@ -193,6 +193,7 @@ xprAddPseudoramiXScreens(int *x, int *y, int *width, int *height, ScreenPtr pScr *width = 800;
*height = 600;
PseudoramiXAddScreen(*x, *y, *width, *height);
+ QuartzCopyDisplayIDs(pScreen, 0, NULL);
return;
}
@@ -253,7 +254,7 @@ xprDisplayInit(void) {
CGDisplayCount displayCount;
- DEBUG_LOG("");
+ TRACE();
CGGetActiveDisplayList(0, NULL, &displayCount);
diff --git a/xorg-server/mi/mieq.c b/xorg-server/mi/mieq.c index 538329827..73f814ef2 100644 --- a/xorg-server/mi/mieq.c +++ b/xorg-server/mi/mieq.c @@ -83,17 +83,17 @@ static EventQueueRec miEventQueue; #include <pthread.h>
static pthread_mutex_t miEventQueueMutex = PTHREAD_MUTEX_INITIALIZER;
-extern BOOL serverInitComplete;
-extern pthread_mutex_t serverInitCompleteMutex;
-extern pthread_cond_t serverInitCompleteCond;
+extern BOOL serverRunning;
+extern pthread_mutex_t serverRunningMutex;
+extern pthread_cond_t serverRunningCond;
static inline void wait_for_server_init(void) {
/* If the server hasn't finished initializing, wait for it... */
- if(!serverInitComplete) {
- pthread_mutex_lock(&serverInitCompleteMutex);
- while(!serverInitComplete)
- pthread_cond_wait(&serverInitCompleteCond, &serverInitCompleteMutex);
- pthread_mutex_unlock(&serverInitCompleteMutex);
+ if(!serverRunning) {
+ pthread_mutex_lock(&serverRunningMutex);
+ while(!serverRunning)
+ pthread_cond_wait(&serverRunningCond, &serverRunningMutex);
+ pthread_mutex_unlock(&serverRunningMutex);
}
}
#endif
|