Exemplo n.º 1
0
Arquivo: asl_fd.c Projeto: aosm/syslog
/*
 * Read from the FD until there is no more to read and redirect to ASL.
 * Preconditions:
 *      1: called from the appropriate serial queue for operating on
 *         redirect_descriptors
 *      2: descriptor corresponds to a valid entry in redirect_descriptors
 *
 * Return values:
 *      If the pipe is closed, EOF is returned regardless of how many bytes
 *      were processed.  If the pipe is still open, the number of read bytes
 *      is returned.
 */
static inline int
_read_redirect(int descriptor, int flush)
{
    int total_read = 0;
    int nbytes;
    asl_redirect_t *aslr = &redirect_descriptors[descriptor];

    while ((nbytes = read(descriptor, aslr->w, BUF_SIZE - (aslr->w - aslr->buf) - 1)) > 0)
	{
        char *s, *p;

        /* Increment our returned number read */
        total_read += nbytes;

        /* Increment our write location */
        aslr->w += nbytes;
        aslr->w[0] = '\0';

        /* One line at a time */
        for (p = aslr->buf; p < aslr->w; p = s + 1)
		{
            /* Find null or \n */
            for (s = p; *s && *s != '\n'; s++);

            if (*s == '\n') *s='\0';

            if (s < aslr->w || aslr->buf == p)
			{
                /* Either the first of multiple messages or one message which is larger than our buffer */
                asl_log((aslclient)aslr->asl, (aslmsg)aslr->msg, aslr->level, "%s", p);
            }
			else
			{
                /* We reached the end of the buffer, move this chunk to the start. */
                memmove(aslr->buf, p, BUF_SIZE - (p - aslr->buf));
                aslr->w = aslr->buf + (s - p);
                break;
            }
        }

        if (p == aslr->w)
		{
            /* Start writing at the beginning in the case where we cleared the buffer */
            aslr->w = aslr->buf;
        }
    }

    /* Flush if requested or we're at EOF */
    if (flush || nbytes == 0)
	{
        if (aslr->w > aslr->buf)
		{
            *aslr->w = '\0';
            asl_log((aslclient)aslr->asl, (aslmsg)aslr->msg, aslr->level, "%s", aslr->buf);
        }
    }

    if (nbytes == 0) return EOF;
    return total_read;
}
Exemplo n.º 2
0
static int fill_cam_struct(IOUSBDeviceInterface197 **devIf,
						   uvccCam *cam)
{
    IOReturn ior;
    if((ior = (*devIf)->GetLocationID(devIf, &(cam->idLocation))) != kIOReturnSuccess)
    {
		uvcc_err("fill_cam_struct: GetLocationID", ior);
		return -1;
	}
	if((get_dev_desc(devIf, &(cam->devDesc))) != 0)
	{
		if(!logger) perror("uvcc error! fill_cam_struct: Could not retrieve device descriptor");
        else asl_log(logger, NULL, ASL_LEVEL_ERR, "fill_cam_struct: Could not retrieve device descriptor: %s", strerror(errno));
		return -1;
	}
	cam->mID = (struct uvccModelID *)&(cam->devDesc.hwIdVendor);
	cam->devIf = devIf;
	if((cam->ctrlIf = get_ctrl_if(devIf)) == NULL)
	{
		(*(cam->devIf))->Release(cam->devIf);
		CFRelease(cam->regName);
		if(!logger) perror("uvcc error! fill_cam_struct: Could not retrieve control interface");
        else asl_log(logger, NULL, ASL_LEVEL_ERR, "fill_cam_struct: Could not retrieve control interface: %s", strerror(errno));
		return -1;
	}
    if((ior = (*(cam->ctrlIf))->GetInterfaceNumber(cam->ctrlIf, &(cam->ifNo))) != kIOReturnSuccess)
    {
		(*(cam->devIf))->Release(cam->devIf);
		(*(cam->ctrlIf))->Release(cam->ctrlIf);
		uvcc_err("fill_cam_struct: GetInterfaceNumber", ior);
		return -1;
	}
	return 0;
}
/*****************************************************************************
* ManageEventsCallback
* -
* This is invoked when launchd loads a event dictionary and needs to inform
* us what a daemon / agent is looking for.
*****************************************************************************/
static void ManageEventsCallback(UserEventAgentLaunchdAction action, CFNumberRef token, CFTypeRef eventMatchDict, void* vContext)
{
    if (action == kUserEventAgentLaunchdAdd)
    {
        if (!eventMatchDict)
        {
            fprintf(stderr, "%s:%s empty dictionary\n", sPluginIdentifier, __FUNCTION__);
            return;
        }
        if (CFGetTypeID(eventMatchDict) != CFDictionaryGetTypeID())
        {
            fprintf(stderr, "%s:%s given non-dict for event dictionary, action %d\n", sPluginIdentifier, __FUNCTION__, action);
            return;
        }
        // Launchd wants us to add a launch event for this token and matching dictionary.
        asl_log(NULL, NULL, ASL_LEVEL_INFO, "%s:%s calling AddEventToPlugin", sPluginIdentifier, __FUNCTION__);
        AddEventToPlugin((BonjourUserEventsPlugin*)vContext, token, (CFDictionaryRef)eventMatchDict);
    }
    else if (action == kUserEventAgentLaunchdRemove)
    {
        // Launchd wants us to remove the event hook we setup for this token / matching dictionary.
        // Note: eventMatchDict can be NULL for Remove.
        asl_log(NULL, NULL, ASL_LEVEL_INFO, "%s:%s calling RemoveEventToPlugin", sPluginIdentifier, __FUNCTION__);
        RemoveEventFromPlugin((BonjourUserEventsPlugin*)vContext, token);
    }
    else
    {
        asl_log(NULL, NULL, ASL_LEVEL_INFO, "%s:%s unknown callback event\n", sPluginIdentifier, __FUNCTION__);
    }
}
Exemplo n.º 4
0
void PrintParams(
				 AuthorizationRef			auth,
				 const void *                userData,
				 CFDictionaryRef				request,
				 CFMutableDictionaryRef      response,
				 aslclient                   asl,
				 aslmsg                      aslMsg)
{
	 CFIndex count;
	 CFIndex index;
	 const void **keys;
	 asl_log(asl, aslMsg, ASL_LEVEL_DEBUG, "waker: %li", CFDictionaryGetCount(request));
	 
	 count = CFDictionaryGetCount( (CFDictionaryRef) request);
	 keys = (const void **) malloc( count * sizeof(const void *));
	 if (keys != NULL) {
		 CFDictionaryGetKeysAndValues( (CFDictionaryRef) request, keys, NULL);
		 
		 for (index = 0; index < count; index++) {
			 char buffer[1024];
			 CFStringRef s = (CFStringRef)CFDictionaryGetValue( (CFDictionaryRef) request, keys[index]);
			 
			 CFStringGetCString(keys[index], buffer, 1024, kCFStringEncodingASCII);
			 asl_log(asl, aslMsg, ASL_LEVEL_DEBUG, "waker: %s", buffer);
			 
			 CFStringGetCString(s, buffer, 1024, kCFStringEncodingASCII);
			 asl_log(asl, aslMsg, ASL_LEVEL_DEBUG, "waker: %s", buffer);
		 }
		 free(keys);
	 }	
}
Exemplo n.º 5
0
int uvccGetCamWithQTUniqueID(CFStringRef uId, uvccCam **cam)
{
	char cUId[19], idVendor[5], idProduct[5], location[9];
	struct uvccModelID mID;
	int nCams, i = 0;
	uvccCam **list;
	uint32_t sLoc;
	/* init cam */
	(*cam) = NULL;
	/* convert to c string and parse values */
	CFStringGetCString(uId, cUId, sizeof(cUId), kCFStringEncodingASCII);
	if(strlen(cUId) != 18 || cUId[0] != '0' || cUId[1] != 'x')
	{
		if(!logger) fprintf(stderr, "uvcc error! uvccGetCamWithQTUniqueID: supplied string is not an QTKit unique ID\n");
        else asl_log(logger, NULL, ASL_LEVEL_ERR, "uvccGetCamWithQTUniqueID: supplied string is not an QTKit unique ID");
		return -1;
	}
	/* copy and add ending */
	strncpy(location, &cUId[2], 8);
	location[8] = 0;
	strncpy(idVendor, &cUId[10], 4);
	idVendor[4] = 0;
	strncpy(idProduct, &cUId[14], 4);
	idProduct[4] = 0;
	sLoc = (uint32_t)strtol(location, NULL, 16);
	mID.idVendor = (uint16_t)strtol(idVendor, NULL, 16);
	mID.idProduct = (uint16_t)strtol(idProduct, NULL, 16);
	/* unfortunately you can't set location as matching dic value (since it's
	   not a cam prop).. */
	nCams = uvccGetCamsWithModelID(&mID, &list);
	if(nCams > 0)
	{	/* find matching cam and copy it into */
		for(i = 0; i < nCams; i++)
		{
			if(sLoc == list[i]->idLocation)
			{	/* we found it! */
				(*cam) = malloc(sizeof(uvccCam));
				if(!(*cam))
				{
					if(!logger) perror("uvcc error! uvccGetCamWithQTUniqueID: could not allocate memory for cam struct");
					else asl_log(logger, NULL, ASL_LEVEL_ERR, " uvccGetCamWithQTUniqueID: could not allocate memory for cam struct: %s", strerror(errno));
				}
				else memcpy((*cam), list[i], sizeof(uvccCam));
			}
			else
			{
				uvccReleaseCam(list[i]);
				free(list[i]);
			}
		}
		free(list);
	}
	if(!(*cam)) {
		if(!logger) fprintf(stderr, "uvcc error! uvccGetCamWithQTUniqueID: no camera with supplied QTKit unique ID was found\n");
        else asl_log(logger, NULL, ASL_LEVEL_ERR, "uvccGetCamWithQTUniqueID: no camera with supplied QTKit unique ID was found");
		return -1;
	}
	return 0;
}
__private_extern__
libSC_info_client_t *
libSC_info_client_create(dispatch_queue_t	q,
			 const char		*service_name,
			 const char		*service_description)
{
	xpc_connection_t	c;
	libSC_info_client_t	*client;
#if	!TARGET_IPHONE_SIMULATOR
	const uint64_t		flags	=	XPC_CONNECTION_MACH_SERVICE_PRIVILEGED;
#else	// !TARGET_IPHONE_SIMULATOR
	const uint64_t		flags	=	0;
#endif	// !TARGET_IPHONE_SIMULATOR

	if (_has_forked) {
		return NULL;
	}

	client = malloc(sizeof(libSC_info_client_t));
	client->active = TRUE;
	client->service_description = strdup(service_description);
	client->service_name = strdup(service_name);

	c = xpc_connection_create_mach_service(service_name, q, flags);

	xpc_connection_set_event_handler(c, ^(xpc_object_t xobj) {
		xpc_type_t	type;

		type = xpc_get_type(xobj);
		if (type == XPC_TYPE_DICTIONARY) {
			asl_log(NULL, NULL, ASL_LEVEL_ERR, "%s: unexpected message", client->service_name);
			log_xpc_object("  dict = ", xobj);
		} else if (type == XPC_TYPE_ERROR) {
			if (xobj == XPC_ERROR_CONNECTION_INVALID) {
				asl_log(NULL, NULL, ASL_LEVEL_ERR, "%s: server not available", client->service_name);
				client->active = FALSE;
			} else if (xobj == XPC_ERROR_CONNECTION_INTERRUPTED) {
				asl_log(NULL, NULL, ASL_LEVEL_DEBUG, "%s: server failed", client->service_name);
			} else {
				const char	*desc;

				desc = xpc_dictionary_get_string(xobj, XPC_ERROR_KEY_DESCRIPTION);
				asl_log(NULL, NULL, ASL_LEVEL_DEBUG,
					"%s: connection error: %d : %s",
					client->service_name,
					xpc_connection_get_pid(c),
					desc);
			}

		} else {
			asl_log(NULL, NULL, ASL_LEVEL_ERR,
				"%s: unknown event type : %p",
				client->service_name,
				type);
		}
	});
Exemplo n.º 7
0
char *sourceSuffix(char *str)
{
    
    asl_log(NULL, NULL, ASL_LEVEL_ERR, "sourceSuffix > test 0");
    
    char *clean = (char*) malloc(sizeof(str)); //request a block of memory
    
    asl_log(NULL, NULL, ASL_LEVEL_ERR, "sourceSuffix > test a");
    char *suff  = (char*) malloc(3);
    asl_log(NULL, NULL, ASL_LEVEL_ERR, "sourceSuffix > test b");
    
    
    asl_log(NULL, NULL, ASL_LEVEL_ERR, "sourceSuffix > str: %s", str);
    //asl_log(NULL, NULL, ASL_LEVEL_ERR, "sourceSuffix > CLEAN: %s", clean);
    
    //strcpy(clean, str);
    
    
    asl_log(NULL, NULL, ASL_LEVEL_ERR, "sourceSuffix > test c");
    long L = strlen(str);
    
    asl_log(NULL, NULL, ASL_LEVEL_ERR, "sourceSuffix > test 1");
    
    //printf("TRIM-INPUT:%ld + %s\n", L, str);
    
    strncpy(suff, (str+L-3), L); //Get the last three characters
    
    suff[3]   = '\0'; // IMPORTANT! //null terminate destination
    
    //printf("SUFF: %s\n", suff);
    
    asl_log(NULL, NULL, ASL_LEVEL_ERR, "sourceSuffix > test 2");
    
    if (strcmp(suff, ".do") != 0 && strcmp(suff, ".DO") != 0)
    {
        strcat(clean, ".do");
    }
    
    asl_log(NULL, NULL, ASL_LEVEL_ERR, "sourceSuffix > test 3");
    
    //printf("CLEAN: %s\n", clean);
    
    //strcpy(str, clean);
    
    asl_log(NULL, NULL, ASL_LEVEL_ERR, "sourceSuffix > test 4");
    //printf("TRIM-OOUTPUT-LEANGTH:%ld + %s\n", strlen(str), str);
    
//free(clean);
    free(suff);
    
    asl_log(NULL, NULL, ASL_LEVEL_ERR, "sourceSuffix > test 5");
    
    return clean; //The given and return variables must be the same
}
void ServiceBrowserCallback (DNSServiceRef sdRef,
                             DNSServiceFlags flags,
                             uint32_t interfaceIndex,
                             DNSServiceErrorType errorCode,
                             const char*                serviceName,
                             const char*                regtype,
                             const char*                replyDomain,
                             void*                      context )
{
    (void)interfaceIndex;
    (void)regtype;
    (void)replyDomain;
    BonjourUserEventsPlugin* plugin = (BonjourUserEventsPlugin*)context;
    NetBrowserInfo* browser = BrowserForSDRef(plugin, sdRef);

    if (!browser) // Missing browser?
    {
        fprintf(stderr, "%s:%s ServiceBrowserCallback: missing browser\n", sPluginIdentifier, __FUNCTION__);
        return;
    }

    if (errorCode != kDNSServiceErr_NoError)
    {
        fprintf(stderr, "%s:%s ServiceBrowserCallback: errcode set %d\n", sPluginIdentifier, __FUNCTION__, errorCode);
        return;
    }

    CFStringRef cfServiceName = CFStringCreateWithCString(NULL, serviceName, kCFStringEncodingUTF8);
    if (cfServiceName == NULL)
    {
        static int msg_count = 0;
        if (msg_count < 1000)
        {
            asl_log(NULL, NULL, ASL_LEVEL_INFO, "%s:%s Can not create CFString for serviceName %s", sPluginIdentifier, __FUNCTION__, serviceName);
            msg_count++;
        }
        return;
    }

    if (flags & kDNSServiceFlagsAdd)
    {
        asl_log(NULL, NULL, ASL_LEVEL_INFO, "%s:%s calling HandleTemporaryEventsForService Add\n", sPluginIdentifier, __FUNCTION__);
        HandleTemporaryEventsForService(plugin, browser, cfServiceName, plugin->_onAddEvents);
    }
    else
    {
        asl_log(NULL, NULL, ASL_LEVEL_INFO, "%s:%s calling HandleTemporaryEventsForService Remove\n", sPluginIdentifier, __FUNCTION__);
        HandleTemporaryEventsForService(plugin, browser, cfServiceName, plugin->_onRemoveEvents);
    }

    CFRelease(cfServiceName);
}
int
main(int argc, char *argv[])
{
	int64_t is_managed;
	char activity_name[32];

	xpc_track_activity();

	is_managed = 0;
	(void)vproc_swap_integer(NULL, VPROC_GSK_IS_MANAGED, NULL, &is_managed);
	if (!is_managed) {
		exit(1);
	}

	if (argc != 2) {
		exit(1);
	}

	if (strcmp(argv[1], "daily") == 0) {
	} else if (strcmp(argv[1], "weekly") == 0) {
	} else if (strcmp(argv[1], "monthly") == 0) {
	} else {
		exit(1);
	}

	snprintf(activity_name, sizeof(activity_name), "com.apple.periodic-%s", argv[1]);

	xpc_activity_register(activity_name, XPC_ACTIVITY_CHECK_IN, ^(xpc_activity_t activity) {
		xpc_activity_state_t state;

		state = xpc_activity_get_state(activity);
		if (state == XPC_ACTIVITY_STATE_RUN) {
			pid_t pid;
			int status;
			bool success = false;

			asl_log(NULL, NULL, ASL_LEVEL_NOTICE, "Running %s periodic task.", argv[1]);

			const char *args[] = { "periodic", argv[1], NULL };
			if (posix_spawn(&pid, "/usr/sbin/periodic", NULL, NULL, (char * const *)args, environ) == 0) {
				if (waitpid(pid, &status, 0) != -1 && WIFEXITED(status) && WEXITSTATUS(status) == 0) {
					success = true;
				}
			}

			if (!success) {
				asl_log(NULL, NULL, ASL_LEVEL_NOTICE, "Error running %s periodic task.", argv[1]);
			}
		}
	});
Exemplo n.º 10
0
Arquivo: log.c Projeto: bincker/hproxy
static inline void __log(const char *szMsg, int level , va_list ap ){
    char level_str[32];
    log_get_level_desc(level, level_str, sizeof(level_str));
    
    time_t now;
    struct timeval tv;
 	time(&now);
    gettimeofday(&tv, 0);
  	char time_str[32];
    strftime(time_str, sizeof(time_str), "%Y/%m/%d %T", localtime(&now));
    
#ifdef __linux__
	if (where & FCTLOG_TO_CONSOLE){
		printf( "%s.%03d [%s] ",time_str, localtime(&now), level_str);
		vprintf(szMsg, ap);
		printf("\n");
	}
	if ((where & FCTLOG_TO_FILE) && sock_file != NULL){
        FILE* fp = fopen(sock_file, "a+");
        if (fp){
            fprintf(fp,  "%s.%03d [%s] ",time_str, localtime(&now), level_str);
            vfprintf(fp, szMsg, ap);
			fprintf(fp, "\n");
            fclose(fp);
        }
    }
#endif

#ifdef __APPLE__
   asl_log(asl, NULL, asl_log_level(level), szTmp);
#endif
}
Exemplo n.º 11
0
void SFB::Logger::Log(levels level, const char *facility, const char *message, const char *function, const char *file, int line)
{
	if(currentLogLevel < level)
		return;

	aslmsg msg = asl_new(ASL_TYPE_MSG);

	if(facility)
		asl_set(msg, ASL_KEY_FACILITY, facility);

	if(function)
		asl_set(msg, "Function", function);

	if(file)
		asl_set(msg, "File", file);

	if(-1 != line) {
		char buf [32];
		if(snprintf(buf, sizeof(buf), "%d", line))
			asl_set(msg, "Line", buf);
	}

	asl_log(nullptr, msg, level, "%s", message);

	asl_free(msg);
}
Exemplo n.º 12
0
void
g_log_default_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer unused_data)
{
	asl_log (NULL, NULL, to_asl_priority (log_level), "%s", message);
	if (log_level & fatal)
		abort ();
}
Exemplo n.º 13
0
static void logToStderr(const char* buffer)
{
#if USE(APPLE_SYSTEM_LOG)
    asl_log(0, 0, ASL_LEVEL_NOTICE, "%s", buffer);
#endif
    fputs(buffer, stderr);
}
static OSStatus DoGetUID(
	AuthorizationRef			auth,
    const void *                userData,
	CFDictionaryRef				request,
	CFMutableDictionaryRef      response,
    aslclient                   asl,
    aslmsg                      aslMsg
)
    // Implements the kSampleGetUIDsCommand.  Gets the process's three UIDs and 
    // adds them to the response dictionary.
{	
	OSStatus					retval = noErr;
    int                         err;
	uid_t						euid;
	uid_t						ruid;
	CFNumberRef					values[2];
	long long					tmp;
	
	// Pre-conditions
	
	assert(auth != NULL);
    // userData may be NULL
	assert(request != NULL);
	assert(response != NULL);
    // asl may be NULL
    // aslMsg may be NULL
	
    // Get the UIDs.
    
	euid = geteuid();
	ruid = getuid();
	
	err = asl_log(asl, aslMsg, ASL_LEVEL_DEBUG, "euid=%ld, ruid=%ld", (long) euid, (long) ruid);
    assert(err == 0);
	
    // Add them to the response.
    
	tmp = euid;
	values[0] = CFNumberCreate(NULL, kCFNumberLongLongType, &tmp);
	tmp = ruid;
	values[1] = CFNumberCreate(NULL, kCFNumberLongLongType, &tmp);
	
	if ( (values[0] == NULL) || (values[1] == NULL) ) {
		retval = coreFoundationUnknownErr;
    } else {
        CFDictionaryAddValue(response, CFSTR(kSampleGetUIDsResponseRUID), values[0]);
        CFDictionaryAddValue(response, CFSTR(kSampleGetUIDsResponseEUID), values[1]);
	}
	
	if (values[0] != NULL) {
		CFRelease(values[0]);
	}
	if (values[1] != NULL) {
		CFRelease(values[1]);
	}

	return retval;
}
static void
log_xpc_object(const char *msg, xpc_object_t obj)
{
	char	*desc;

	desc = xpc_copy_description(obj);
	asl_log(NULL, NULL, ASL_LEVEL_ERR, "%s = %s", msg, desc);
	free(desc);
}
Exemplo n.º 16
0
void __security_debug(const char *scope, const char *function,
    const char *file, int line, const char *format, ...)
{
#if !defined(NDEBUG)
	pthread_once(&__security_debug_once, __security_debug_init);

	CFStringRef scopeName = NULL;
	/* Scope NULL is always enabled. */
	if (scope) {
		/* Check if the scope is enabled. */
		if (scopeSet) {
			scopeName = copyScopeName(scope, strlen(scope));
			if (negate == CFSetContainsValue(scopeSet, scopeName)) {
				CFRelease(scopeName);
				return;
			}
		} else if (!negate) {
			return;
		}
	}

	CFStringRef formatStr = CFStringCreateWithCString(kCFAllocatorDefault,
		format, kCFStringEncodingUTF8);
	va_list args;
	va_start(args, format);
	CFStringRef message = CFStringCreateWithFormatAndArguments(
		kCFAllocatorDefault, NULL, formatStr, args);
	va_end(args);
	time_t now = time(NULL);
	char *date = ctime(&now);
	date[19] = '\0';
	CFStringRef logStr = CFStringCreateWithFormat(kCFAllocatorDefault, NULL,
		CFSTR("%s %-*s %s %@\n"), date + 4, MAX_SCOPE_LENGTH - 1,
        scope ? scope : "", function, message);
	CFShow(logStr);
    char logMsg[4096];
    if (CFStringGetCString(logStr, logMsg, sizeof(logMsg), kCFStringEncodingUTF8)) {
#if 0
        asl_log(NULL, NULL, ASL_LEVEL_INFO, logMsg);
#else
        aslmsg msg = asl_new(ASL_TYPE_MSG);
        if (scope) {
            asl_set(msg, ASL_KEY_FACILITY, scope);
        }
        asl_set(msg, ASL_KEY_LEVEL, ASL_STRING_INFO);
        asl_set(msg, ASL_KEY_MSG, logMsg);
        asl_send(NULL, msg);
        asl_free(msg);
#endif
    }
	CFRelease(logStr);
	CFRelease(message);
	CFRelease(formatStr);
	if (scopeName)
		CFRelease(scopeName);
#endif
}
OSStatus DoWriteDataToFile(COMMAND_PROC_ARGUMENTS) {
#pragma unused (auth)
#pragma unused (userData)
	OSStatus retval = noErr;
	
	// Pre-conditions
    
    // userData may be NULL
	assert(request != NULL);
	assert(response != NULL);
    // asl may be NULL
    // aslMsg may be NULL
	
	// Get data to write and assert that it's a CFDataRef
	CFDataRef data = CFDictionaryGetValue(request, CFSTR(kData)) ;
	assert(data != NULL) ;
	assert(CFGetTypeID(data) == CFDataGetTypeID()) ;
	
	// Get path and assert that it's a CFStringRef
	CFStringRef filePath = CFDictionaryGetValue(request, CFSTR(kPath)) ;
	assert(filePath != NULL) ;
	assert(CFGetTypeID(filePath) == CFStringGetTypeID()) ;
	
	CFURLRef url = CFURLCreateWithFileSystemPath (
												  kCFAllocatorDefault,
												  filePath,
												  kCFURLPOSIXPathStyle,
												  false
												  ) ;
	
	SInt32 errorCode ;
	Boolean ok = CFURLWriteDataAndPropertiesToResource (
														url,
														data,
														NULL,
														&errorCode
														) ;
	if (!ok) {
		retval = errorCode ;
	}
	
	asl_log(asl,
			aslMsg,
			ASL_LEVEL_DEBUG,
			"DoWriteDataToFile result ok=%d for %s",
			ok,
			CFStringGetCStringPtr(
								  filePath,
								  CFStringGetSystemEncoding()
								  )
			) ;
	
	// Clean up
	CFQRelease(url) ;
	
	return retval ;
}	
Exemplo n.º 18
0
static void
sessionTracerLogStop (const char *domain, const char *type, int caused_by_failure, const char *reason, u_int32_t established, u_int32_t duration)
{
	aslmsg      m;
	char *      buf;
	char		data[256] = {0};

	m = asl_new(ASL_TYPE_MSG);
	asl_set(m, "com.apple.message.domain", domain);
	asl_set(m, "com.apple.message.type", type);
	asl_set(m, ASL_KEY_FACILITY, domain);
	asl_set(m, ASL_KEY_MSG, sessionString);
	if (caused_by_failure) {
		asl_set(m, "com.apple.message.result", CONSTSTR("failure"));	// failure
	} else {
		asl_set(m, "com.apple.message.result", CONSTSTR("success"));	// success
	}
	if (reason) {
		asl_set(m, "com.apple.message.reason", reason);
	} else {
		// reason was NULL; make sure success/failure have different signature
		if (caused_by_failure) {
			asl_set(m, "com.apple.message.reason", CONSTSTR("Internal/Server-side error"));
		} else {
			asl_set(m, "com.apple.message.reason", CONSTSTR("User/System initiated the disconnect"));
		}
	}
	
	buf = sessionTracerBucketizeTime(duration);
	
	if (established) {
		asl_set(m, "com.apple.message.connectiontime", buf);	// stuff the up time into value
		snprintf(data, sizeof(data), "SCNCController: Disconnecting.");
		asl_set(m, "com.apple.message.controller", data);
		asl_log(NULL, m, ASL_LEVEL_NOTICE, "");
	} else {
		asl_set(m, "com.apple.message.negotiatingtime", buf);	/// stuff the negoing time into value2
		snprintf(data, sizeof(data), "SCNCController: Disconnecting.");
		asl_set(m, "com.apple.message.controller", data);
		asl_log(NULL, m, ASL_LEVEL_NOTICE, "");
	}
	
	asl_free(m);
}
Exemplo n.º 19
0
/* internals! */
static CFDictionaryRef get_usb_service_dic()
{	/* this just gets the usb device matching dic */
	CFDictionaryRef mRef;
	if((mRef = IOServiceMatching(kIOUSBDeviceClassName)) == NULL)
	{   /* ASL_OPT_STDERR doesn't work on all systems.. */
		if(!logger) perror("uvcc error! get_usb_service_dic: IOServiceMatching returned NULL, no service matching dictionary for kIOUSBDeviceClassName could be created");
        else asl_log(logger, NULL, ASL_LEVEL_ERR, "get_usb_service_dic: IOServiceMatching returned NULL, no service matching dictionary for kIOUSBDeviceClassName could be created: %s", strerror(errno));
	}
	return mRef;
}
Exemplo n.º 20
0
static void logToStderr(const char* buffer)
{
#if USE(APPLE_SYSTEM_LOG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
    asl_log(0, 0, ASL_LEVEL_NOTICE, "%s", buffer);
#pragma clang diagnostic pop
#endif
    fputs(buffer, stderr);
}
void AddEventDictionary(CFDictionaryRef eventDict, CFMutableDictionaryRef allEventsDictionary, NetBrowserInfo* key)
{
    CFMutableArrayRef eventsForBrowser = (CFMutableArrayRef)CFDictionaryGetValue(allEventsDictionary, key);

    if (!eventsForBrowser) // We have no events for this browser yet, lets add him.
    {
        eventsForBrowser = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
        CFDictionarySetValue(allEventsDictionary, key, eventsForBrowser);
        asl_log(NULL, NULL, ASL_LEVEL_INFO, "%s:%s creating a new array", sPluginIdentifier, __FUNCTION__);
    }
    else
    {
        asl_log(NULL, NULL, ASL_LEVEL_INFO, "%s:%s Incrementing refcount", sPluginIdentifier, __FUNCTION__);
        CFRetain(eventsForBrowser);
    }

    CFArrayAppendValue(eventsForBrowser, eventDict);
    CFRelease(eventsForBrowser);
}
Exemplo n.º 22
0
Arquivo: print.c Projeto: ljx0305/tbox
/* //////////////////////////////////////////////////////////////////////////////////////
 * implementation
 */
tb_void_t tb_print(tb_char_t const* string)
{
    // check
    tb_check_return(string);

    // print to the ios device log
    asl_log(tb_null, tb_null, ASL_LEVEL_WARNING, "[%08x]: %s", (tb_uint32_t)tb_thread_self(), string);

    // print to the stdout
    fputs(string, stdout);
}
Exemplo n.º 23
0
void
mono_log_write_asl (const char *log_domain, GLogLevelFlags level, mono_bool hdr, const char *message)
{
	asl_log (NULL, NULL, to_asl_priority (level), "%s%s%s\n",
		log_domain != NULL ? log_domain : "",
		log_domain != NULL ? ": " : "",
		message);

	if (level & G_LOG_LEVEL_ERROR)
		abort();
}
Exemplo n.º 24
0
CAMLprim value stub_asl_log(value client, value message, value level, value txt) {
  CAMLparam4(client, message, level, txt);
  int c_level = Int_val(level);
  aslclient asl = Asl_val(client);
  aslmsg msg = Msg_val(message);
  const char *c_message = strdup(String_val(txt));
  caml_release_runtime_system();
  asl_log(asl, msg, c_level, "%s", c_message);
  caml_acquire_runtime_system();
  free((void*)c_message);
  CAMLreturn(0);
}
/*****************************************************************************
* NetBrowserInfoRelease
* -
* The method releases a NetBrowserInfo object.
*****************************************************************************/
void NetBrowserInfoRelease(CFAllocatorRef allocator, const void* info)
{
    (void)allocator;
    NetBrowserInfo* obj = (NetBrowserInfo*)info;

    if (!obj)
        return;

    if (obj->refCount == 1)
    {
        asl_log(NULL, NULL, ASL_LEVEL_INFO, "%s:%s: DNSServiceRefDeallocate %p", sPluginIdentifier, __FUNCTION__, obj->browserRef);
        DNSServiceRefDeallocate(obj->browserRef);
        free(obj);
    }
    else
    {
        --obj->refCount;
        asl_log(NULL, NULL, ASL_LEVEL_INFO, "%s:%s: Decremented ref count on %p, count %d", sPluginIdentifier, __FUNCTION__, obj->browserRef, (int)obj->refCount);
    }

}
Exemplo n.º 26
0
void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap)
{
#if TARGET_OS_IPHONE
   static int asl_inited = 0;
#if !TARGET_IPHONE_SIMULATOR
static aslclient asl_client;
#endif
#endif

   if (!RARCH_LOG_VERBOSE())
      return;
#if TARGET_OS_IPHONE
#if TARGET_IPHONE_SIMULATOR
   vprintf(fmt, ap);
#else
   if (!asl_inited)
   {
      asl_client = asl_open("RetroArch", "com.apple.console", ASL_OPT_STDERR | ASL_OPT_NO_DELAY);
      asl_inited = 1;
   }
   aslmsg msg = asl_new(ASL_TYPE_MSG);
   asl_set(msg, ASL_KEY_READ_UID, "-1");
   if (tag)
      asl_log(asl_client, msg, ASL_LEVEL_NOTICE, "%s", tag);
   asl_vlog(asl_client, msg, ASL_LEVEL_NOTICE, fmt, ap);
   asl_free(msg);
#endif
#elif defined(_XBOX1)
   /* FIXME: Using arbitrary string as fmt argument is unsafe. */
   char msg_new[1024], buffer[1024];
   snprintf(msg_new, sizeof(msg_new), "%s: %s %s",
         PROGRAM_NAME,
         tag ? tag : "",
         fmt);
   wvsprintf(buffer, msg_new, ap);
   OutputDebugStringA(buffer);
#elif defined(ANDROID)
   int prio = ANDROID_LOG_INFO;
   if (tag)
   {
      if (string_is_equal("[WARN]", tag))
         prio = ANDROID_LOG_WARN;
      else if (string_is_equal("[ERROR]", tag))
         prio = ANDROID_LOG_ERROR;
   }
   __android_log_vprint(prio, PROGRAM_NAME, fmt, ap);
#else
   fprintf(LOG_FILE, "%s %s :: ", PROGRAM_NAME, tag ? tag : "[INFO]");
   vfprintf(LOG_FILE, fmt, ap);
   fflush(LOG_FILE);
#endif
}
Exemplo n.º 27
0
static void HandleSIGTERMFromRunLoop(CFFileDescriptorRef f, CFOptionFlags callBackTypes, void *info)
    // Called from the runloop when the process receives a SIGTERM.  We log 
    // this occurence (which is safe to do because we're not in an actual signal 
    // handler, courtesy of the 'magic' in InstallHandleSIGTERMFromRunLoop) 
    // and then tell the app to quit.
{
    #pragma unused(f)
    #pragma unused(callBackTypes)
    #pragma unused(info)
    (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Got SIGTERM");

    QuitApplicationEventLoop();
}
/*****************************************************************************
* NetBrowserInfoRetain
* -
* The method retains a NetBrowserInfo object.
*****************************************************************************/
const void* NetBrowserInfoRetain(CFAllocatorRef allocator, const void* info)
{
    (void)allocator;
    NetBrowserInfo* obj = (NetBrowserInfo*)info;

    if (!obj)
        return NULL;

    ++obj->refCount;
    asl_log(NULL, NULL, ASL_LEVEL_INFO, "%s:%s: Incremented ref count on %p, count %d", sPluginIdentifier, __FUNCTION__, obj->browserRef, (int)obj->refCount);

    return obj;
}
Exemplo n.º 29
0
static void ks_service_matching_callback(void *refcon, io_iterator_t iterator)
{
	io_object_t obj = IO_OBJECT_NULL;

	while ((obj = IOIteratorNext(iterator))) {
        kern_return_t ret = IOServiceOpen(obj, mach_task_self(), 0,
            (io_connect_t*)refcon);
        if (ret) {
            asl_log(NULL, NULL, ASL_LEVEL_ERR,
                "IOServiceOpen() failed: %d", ret);
        }
        IOObjectRelease(obj);
	}
}
Exemplo n.º 30
0
static void register_timeout(void)
{
    if (idle_timer == NULL) {
        idle_timer = CFRunLoopTimerCreate(kCFAllocatorDefault,
            CFAbsoluteTimeGetCurrent() + TIMEOUT_IN_SECONDS,
            TIMEOUT_IN_SECONDS, 0, 0, idle_timer_proc, NULL);
        if (idle_timer == NULL) {
            asl_log(NULL, NULL, ASL_LEVEL_CRIT,
                "FATAL: failed to create idle timer, exiting.");
            exit(1);
        }
        CFRunLoopAddTimer(CFRunLoopGetCurrent(), idle_timer,
            kCFRunLoopDefaultMode);
    }
}