Exemplo n.º 1
0
void
IOPowerWatcher::iopmcallback(void *				param, 
			     IOPMConnection                    connection,
			     IOPMConnectionMessageToken        token, 
			     IOPMSystemPowerStateCapabilities	capabilities)
{
    IOPowerWatcher *me = (IOPowerWatcher *)param;

    if (SECURITY_DEBUG_LOG_ENABLED()) {
	secdebug("powerwatch", "powerstates");
	if (capabilities & kIOPMSystemPowerStateCapabilityDisk)
	    secdebug("powerwatch", "disk");
	if (capabilities & kIOPMSystemPowerStateCapabilityNetwork)
	    secdebug("powerwatch", "net");
	if (capabilities & kIOPMSystemPowerStateCapabilityAudio) 
	    secdebug("powerwatch", "audio");
	if (capabilities & kIOPMSystemPowerStateCapabilityVideo)
	    secdebug("powerwatch", "video");
    }

    /* if cpu and no display -> in DarkWake */
    if ((capabilities & (kIOPMSystemPowerStateCapabilityCPU|kIOPMSystemPowerStateCapabilityVideo)) == kIOPMSystemPowerStateCapabilityCPU) {
        secdebug("powerwatch", "enter DarkWake");
	me->mInDarkWake = true;
    } else if (me->mInDarkWake) {
        secdebug("powerwatch", "exit DarkWake");
	me->mInDarkWake = false;
    }

    (void)IOPMConnectionAcknowledgeEvent(connection, token);

    return;
}
void secdebug_internal(const char* scope, const char* format, ...)
{
    if (__builtin_expect(SECURITY_DEBUG_LOG_ENABLED(), 0))
    {
        va_list list;
        va_start(list, format);
        
        CFStringRef formatString = CFStringCreateWithCString(NULL, format, kCFStringEncodingUTF8);
        CFStringRef message = CFStringCreateWithFormatAndArguments(kCFAllocatorDefault, NULL, formatString, list);
        CFRelease(formatString);
        CFIndex maxLength = CFStringGetMaximumSizeForEncoding(CFStringGetLength(message), kCFStringEncodingUTF8) + 1;
        char buffer[maxLength];
        CFStringGetCString(message, buffer, sizeof(buffer), kCFStringEncodingUTF8);
        CFRelease(message);
        SECURITY_DEBUG_LOG((char *)(scope), (buffer));
        
        va_end(list);
    }
}