int main(int argc, char **argv, char **envp) { aslclient aslc; pid_t child; int pstat; if(argc < 2 || strcmp(argv[1], "--help") == 0) { fprintf(stderr, "Usage: %s prog [args...]\n", argv[0]); exit(EXIT_FAILURE); } aslc = asl_open(BUNDLE_ID_PREFIX".startx", BUNDLE_ID_PREFIX, ASL_OPT_NO_DELAY); xi_asl_capture_fd(aslc, NULL, ASL_LEVEL_INFO, STDOUT_FILENO); xi_asl_capture_fd(aslc, NULL, ASL_LEVEL_NOTICE, STDERR_FILENO); #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 assert(posix_spawnp(&child, argv[1], NULL, NULL, &argv[1], envp) == 0); #else switch(child = fork()) { case -1: perror("fork"); return errno; case 0: return execvp(argv[1], &argv[1]); default: break; } #endif wait4(child, &pstat, 0, (struct rusage *)0); return pstat; }
void debug_log(int level, const char *str, ...) { va_list v; if ((debug & DEBUG_STDERR) && (level <= (debug & DEBUG_LEVEL_MASK))) { va_start(v, str); vfprintf(stderr, str, v); va_end(v); } if (debug & DEBUG_ASL) { char *line = NULL; if (aslc == NULL) { aslc = asl_open("aslmanager", "syslog", 0); asl_msg_t *msg = asl_msg_new(ASL_TYPE_MSG); asl_msg_set_key_val(msg, ASL_KEY_MSG, "Status Report"); asl_msg_set_key_val(msg, ASL_KEY_LEVEL, ASL_STRING_NOTICE); asl_create_auxiliary_file((asl_object_t)msg, "Status Report", "public.text", &asl_aux_fd); asl_msg_release(msg); } va_start(v, str); vasprintf(&line, str, v); va_end(v); if (line != NULL) write(asl_aux_fd, line, strlen(line)); free(line); } }
int main(int argc, char * const *argv) { log_asl_client = asl_open(NULL, "com.your.program", 0); // -- your code here -- asl_close(log_asl_client); return 0; }
// create a new ASL log void asepsis_setup_logging(void) { static int asepsis_logging_initialized = 0; if (asepsis_logging_initialized) { return; } asepsis_logging_initialized = 1; g_asepsis_asl = asl_open("Asepsis", "dylib", 0); g_asepsis_log_msg = asl_new(ASL_TYPE_MSG); asl_set(g_asepsis_log_msg, ASL_KEY_SENDER, "Asepsis"); }
static void initialize_logging(void) { logclient = asl_open(NULL, kmDNSHelperServiceName, (opt_debug ? ASL_OPT_STDERR : 0)); if (NULL == logclient) { fprintf(stderr, "Could not initialize ASL logging.\n"); fflush(stderr); return; } if (opt_debug) asl_set_filter(logclient, ASL_FILTER_MASK_UPTO(ASL_LEVEL_DEBUG)); }
static void sec_debug_init() { char *ccEnvStdErr = getenv("CC_STDERR"); if(ccEnvStdErr != NULL && strncmp(ccEnvStdErr, "yes", 3) == 0) std_options |= ASL_OPT_STDERR; aslhandle = asl_open(std_ident, std_facility, std_options); msgptr = asl_new(ASL_TYPE_MSG); asl_set(msgptr, ASL_KEY_FACILITY, "com.apple.infosec"); }
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 }
void ssyasl_init(char* progname) { ssyasl_gAslClient = asl_open(NULL, NULL, ASL_OPT_STDERR) ; char* path = ssyasl_create_log_path(progname) ; ssyasl_gFileDescriptor = open(path, FWRITE | O_CREAT | O_APPEND, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) ; free(path) ; asl_add_log_file(ssyasl_gAslClient, ssyasl_gFileDescriptor) ; // Without the following, you sometimes get two sysbeeps whenever asl_log is // invoked with level ASL_LEVEL_EMERG. Makes no sense to me. asl_set_filter(ssyasl_gAslClient, ASL_LEVEL_EMERG) ; ssyasl_set_filter(ASL_LEVEL_NOTICE) ; }
CAMLprim value stub_asl_open(value ident, value facility, value stderr, value no_delay, value no_remote) { CAMLparam5(ident, facility, stderr, no_delay, no_remote); const char *c_ident = String_val(ident); const char *c_facility = String_val(facility); uint32_t options = (Bool_val(stderr)?ASL_OPT_STDERR:0) | (Bool_val(no_delay)?ASL_OPT_NO_DELAY:0) | (Bool_val(no_remote)?ASL_OPT_NO_REMOTE:0); aslclient asl = NULL; caml_release_runtime_system(); asl = asl_open(c_ident, c_facility, options); caml_acquire_runtime_system(); CAMLreturn(alloc_client(asl)); }
/* funcs are listed in the same order as in the header */ int uvccInit() { int ret = UVCC_ERR_NO_ERROR; /* mach_port_null -> default port to communicate on */ kern_return_t kr = IOMasterPort(MACH_PORT_NULL, &uvcc_port); if(kr != kIOReturnSuccess || !uvcc_port) { uvcc_err("uvccInit: IOMasterPort", kr); return UVCC_ERR_CREATE_MASTER_PORT_FAIL; } logger = asl_open("se.dm9.uvcc", "uvcc logger facility", ASL_OPT_STDERR | ASL_OPT_NO_DELAY); if(!logger) ret = UVCC_WARN_LOGGING_TO_STDERR; last_error = kIOReturnSuccess; last_error_fn = "uvccInit"; return ret; }
void _init_asl(int source, int to_stderr) { if (asl != NULL){ asl_close(asl);; asl = NULL; } if (log_file_fd >= 0) close(log_file_fd); char source_desc[64]; log_get_source_desc(source, source_desc, sizeof(source_desc)); int opt = (to_stderr)?ASL_OPT_STDERR:0; asl = asl_open(FCT_LOG_IDENTITY, source_desc, opt); log_file_fd = open(sock_file, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (log_file_fd >= 0) asl_add_log_file(asl, log_file_fd); }
__private_extern__ asl_client_t * _asl_open_default() { static dispatch_once_t once; dispatch_once(&once, ^{ /* * Do a sleight-of-hand with ASL_OPT_NO_REMOTE to avoid a deadlock * since asl_open(xxx, yyy, 0) calls _asl_notify_open(1) * which locks _asl_global.lock. */ _asl_global.asl = (asl_client_t *)asl_open(NULL, NULL, ASL_OPT_NO_REMOTE); /* Reset options to clear ASL_OPT_NO_REMOTE bit */ if (_asl_global.asl != NULL) _asl_global.asl->options = 0; /* Now call _asl_notify_open(0) to finish the work */ _asl_notify_open(0); });
boolean_t IOHIDEventSystemStatistics::open(IOHIDSessionRef session, IOOptionBits options) { CFTypeRef bootArgs = nil; io_registry_entry_t entry = IO_OBJECT_NULL; (void)session; (void)options; entry = IORegistryEntryFromPath(kIOMasterPortDefault, "IODeviceTree:/options"); if(entry){ bootArgs = IORegistryEntryCreateCFProperty(entry, CFSTR("boot-args"), nil, 0); if (bootArgs){ if (CFGetTypeID(bootArgs) == CFStringGetTypeID()){ CFRange findRange; CFStringRef bootArgsString = (CFStringRef)bootArgs; findRange = CFStringFind(bootArgsString, CFSTR("opposing-button-logging"), 0); if (findRange.length != 0) _logButtonFiltering = true; } CFRelease(bootArgs); IOObjectRelease(entry); } } if (_logButtonFiltering) { _logStrings = CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks); _asl = asl_open("ButtonLogging", "Button Filtering Information", 0); _logfd = ::open("/var/mobile/Library/Logs/button.log", O_CREAT | O_APPEND | O_RDWR, 0644); if ((_logfd != -1) && (_asl != NULL)) asl_add_log_file(_asl, _logfd); } return true; }
/* * Open and set up system logging. */ void auditd_openlog(int debug, gid_t gid) { uint32_t opt = 0; char *cp = NULL; if (debug) opt = ASL_OPT_STDERR; au_aslclient = asl_open("auditd", "com.apple.auditd", opt); au_aslmsg = asl_new(ASL_TYPE_MSG); #ifdef ASL_KEY_READ_UID /* * Make it only so the audit administrator and members of the audit * review group (if used) have access to the auditd system log messages. */ asl_set(au_aslmsg, ASL_KEY_READ_UID, "0"); asprintf(&cp, "%u", gid); if (cp != NULL) { #ifdef ASL_KEY_READ_GID asl_set(au_aslmsg, ASL_KEY_READ_GID, cp); #endif free(cp); } #endif /* * Set the client-side system log filtering. */ if (debug) asl_set_filter(au_aslclient, ASL_FILTER_MASK_UPTO(ASL_LEVEL_DEBUG)); else asl_set_filter(au_aslclient, ASL_FILTER_MASK_UPTO(ASL_LEVEL_INFO)); }
void openlog(const char *ident, int opts, int logfac) { const char *facility; uint32_t asl_opts; pthread_mutex_lock(&_sl_lock); /* close existing aslclient */ if (_sl_asl != NULL) asl_close(_sl_asl); _sl_asl = NULL; if (_sl_ident != NULL) free(_sl_ident); _sl_ident = NULL; /* open with specified parameters */ if (ident != NULL) _sl_ident = strdup(ident); /* NB we allow the strdup to fail silently */ _sl_fac = logfac; facility = asl_syslog_faciliy_num_to_name(_sl_fac); _sl_opts = opts; asl_opts = ASL_OPT_SYSLOG_LEGACY; if (_sl_opts & LOG_NO_NOTIFY) asl_opts |= ASL_OPT_NO_REMOTE; if (_sl_opts & LOG_PERROR) asl_opts |= ASL_OPT_STDERR; _sl_mask = ASL_FILTER_MASK_UPTO(ASL_LEVEL_DEBUG); _sl_asl = asl_open(_sl_ident, facility, asl_opts); asl_set_filter(_sl_asl, _sl_mask); pthread_mutex_unlock(&_sl_lock); }
int main(int argc, char * const *argv) { uint32_t client_opts, send_level; const char *identity, *facility; // ASL client options client_opts = 0; // What level of messages are sent to syslogd send_level = ASL_LEVEL_NOTICE; // Sender identity. This should be NULL, as asl_open() will set this to the // name of the program. Only set this if you really need to. identity = NULL; // This should be your UTI facility = "se.hunch.asl.example"; // Options accepted by our example program int ch; static struct option longopts[] = { { "debug", no_argument, NULL, 'd' }, { "stderr", no_argument, NULL, 's' }, { "no-remote", no_argument, NULL, 'n' }, { "help", no_argument, NULL, 'h' }, { NULL, 0, NULL, '\0' } }; // Parse options while ((ch = getopt_long(argc, argv, "dsnh", longopts, NULL)) != -1) switch (ch) { case 'd': // Send all messages send_level = ASL_LEVEL_DEBUG; // This disables the remote-control mechanism for adjusting // filter levers for processes using e.g. syslog -c ... client_opts |= ASL_OPT_NO_REMOTE; break; case 's': // Print messages to stderr (adds stderr as an output file descriptor) client_opts |= ASL_OPT_STDERR; break; case 'n': // Send no messages at all. This does only affect what messages are sent // to the server and does not restrict which message are printed to // stderr, if enabled. send_level = -1; break; // Print usage and help default: usage(argv[0]); exit(1); } argc -= optind; argv += optind; // Setting ASL_OPT_NO_DELAY connects to the server immediately when calling asl_open() client_opts |= ASL_OPT_NO_DELAY; // Open connection to ASL (log_asl_client is defined in logging.h) // See /usr/include/asl.h for more details. log_asl_client = asl_open(identity, facility, client_opts); // The log_asl_client variable is used by the log_* and Log_* macros in logging.h // Handle errors from asl_open() if (log_asl_client == NULL) { perror("asl_open"); exit(2); } // Set the level for which messages are sent to the server log_set_send_filter(send_level); // Emit one message for each level log_emerg("This is a emerg-level message -- this message may propagate " "to all TTYs and/or other user interfaces"); log_alert("This is a alert-level message"); log_crit("This is a crit-level message"); log_err("This is a err-level message"); log_warn("This is a warn-level message"); log_notice("This is a notice-level message"); log_info("This is a info-level message"); log_debug("This message is a debug-level message"); // Close connection to syslogd asl_close(log_asl_client); return 0; }
int main(int argc, char *argv[]) { OSStatus err; int argIndex; Boolean delay; Boolean waitForWindowServerSession; Boolean forceShow; Boolean cleanExit; IBNibRef nibRef; WindowRef window; // Initialise our ASL state. gASLClient = asl_open(NULL, "PreLoginAgents", 0); assert(gASLClient != NULL); (void) asl_set_filter(gASLClient, ASL_FILTER_MASK_UPTO(ASL_LEVEL_INFO)); gASLMessage = asl_new(ASL_TYPE_MSG); assert(gASLMessage != NULL); (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Start"); // Parse our arguments. We support arguments that allow you to turn off // various special cases within the code. This makes it easy to test whether // the special cases are still required. delay = false; waitForWindowServerSession = false; forceShow = true; cleanExit = true; for (argIndex = 1; argIndex < argc; argIndex++) { if ( strcasecmp(argv[argIndex], "--nodelay") == 0 ) { delay = false; } else if ( strcasecmp(argv[argIndex], "--delay") == 0 ) { delay = true; } else if ( strcasecmp(argv[argIndex], "--nowait") == 0 ) { waitForWindowServerSession = false; } else if ( strcasecmp(argv[argIndex], "--wait") == 0 ) { waitForWindowServerSession = true; } else if ( strcasecmp(argv[argIndex], "--noforce") == 0 ) { forceShow = false; } else if ( strcasecmp(argv[argIndex], "--force") == 0 ) { forceShow = true; } else if ( strcasecmp(argv[argIndex], "--nocleanexit") == 0 ) { cleanExit = false; } else if ( strcasecmp(argv[argIndex], "--cleanexit") == 0 ) { cleanExit = true; } else { (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Unrecognised argument '%s'", argv[argIndex]); } } // Handle various options. if (waitForWindowServerSession) { WaitForWindowServerSession(); } else { (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Not waiting for CGSessionCopyCurrentDictionary"); } if (delay) { (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Delaying"); sleep(3); } else { (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Not delaying"); } // Set up our UI. err = CreateNibReference(CFSTR("main"), &nibRef); assert(err == noErr); err = CreateWindowFromNib(nibRef, CFSTR("MainWindow"), &window); assert(err == noErr); DisposeNibReference(nibRef); // We have to set kHIWindowBitCanBeVisibleWithoutLogin to let the // system know that we're not accidentally trying to display a window // pre-login. // // Also, window is a utility window and, by default, these have the // kWindowHideOnSuspendAttribute attribute set. As our application is a // UI element which never activates, and we want our panel to show regardless, // we must clear kWindowHideOnSuspendAttribute. static const int kAttributesToSet[] = { kHIWindowBitCanBeVisibleWithoutLogin, 0 }; static const int kAttributesToClear[] = { kHIWindowBitHideOnSuspend, 0 }; err = HIWindowChangeAttributes( window, kAttributesToSet, kAttributesToClear ); assert(err == noErr); // Due to a problem with the relationship between the UI frameworks and the // window server <rdar://problem/5136400>, ShowWindow is not sufficient to // show the window. We also have to use BringToFront. ShowWindow(window); if (forceShow) { (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Showing window with extreme prejudice"); BringToFront(window); } else { (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Showing window normally"); } // Set up our SIGTERM handler. if (cleanExit) { (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Installing SIGTERM handler"); InstallHandleSIGTERMFromRunLoop(); } else { (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Not installing SIGTERM handler"); } // Go go gadget Carbon! (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "RunApplicationEventLoop"); RunApplicationEventLoop(); (void) asl_log(gASLClient, gASLMessage, ASL_LEVEL_INFO, "Stop"); return EXIT_SUCCESS; }
void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap) { #if TARGET_OS_IPHONE static int asl_initialized = 0; #if !TARGET_IPHONE_SIMULATOR static aslclient asl_client; #endif #else FILE *fp = NULL; (void)fp; #endif if (!verbosity_is_enabled()) return; #if TARGET_OS_IPHONE #if TARGET_IPHONE_SIMULATOR vprintf(fmt, ap); #else if (!asl_initialized) { asl_client = asl_open(file_path_str(FILE_PATH_PROGRAM_NAME), "com.apple.console", ASL_OPT_STDERR | ASL_OPT_NO_DELAY); asl_initialized = 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]; char buffer[1024]; msg_new[0] = buffer[0] = '\0'; snprintf(msg_new, sizeof(msg_new), "%s: %s %s", file_path_str(FILE_PATH_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(file_path_str(FILE_PATH_LOG_WARN), tag)) prio = ANDROID_LOG_WARN; else if (string_is_equal(file_path_str(FILE_PATH_LOG_ERROR), tag)) prio = ANDROID_LOG_ERROR; } __android_log_vprint(prio, file_path_str(FILE_PATH_PROGRAM_NAME), fmt, ap); #else #ifdef HAVE_FILE_LOGGER fp = (FILE*)retro_main_log_file(); #else fp = stderr; #endif fprintf(fp, "%s %s :: ", file_path_str(FILE_PATH_PROGRAM_NAME), tag ? tag : file_path_str(FILE_PATH_LOG_INFO)); vfprintf(fp, fmt, ap); fflush(fp); #endif }
void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap) { #if TARGET_OS_IPHONE #if TARGET_IPHONE_SIMULATOR vprintf(fmt, ap); #else static aslclient asl_client; static int asl_initialized = 0; if (!asl_initialized) { asl_client = asl_open( file_path_str(FILE_PATH_PROGRAM_NAME), "com.apple.console", ASL_OPT_STDERR | ASL_OPT_NO_DELAY); asl_initialized = 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]; char buffer[1024]; msg_new[0] = buffer[0] = '\0'; snprintf(msg_new, sizeof(msg_new), "%s: %s %s", file_path_str(FILE_PATH_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(file_path_str(FILE_PATH_LOG_WARN), tag)) prio = ANDROID_LOG_WARN; else if (string_is_equal(file_path_str(FILE_PATH_LOG_ERROR), tag)) prio = ANDROID_LOG_ERROR; } __android_log_vprint(prio, file_path_str(FILE_PATH_PROGRAM_NAME), fmt, ap); } #else { #ifdef HAVE_QT char buffer[1024]; #endif #ifdef HAVE_FILE_LOGGER FILE *fp = (FILE*)retro_main_log_file(); #else FILE *fp = stderr; #endif #ifdef HAVE_QT buffer[0] = '\0'; vsnprintf(buffer, sizeof(buffer), fmt, ap); if (fp) { fprintf(fp, "%s %s", tag ? tag : file_path_str(FILE_PATH_LOG_INFO), buffer); fflush(fp); } ui_companion_driver_log_msg(buffer); #else #if defined(NXLINK) && !defined(HAVE_FILE_LOGGER) if (nxlink_connected) mutexLock(&nxlink_mtx); #endif if (fp) { fprintf(fp, "%s ", tag ? tag : file_path_str(FILE_PATH_LOG_INFO)); vfprintf(fp, fmt, ap); fflush(fp); } #if defined(NXLINK) && !defined(HAVE_FILE_LOGGER) if (nxlink_connected) mutexUnlock(&nxlink_mtx); #endif #endif } #endif }
void __libclog_create_client( void ) { __libclog_client = asl_open( "CLog", "com.apple.console", ASL_OPT_STDERR | ASL_OPT_NO_DELAY ); }