val = NULL;
if ((asl_msg_lookup(msg, ASL_KEY_OPTION, &val, NULL) == 0) && (val != NULL)) eval &= ~EVAL_SEND_TRACE;
- /* don't send lastlog/utmp messages to Activity Tracing */
- val = NULL;
- if ((asl_msg_lookup(msg, ASL_KEY_FACILITY, &val, NULL) == 0) && (val != NULL) &&
- (!strcmp(val, FACILITY_LASTLOG) || !strcmp(val, FACILITY_UTMPX))) eval &= ~EVAL_SEND_TRACE;
-
/* don't send CFLog messages to Activity Tracing */
val = NULL;
if ((asl_msg_lookup(msg, ASL_KEY_CFLOG_LOCAL_TIME, &val, NULL) == 0) && (val != NULL)) eval &= ~EVAL_SEND_TRACE;
+ val = NULL;
+ if (((asl_msg_lookup(msg, ASL_KEY_FACILITY, &val, NULL) == 0) && (val != NULL)) ||
+ ((asl_msg_lookup(asl->kvdict, ASL_KEY_FACILITY, &val, NULL) == 0) && (val != NULL)))
+ {
+ /* don't send lastlog/utmp messages to Activity Tracing */
+ if (!strcmp(val, FACILITY_LASTLOG) || !strcmp(val, FACILITY_UTMPX)) eval &= ~EVAL_SEND_TRACE;
+
+ /* don't send LOG_INSTALL messages to Activity Tracing */
+ if (!strcmp(val, asl_syslog_faciliy_num_to_name(LOG_INSTALL))) eval &= ~EVAL_SEND_TRACE;
+ }
+
return eval;
}
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
+#include <stdarg.h>
#include <pthread.h>
#include <dispatch/dispatch.h>
#include <asl.h>
#include <os/log.h>
#include <os/log_private.h>
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
#define LOG_NO_NOTIFY 0x1000
extern const char *asl_syslog_faciliy_num_to_name(int n);
extern uint32_t _asl_lib_vlog(asl_object_t obj, uint32_t eval, asl_object_t msg, const char *format, va_list ap);
extern uint32_t _asl_lib_vlog_text(asl_object_t obj, uint32_t eval, asl_object_t msg, const char *format, va_list ap);
-
-/* SHIM SPI */
-asl_object_t
+static void
_syslog_asl_client()
{
pthread_mutex_lock(&_sl_lock);
asl_set_filter(_sl_asl, _sl_mask);
}
pthread_mutex_unlock(&_sl_lock);
-
- return _sl_asl;
}
-/*
- * syslog, vsyslog --
- * print message on log file; output is intended for syslogd(8).
- */
-
-void
-vsyslog(int pri, const char *fmt, va_list ap)
+static void
+_vsyslog(int pri, const char *fmt, va_list ap, void *addr, bool mirror)
{
int level = pri & LOG_PRIMASK;
int fac = pri & LOG_FACMASK;
+ asl_object_t msg;
uint32_t eval;
- void *addr;
+ bool trace;
_syslog_asl_client();
- eval = _asl_evaluate_send(_sl_asl, NULL, level);
+ msg = asl_new(ASL_TYPE_MSG);
- /* don't send install messages to Activity Tracing */
- if (fac == LOG_INSTALL || (fac == 0 && _sl_fac == LOG_INSTALL)) {
- eval &= ~EVAL_SEND_TRACE;
+ if (fac != 0)
+ {
+ const char *facility = asl_syslog_faciliy_num_to_name(fac);
+ if (facility != NULL) asl_set(msg, ASL_KEY_FACILITY, facility);
}
- addr = __builtin_return_address(0);
+ eval = _asl_evaluate_send(_sl_asl, msg, level);
+ trace = (eval & EVAL_SEND_TRACE) && os_log_shim_enabled(addr);
- if ((eval & EVAL_SEND_TRACE) && os_log_shim_enabled(addr))
+ if (trace)
{
va_list ap_copy;
os_log_type_t type = shim_syslog_to_log_type[level];
os_log_with_args(OS_LOG_DEFAULT, type, fmt, ap_copy, addr);
va_end(ap_copy);
- if (eval & EVAL_TEXT_FILE)
+ if ((eval & EVAL_TEXT_FILE) && !mirror)
{
- asl_object_t msg = asl_new(ASL_TYPE_MSG);
- const char *facility;
-
- if (fac != 0)
- {
- facility = asl_syslog_faciliy_num_to_name(fac);
- if (facility != NULL) asl_set(msg, ASL_KEY_FACILITY, facility);
- }
-
_asl_lib_vlog_text(_sl_asl, eval, msg, fmt, ap);
-
- asl_release(msg);
}
}
- else if (eval & EVAL_ASL)
- {
- asl_object_t msg = asl_new(ASL_TYPE_MSG);
- const char *facility;
-
- if (fac != 0)
- {
- facility = asl_syslog_faciliy_num_to_name(fac);
- if (facility != NULL) asl_set(msg, ASL_KEY_FACILITY, facility);
- }
+ if ((eval & EVAL_ASL) && (mirror || !trace))
+ {
_asl_lib_vlog(_sl_asl, eval, msg, fmt, ap);
-
- asl_release(msg);
}
-}
-
-void
-#ifdef __STDC__
-syslog(int pri, const char *fmt, ...)
-#else
-syslog(pri, fmt, va_alist)
-int pri;
-char *fmt;
-va_dcl
-#endif
-{
- int level = pri & LOG_PRIMASK;
- int fac = pri & LOG_FACMASK;
- uint32_t eval;
- void *addr;
- _syslog_asl_client();
-
- eval = _asl_evaluate_send(_sl_asl, NULL, level);
+ asl_release(msg);
+}
- /* don't send install messages to Activity Tracing */
- if (fac == LOG_INSTALL || (fac == 0 && _sl_fac == LOG_INSTALL)) {
- eval &= ~EVAL_SEND_TRACE;
- }
+#if TARGET_OS_OSX
- addr = __builtin_return_address(0);
+extern typeof(syslog) syslog_legacy asm("_syslog");
+extern typeof(syslog) syslog_os_log asm("_syslog" __DARWIN_SUF_EXTSN);
- if ((eval & EVAL_SEND_TRACE) && os_log_shim_enabled(addr))
- {
- va_list ap;
- os_log_type_t type = shim_syslog_to_log_type[level];
-
-#ifdef __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- os_log_with_args(OS_LOG_DEFAULT, type, fmt, ap, addr);
- va_end(ap);
+void
+syslog_legacy(int pri, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ _vsyslog(pri, fmt, ap, __builtin_return_address(0), true);
+ va_end(ap);
+}
- if (eval & EVAL_TEXT_FILE)
- {
- va_list ap;
- asl_object_t msg = asl_new(ASL_TYPE_MSG);
- const char *facility;
-
- if (fac != 0)
- {
- facility = asl_syslog_faciliy_num_to_name(fac);
- if (facility != NULL) asl_set(msg, ASL_KEY_FACILITY, facility);
- }
-
-#ifdef __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- _asl_lib_vlog_text(_sl_asl, eval, msg, fmt, ap);
- va_end(ap);
+void
+syslog_os_log(int pri, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ _vsyslog(pri, fmt, ap, __builtin_return_address(0), false);
+ va_end(ap);
+}
- asl_release(msg);
- }
- }
- else if (eval & EVAL_ASL)
- {
- va_list ap;
- asl_object_t msg = asl_new(ASL_TYPE_MSG);
- const char *facility;
+#else /* !TARGET_OS_OSX */
- if (fac != 0)
- {
- facility = asl_syslog_faciliy_num_to_name(fac);
- if (facility != NULL) asl_set(msg, ASL_KEY_FACILITY, facility);
- }
+void
+syslog(int pri, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ _vsyslog(pri, fmt, ap, __builtin_return_address(0), false);
+ va_end(ap);
+}
-#ifdef __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- _asl_lib_vlog(_sl_asl, eval, msg, fmt, ap);
- va_end(ap);
+#endif /* !TARGET_OS_OSX */
- asl_release(msg);
- }
+void
+vsyslog(int pri, const char *fmt, va_list ap)
+{
+ _vsyslog(pri, fmt, ap, __builtin_return_address(0), false);
}
#ifndef BUILDING_VARIANT