xserver: Branch 'master' - 8 commits

Keith Packard keithp at kemper.freedesktop.org
Sun May 22 16:28:49 PDT 2011


 dix/main.c                            |   25 ++-
 hw/xquartz/X11Application.m           |    6 
 hw/xquartz/console_redirect.c         |    2 
 hw/xquartz/darwin.c                   |   33 ++++-
 hw/xquartz/darwin.h                   |   15 --
 hw/xquartz/mach-startup/bundle-main.c |    5 
 hw/xquartz/mach-startup/stub.c        |    1 
 hw/xquartz/man/Xquartz.man            |    6 
 hw/xquartz/pbproxy/app-main.m         |    6 
 hw/xquartz/pbproxy/main.m             |   16 +-
 hw/xquartz/quartz.c                   |   15 +-
 hw/xquartz/quartzRandR.c              |  219 ++++++++++++++++++----------------
 hw/xquartz/quartzStartup.c            |    1 
 hw/xquartz/xpr/xprScreen.c            |    3 
 mi/mieq.c                             |   16 +-
 15 files changed, 210 insertions(+), 159 deletions(-)

New commits:
commit 1fb501ad1521cfedaa5cf3052d45a924ef1866cf
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sun May 22 10:18:36 2011 -0700

    XQuartz: Don't crash if CG increases our display resolution
    
    miPaintWindow would cause fbFill() to overwrite pScreen's pixmap which was
    sized for the old resolution.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index 68a059c..c395b42 100644
--- a/hw/xquartz/quartz.c
+++ b/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);
 }
commit 60af79e35ee8546a99d15a1358aac3deabfa22be
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sun May 22 09:32:57 2011 -0700

    XQuartz: RandR: Don't crash if X11 is launched while there are no attached displays
    
    If CG reports no displays when launching, we could crash in RandR.  Instead, just
    provide a fake 800x600 display until we are notified about displays being attached.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index 0e71d36..68a059c 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -464,11 +464,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/hw/xquartz/quartzRandR.c b/hw/xquartz/quartzRandR.c
