--- src/macosx/system.m.orig	2009-11-22 12:17:42.000000000 +1100
+++ src/macosx/system.m	2011-08-08 01:01:52.000000000 +1000
@@ -386,13 +386,26 @@ int osx_bootstrap_ok(void)
    mach_port_t bp;
    kern_return_t ret;
    CFMachPortRef cfport;
+   CFDictionaryRef sessiondict;
 
    /* If have tested once, just return that answer */
    if (_ok >= 0)
       return _ok;
+   /* check for window server session */
+   sessiondict = CGSessionCopyCurrentDictionary();
+   if (!sessiondict) {
+      return (_ok = 0);
+   } else {
+      CFRelease(sessiondict);
+   }
+
    cfport = CFMachPortCreate(NULL, NULL, NULL, NULL);
-   task_get_bootstrap_port(mach_task_self(), &bp);
-   ret = bootstrap_register(bp, "bootstrap-ok-test", CFMachPortGetPort(cfport));
+   if (!cfport)
+      return (_ok = 0);
+   ret = task_get_bootstrap_port(mach_task_self(), &bp);
+   if (ret == ERR_SUCCESS) {
+      ret = bootstrap_register(bp, "bootstrap-ok-test", CFMachPortGetPort(cfport));
+   }
    CFRelease(cfport);
    _ok = (ret == KERN_SUCCESS) ? 1 : 0;
    return _ok;
