From 1496e7d1dd53a3a0fed695ccb7ea6f5197672810 Mon Sep 17 00:00:00 2001 From: Apple Date: Thu, 17 Dec 2009 02:49:14 +0000 Subject: [PATCH] syslog-100.0.1.tar.gz --- aslcommon/Makefile | 4 ++++ aslmanager.tproj/Makefile | 1 + syslogd.tproj/Makefile | 1 + syslogd.tproj/bsd_out.c | 26 +++++++++++++------------- syslogd.tproj/daemon.c | 23 +++++++++++++++++++---- syslogd.tproj/dbserver.c | 1 - syslogd.tproj/remote.c | 2 +- util.tproj/syslog.c | 7 ++++++- 8 files changed, 45 insertions(+), 20 deletions(-) diff --git a/aslcommon/Makefile b/aslcommon/Makefile index eb99ed0..9bc1604 100644 --- a/aslcommon/Makefile +++ b/aslcommon/Makefile @@ -11,3 +11,7 @@ USERDEFS = asl_ipc.defs Extra_CC_Flags = -Wall -D__MigTypeCheck=1 -I. include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make + +ifneq ($(SDKROOT),) +Extra_MIG_Flags = -arch $(firstword $(RC_ARCHS)) +endif diff --git a/aslmanager.tproj/Makefile b/aslmanager.tproj/Makefile index 197b0f7..9872e69 100644 --- a/aslmanager.tproj/Makefile +++ b/aslmanager.tproj/Makefile @@ -13,3 +13,4 @@ include $(MAKEFILEPATH)/CoreOS/ReleaseControl/BSDCommon.make after_install: codesign -s- $(DSTROOT)/usr/sbin/aslmanager + plutil -convert binary1 $(DSTROOT)/System/Library/LaunchDaemons/com.apple.aslmanager.plist diff --git a/syslogd.tproj/Makefile b/syslogd.tproj/Makefile index 2aa8a32..6f40d64 100644 --- a/syslogd.tproj/Makefile +++ b/syslogd.tproj/Makefile @@ -35,5 +35,6 @@ after_install: $(INSTALL_DIRECTORY) "$(DSTROOT)"/usr/share/sandbox $(INSTALL_FILE) syslogd.sb "$(DSTROOT)"/usr/share/sandbox codesign -s- $(DSTROOT)/usr/sbin/syslogd + plutil -convert binary1 $(DSTROOT)/System/Library/LaunchDaemons/com.apple.syslogd.plist mkfile 8 "$(DSTROOT)"/private/var/log/asl/SweepStore chmod 644 "$(DSTROOT)"/private/var/log/asl/SweepStore diff --git a/syslogd.tproj/bsd_out.c b/syslogd.tproj/bsd_out.c index f4f2a55..10bbb75 100644 --- a/syslogd.tproj/bsd_out.c +++ b/syslogd.tproj/bsd_out.c @@ -101,7 +101,7 @@ _do_reset(void) { bsd_out_network_reset(); } - + reset = RESET_NONE; pthread_mutex_unlock(&reset_lock); @@ -438,7 +438,7 @@ bsd_log_string(const char *msg) static int _syslog_send_repeat_msg(struct config_rule *r) { - char vt[32], *p, *msg; + char vt[32], *msg; time_t tick; int len, status; @@ -447,14 +447,13 @@ _syslog_send_repeat_msg(struct config_rule *r) if (r->last_count == 0) return 0; tick = time(NULL); - p = ctime(&tick); - if (p == NULL) return -1; - memcpy(vt, p+4, 15); - vt[15] = '\0'; + memset(vt, 0, sizeof(vt)); + ctime_r(&tick, vt); + vt[19] = '\0'; msg = NULL; - asprintf(&msg, "%s: --- last message repeated %u time%s ---\n", vt, r->last_count, (r->last_count == 1) ? "" : "s"); + asprintf(&msg, "%s: --- last message repeated %u time%s ---\n", vt + 4, r->last_count, (r->last_count == 1) ? "" : "s"); if (msg == NULL) return -1; len = strlen(msg); @@ -489,7 +488,7 @@ _syslog_send_repeat_msg(struct config_rule *r) static int _syslog_send(asl_msg_t *msg, struct config_rule *r, char **out, char **fwd, time_t now) { - char vt[16], *so, *sf, *p, *outmsg; + char vt[16], tstr[32], *so, *sf, *outmsg; const char *vtime, *vhost, *vident, *vpid, *vmsg, *vlevel, *vfacility, *vrefproc, *vrefpid; size_t outlen, n; time_t tick; @@ -522,8 +521,9 @@ _syslog_send(asl_msg_t *msg, struct config_rule *r, char **out, char **fwd, time if (tick == 0) tick = now; } - p = ctime(&tick); - memcpy(vt, p+4, 15); + memset(tstr, 0, sizeof(tstr)); + ctime_r(&tick, tstr); + memcpy(vt, tstr+4, 15); vt[15] = '\0'; vhost = asl_get(msg, ASL_KEY_HOST); @@ -963,15 +963,15 @@ int bsd_out_network_reset(void) { struct config_rule *r; - + for (r = bsd_out_rule.tqh_first; r != NULL; r = r->entries.tqe_next) - { + { if (r->type == DST_TYPE_SOCK) { close(r->fd); r->fd = -1; } } - + return 0; } diff --git a/syslogd.tproj/daemon.c b/syslogd.tproj/daemon.c index b469ad9..ca428fc 100644 --- a/syslogd.tproj/daemon.c +++ b/syslogd.tproj/daemon.c @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include "daemon.h" @@ -68,7 +67,9 @@ static char myname[MAXHOSTNAMELEN + 1] = {0}; static OSSpinLock count_lock = 0; +#ifndef CONFIG_IPHONE static vproc_transaction_t vproc_trans = {0}; +#endif #define QUOTA_TABLE_SIZE 8192 #define QUOTA_TABLE_SLOTS 8 @@ -224,7 +225,7 @@ freeList(char **l) * actually just an array with 8 entry slots (for collisions) per bucket. * If there are more than 8 pids that hash to the same bucket, we * re-use the one with the lowest message usage (highest remaining - * quota). This can lead to "generosity: if there are nine of more + * quota). This can lead to "generosity: if there are nine or more * pids with the same last 10 bits all logging like crazy, we may * end up allowing some of them to log more than their quota. * That would be a remarkably rare occurrence. @@ -239,6 +240,8 @@ quota_check(pid_t pid, time_t now, asl_msg_t *msg) if (msg == NULL) return VERIFY_STATUS_INVALID_MESSAGE; if (global.mps_limit == 0) return VERIFY_STATUS_OK; + OSSpinLockLock(&global.lock); + if (quota_table_time != now) { memset(quota_table_pid, 0, sizeof(quota_table_pid)); @@ -256,6 +259,8 @@ quota_check(pid_t pid, time_t now, asl_msg_t *msg) { quota_table_pid[x] = pid; quota_table_quota[x] = global.mps_limit; + + OSSpinLockUnlock(&global.lock); return VERIFY_STATUS_OK; } @@ -276,11 +281,17 @@ quota_check(pid_t pid, time_t now, asl_msg_t *msg) asl_set(msg, ASL_KEY_LEVEL, QUOTA_EXCEEDED_LEVEL); } + OSSpinLockUnlock(&global.lock); return VERIFY_STATUS_OK; } - if (quota_table_quota[x] < 0) return VERIFY_STATUS_EXCEEDED_QUOTA; + if (quota_table_quota[x] < 0) + { + OSSpinLockUnlock(&global.lock); + return VERIFY_STATUS_EXCEEDED_QUOTA; + } + OSSpinLockUnlock(&global.lock); return VERIFY_STATUS_OK; } @@ -294,10 +305,10 @@ quota_check(pid_t pid, time_t now, asl_msg_t *msg) } /* can't find the pid and no slots were available - reuse slot with highest remaining quota */ - asldebug("Quotas: reused slot %d pid %d quota %d for new pid %d\n", maxx, (int)quota_table_pid[maxx], quota_table_quota[maxx], (int)pid); quota_table_pid[maxx] = pid; quota_table_quota[maxx] = global.mps_limit; + OSSpinLockUnlock(&global.lock); return VERIFY_STATUS_OK; } @@ -438,7 +449,9 @@ asl_client_count_increment() { OSSpinLockLock(&count_lock); +#ifndef CONFIG_IPHONE if (global.client_count == 0) vproc_trans = vproc_transaction_begin(NULL); +#endif global.client_count++; #ifdef DEBUG asldebug("global.client_count++ (%d)\n", global.client_count); @@ -453,7 +466,9 @@ asl_client_count_decrement() OSSpinLockLock(&count_lock); if (global.client_count > 0) global.client_count--; +#ifndef CONFIG_IPHONE if (global.client_count == 0) vproc_transaction_end(NULL, vproc_trans); +#endif #ifdef DEBUG asldebug("global.client_count-- (%d)\n", global.client_count); #endif diff --git a/syslogd.tproj/dbserver.c b/syslogd.tproj/dbserver.c index 5bce571..a0a51e0 100644 --- a/syslogd.tproj/dbserver.c +++ b/syslogd.tproj/dbserver.c @@ -460,7 +460,6 @@ database_server() if ((now.tv_sec > send_time.tv_sec) || ((now.tv_sec == send_time.tv_sec) && (now.tv_usec > send_time.tv_usec))) { notify_post(ASL_DB_NOTIFICATION); - notify_post(SELF_DB_NOTIFICATION); send_time.tv_sec = 0; send_time.tv_usec = 0; snooze = 0; diff --git a/syslogd.tproj/remote.c b/syslogd.tproj/remote.c index 7a97f55..4273abb 100644 --- a/syslogd.tproj/remote.c +++ b/syslogd.tproj/remote.c @@ -524,7 +524,7 @@ session(void *x) continue; } - status = notify_register_file_descriptor(SELF_DB_NOTIFICATION, &wfd, 0, &wtoken); + status = notify_register_file_descriptor(ASL_DB_NOTIFICATION, &wfd, 0, &wtoken); if (status != 0) { snprintf(str, sizeof(str) - 1, "notify_register_file_descriptor failed: %d\n", status); diff --git a/util.tproj/syslog.c b/util.tproj/syslog.c index 656c6cb..3cc73bb 100644 --- a/util.tproj/syslog.c +++ b/util.tproj/syslog.c @@ -112,9 +112,14 @@ static asl_file_list_t *db_files = NULL; static asl_store_t *store = NULL; static asl_file_t *legacy = NULL; -static uint32_t dbselect = DB_SELECT_STORE; static asl_file_t *export = NULL; +#ifdef CONFIG_IPHONE +static uint32_t dbselect = DB_SELECT_SYSLOGD; +#else +static uint32_t dbselect = DB_SELECT_STORE; +#endif + /* notify SPI */ uint32_t notify_register_plain(const char *name, int *out_token); -- 2.45.2