index d452b02..98b382d 100644
--- a/hw/xquartz/quartzRandR.c
+++ b/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;
@@ -446,9 +450,16 @@ static Bool _QuartzRandRUpdateFakeModes (ScreenPtr pScreen) {
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
     QuartzModeInfo activeMode;
 
-    if (!QuartzRandRCopyCurrentModeInfo(pQuartzScreen->displayIDs[0], &activeMode)) {
-        ErrorF("Unable to determine current display mode.\n");
-        return FALSE;
+    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)
@@ -456,7 +467,7 @@ static Bool _QuartzRandRUpdateFakeModes (ScreenPtr pScreen) {
     if(pQuartzScreen->currentMode.ref)
         CFRelease(pQuartzScreen->currentMode.ref);
 
-    if (pQuartzScreen->displayCount > 1) {
+    if(pQuartzScreen->displayCount > 1) {
         activeMode.width = pScreen->width;
         activeMode.height = pScreen->height;
         if(XQuartzIsRootless)
@@ -479,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/hw/xquartz/xpr/xprScreen.c b/hw/xquartz/xpr/xprScreen.c
index d2968dc..98250e6 100644
--- a/hw/xquartz/xpr/xprScreen.c
+++ b/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;
     }
 
commit f25ca898c54cb88c7886005fc75a53762c42710b
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Thu May 19 14:39:22 2011 -0700

    XQuartz: Mark functions _X_NORETURN
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index e90c33e..fa8d4ce 100644
--- a/hw/xquartz/darwin.c
+++ b/hw/xquartz/darwin.c
@@ -772,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/hw/xquartz/mach-startup/stub.c b/hw/xquartz/mach-startup/stub.c
index 8319dd0..d8e4abd 100644
--- a/hw/xquartz/mach-startup/stub.c
+++ b/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/hw/xquartz/quartzStartup.c b/hw/xquartz/quartzStartup.c
index 00a9e48..25ef76e 100644
--- a/hw/xquartz/quartzStartup.c
+++ b/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);
commit 7413886d650aef492ecbfdc4298c2d92d9af5f87
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Thu May 19 14:35:56 2011 -0700

    XQuartz: Silence clang warnings about shadow declarations
    
    X11Application.m:1272:26: warning: declaration shadows a local variable [-Wshadow,Semantic Issue]
                    xp_error e;
                             ^
    X11Application.m:1098:36: note: previous declaration is here
    - (void) sendX11NSEvent:(NSEvent *)e {
                                       ^
    1 warning generated.
    
    bundle-main.c:648:36: warning: declaration shadows a local variable [-Wshadow,Semantic Issue]
                        int max_files, i;
                                       ^
    bundle-main.c:594:9: note: previous declaration is here
        int i;
            ^
    1 warning generated.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 283132e..7c41cbc 100644
--- a/hw/xquartz/X11Application.m
+++ b/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/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 0e62914..94c6068 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/hw/xquartz/mach-startup/bundle-main.c
@@ -645,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));
commit 96ac4e61f4618332d95d1fd0e4799dd82844f90f
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Thu May 19 14:34:39 2011 -0700

    XQuartz: Update DEBUG_LOG to report to ASL
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/darwin.c b/hw/xquartz/darwin.c
index 50234f2..e90c33e 100644
--- a/hw/xquartz/darwin.c
+++ b/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
diff --git a/hw/xquartz/darwin.h b/hw/xquartz/darwin.h
index 507c6f7..659de43 100644
--- a/hw/xquartz/darwin.h
+++ b/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/hw/xquartz/mach-startup/bundle-main.c b/hw/xquartz/mach-startup/bundle-main.c
index 8e34376..0e62914 100644
--- a/hw/xquartz/mach-startup/bundle-main.c
+++ b/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);
diff --git a/hw/xquartz/man/Xquartz.man b/hw/xquartz/man/Xquartz.man
index 19e8efb..aea56c9 100644
--- a/hw/xquartz/man/Xquartz.man
+++ b/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/hw/xquartz/xpr/xprScreen.c b/hw/xquartz/xpr/xprScreen.c
index f6a7129..d2968dc 100644
--- a/hw/xquartz/xpr/xprScreen.c
+++ b/hw/xquartz/xpr/xprScreen.c
@@ -253,7 +253,7 @@ xprDisplayInit(void)
 {
     CGDisplayCount displayCount;
 
-    DEBUG_LOG("");
+    TRACE();
 
     CGGetActiveDisplayList(0, NULL, &displayCount);
 
commit 384eb45b944a4386eae74a5503423c13b5f2a659
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat May 14 18:33:57 2011 -0700

    XQuartz: RandR: Avoid over-releasing if we are unable to determine the current display mode.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/quartzRandR.c b/hw/xquartz/quartzRandR.c
index 05641a6..d452b02 100644
--- a/hw/xquartz/quartzRandR.c
+++ b/hw/xquartz/quartzRandR.c
@@ -444,26 +444,29 @@ static Bool QuartzRandRSetConfig (ScreenPtr           pScreen,
 
 static Bool _QuartzRandRUpdateFakeModes (ScreenPtr pScreen) {
     QuartzScreenPtr pQuartzScreen = QUARTZ_PRIV(pScreen);
+    QuartzModeInfo activeMode;
+
+    if (!QuartzRandRCopyCurrentModeInfo(pQuartzScreen->displayIDs[0], &activeMode)) {
+        ErrorF("Unable to determine current display mode.\n");
+        return FALSE;
+    }
 
     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;
+        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;
 
commit 25191648b8db87735a99243697f73036255c1eb6
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat May 14 16:11:32 2011 -0700

    XQuartz: Don't call mieqEnqueue during server shutdown
    
    Found-by: GuardMalloc
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/dix/main.c b/dix/main.c
index 31e2d48..bc958b8 100644
--- a/dix/main.c
+++ b/dix/main.c
@@ -121,9 +121,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[]);
 
@@ -277,18 +277,25 @@ 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();
 
 	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/hw/xquartz/pbproxy/app-main.m b/hw/xquartz/pbproxy/app-main.m
index 9055bad..a8c3a60 100644
--- a/hw/xquartz/pbproxy/app-main.m
+++ b/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/hw/xquartz/pbproxy/main.m b/hw/xquartz/pbproxy/main.m
index dbdb6d0..29ce83b 100644
--- a/hw/xquartz/pbproxy/main.m
+++ b/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/mi/mieq.c b/mi/mieq.c
index 236ffcc..031b11a 100644
--- a/mi/mieq.c
+++ b/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
commit fd5f630bc41de73be3b1d26bf9ce3e9ef1badc3b
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat May 14 14:09:45 2011 -0700

    XQuartz: Fix an array-index-out-of-bounds crasher
    
    Found-by: GuardMalloc
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/console_redirect.c b/hw/xquartz/console_redirect.c
index cdd2b89..70a819e 100644
--- a/hw/xquartz/console_redirect.c
+++ b/hw/xquartz/console_redirect.c
@@ -116,7 +116,7 @@ static inline int _read_redirect(int fd, int flush) {
                 *s='\0';
                 asl_log(aslr->asl, aslr->msg, aslr->level, "%s", p);
             } else if(aslr->buf != p) {
-                memmove(aslr->buf, p, BUF_SIZE);
+                memmove(aslr->buf, p, BUF_SIZE - (p - aslr->buf));
                 aslr->w = aslr->buf + (s - p);
                 break;
             } else if(nbytes == BUF_SIZE - 1) {


More information about the xorg-commit mailing list