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)); }
/* setlogmask -- set the log mask level */ int setlogmask(int mask) { int oldmask; pthread_mutex_lock(&_sl_lock); _sl_mask = mask; oldmask = asl_set_filter(_sl_asl, mask); pthread_mutex_unlock(&_sl_lock); return oldmask; }
/* * 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 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) ; }
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 *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; }