]> git.saurik.com Git - apple/security.git/blobdiff - cdsa/cdsa_utilities/machrunloopserver.cpp
Security-177.tar.gz
[apple/security.git] / cdsa / cdsa_utilities / machrunloopserver.cpp
index 93fc8f29ecc3e553977514a3acdd3fc14275dd40..cf860dbf8a6514b7f6efd2d03ca08956eca7b741 100644 (file)
@@ -20,8 +20,8 @@
 // machrunloopserver - C++ shell for writing Mach 3 servers called by CFRunLoop
 //
 #include "machrunloopserver.h"
+#include <Security/cfutilities.h>
 #include <mach/mach_error.h>
-#include <CoreFoundation/CoreFoundation.h>
 #include <Security/debugging.h>
 
 
@@ -83,10 +83,10 @@ void MachRunLoopServer::blockNewRequests(bool block)
 {
        if (block) {
                CFRunLoopRemoveSource(runLoop, runLoopSource, kCFRunLoopDefaultMode);
-               debug("machsrv", "disabled request reception");
+               secdebug("machsrv", "disabled request reception");
        } else {
                CFRunLoopAddSource(runLoop, runLoopSource, kCFRunLoopDefaultMode);
-               debug("machsrv", "enabled request reception");
+               secdebug("machsrv", "enabled request reception");
        }
 }
 
@@ -101,7 +101,7 @@ void MachRunLoopServer::alsoListenOn(Port port)
        CFRef<CFRunLoopSourceRef> source =
                CFMachPortCreateRunLoopSource(NULL, cfPort, 10);        //@@@ no idea what order is good
        CFRunLoopAddSource(runLoop, source, kCFRunLoopDefaultMode);
-       debug("machsrv", "also receiving from port %d", port.port());
+       secdebug("machsrv", "also receiving from port %d", port.port());
 }
 
 void MachRunLoopServer::stopListenOn(Port port)
@@ -111,7 +111,7 @@ void MachRunLoopServer::stopListenOn(Port port)
        CFRef<CFRunLoopSourceRef> source =
                CFMachPortCreateRunLoopSource(NULL, cfPort, 10);        //@@@ no idea what order is good
        CFRunLoopRemoveSource(runLoop, source, kCFRunLoopDefaultMode);
-       debug("machsrv", "no longer receiving from port %d", port.port());
+       secdebug("machsrv", "no longer receiving from port %d", port.port());
 }
 
 
@@ -125,7 +125,10 @@ void MachRunLoopServer::notifyIfDead(Port port) const
        //@@@ not clear how to deal with CFRetainCount of cfPort here
        //    will CF clean up the cfPort when it dies? Or do we have to keep a set?
        CFMachPortRef cfPort = CFMachPortCreateWithPort(NULL, port, NULL, NULL, NULL);
-       CFMachPortSetInvalidationCallBack(cfPort, cfInvalidateCallback);
+       if (cfPort != NULL) // check to make sure that we got a valid port reference back
+       {
+               CFMachPortSetInvalidationCallBack(cfPort, cfInvalidateCallback);
+       }
 }
 
 void MachRunLoopServer::cfInvalidateCallback(CFMachPortRef cfPort, void *)
@@ -147,20 +150,20 @@ void MachRunLoopServer::oneRequest(mach_msg_header_t *request)
        if (!handle(request, replyBuffer)) {
                // MIG dispatch did not recognize the request. Ignore/Retry/Fail? :-)
                //@@@ Should send an error reply back here, I suppose. Later...
-               debug("machrls", "MachRunLoopServer dispatch failed");
+               secdebug("machrls", "MachRunLoopServer dispatch failed");
                return;
        }
        
        // MIG dispatch handled the call. Send reply back to caller.
        // This boilerplate stolen from mach_msg_server, since MIG can't seem to
        // generate send-only code for replies (without explicit simpleroutines).
-       if (kern_return_t err = mach_msg_overwrite_trap(replyBuffer,
+       if (IFDEBUG(kern_return_t err =) mach_msg_overwrite(replyBuffer,
                (MACH_MSGH_BITS_REMOTE(replyBuffer->msgh_bits) == MACH_MSG_TYPE_MOVE_SEND_ONCE) ?
                MACH_SEND_MSG : MACH_SEND_MSG|MACH_SEND_TIMEOUT,
                replyBuffer->msgh_size, 0, MACH_PORT_NULL,
                0, MACH_PORT_NULL, (mach_msg_header_t *) 0, 0)) {
                //@@@ should at least clean up resources here, I suppose.
-               debug("machsrv", "RunloopServer cannot post reply: %s", mach_error_string(err));
+               secdebug("machsrv", "RunloopServer cannot post reply: %s", mach_error_string(err));
                active().releaseDeferredAllocations();
                return;
        }