// 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>
{
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");
}
}
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)
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());
}
//@@@ 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 *)
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;
}