From 30cde84f1eb4f8e4638b3c120d12001b121882b9 Mon Sep 17 00:00:00 2001 From: Apple Date: Thu, 5 Jul 2018 18:32:40 +0000 Subject: [PATCH 1/1] syslog-356.200.4.tar.gz --- libsystem_asl.tproj/src/asl.c | 68 ++++++++++------------- libsystem_asl.tproj/src/asl_core.c | 38 ------------- syslogd.tproj/com.apple.syslogd.plist | 5 +- syslogd.tproj/com.apple.syslogd_sim.plist | 5 +- syslogd.tproj/dbserver.c | 24 +++++--- xcodeconfig/libasl.xcconfig | 2 + 6 files changed, 49 insertions(+), 93 deletions(-) diff --git a/libsystem_asl.tproj/src/asl.c b/libsystem_asl.tproj/src/asl.c index 8e4777e..027516e 100644 --- a/libsystem_asl.tproj/src/asl.c +++ b/libsystem_asl.tproj/src/asl.c @@ -127,6 +127,7 @@ typedef struct time_t last_send; time_t last_oq_msg; uint32_t quota; + dispatch_once_t port_lookup_once; mach_port_t server_port; char *sender; pthread_mutex_t lock; @@ -135,7 +136,7 @@ typedef struct asl_client_t *asl; } _asl_global_t; -__private_extern__ _asl_global_t _asl_global = {0, -1, -1, -1, 0LL, 0LL, 0LL, 0LL, 0, MACH_PORT_NULL, NULL, PTHREAD_MUTEX_INITIALIZER, 0, NULL, NULL}; +__private_extern__ _asl_global_t _asl_global = {0, -1, -1, -1, 0LL, 0LL, 0LL, 0LL, 0, 0, MACH_PORT_NULL, NULL, PTHREAD_MUTEX_INITIALIZER, 0, NULL, NULL}; static const char *level_to_number_string[] = {"0", "1", "2", "3", "4", "5", "6", "7"}; @@ -158,6 +159,7 @@ _asl_fork_child() _asl_global.last_send = 0; _asl_global.last_oq_msg = 0; + _asl_global.port_lookup_once = 0; _asl_global.server_port = MACH_PORT_NULL; pthread_mutex_init(&(_asl_global.lock), NULL); @@ -252,9 +254,22 @@ _asl_notify_close() #endif static void -_asl_global_init(int reset) +_asl_global_init() { - _asl_global.server_port = asl_core_get_service_port(reset); + dispatch_once(&_asl_global.port_lookup_once, ^{ + char *str = getenv("ASL_DISABLE"); + if ((str == NULL) || strcmp(str, "1")) + { + bootstrap_look_up2(bootstrap_port, ASL_SERVICE_NAME, &_asl_global.server_port, 0, BOOTSTRAP_PRIVILEGED_SERVER); + } + }); +} + +mach_port_t +asl_core_get_service_port(__unused int reset) +{ + _asl_global_init(); + return _asl_global.server_port; } #pragma mark - @@ -266,7 +281,7 @@ asl_open(const char *ident, const char *facility, uint32_t opts) asl_client_t *asl = asl_client_open(ident, facility, opts); if (asl == NULL) return NULL; - _asl_global_init(0); + _asl_global_init(); if (!(opts & ASL_OPT_NO_REMOTE)) _asl_notify_open(1); return (asl_object_t)asl; @@ -1358,7 +1373,7 @@ _asl_send_message(asl_object_t obj, uint32_t eval, asl_msg_t *msg, const char *m return outstatus; } - _asl_global_init(0); + _asl_global_init(); outstatus = 0; /* @@ -1512,14 +1527,8 @@ _asl_send_message(asl_object_t obj, uint32_t eval, asl_msg_t *msg, const char *m kstatus = _asl_server_message(_asl_global.server_port, (caddr_t)str, len); if (kstatus != KERN_SUCCESS) { - /* retry once if the call failed */ - _asl_global_init(1); - kstatus = _asl_server_message(_asl_global.server_port, (caddr_t)str, len); - if (kstatus != KERN_SUCCESS) - { - vm_deallocate(mach_task_self(), (vm_address_t)str, vmsize); - outstatus = -1; - } + vm_deallocate(mach_task_self(), (vm_address_t)str, vmsize); + outstatus = -1; } } else if (vmsize >0) vm_deallocate(mach_task_self(), (vm_address_t)str, vmsize); @@ -1730,7 +1739,7 @@ _asl_auxiliary(asl_msg_t *msg, const char *title, const char *uti, const char *u return ASL_STATUS_OK; } - _asl_global_init(0); + _asl_global_init(); if (_asl_global.server_port == MACH_PORT_NULL) return ASL_STATUS_FAILED; send_str = asl_msg_to_string_raw(ASL_STRING_MIG, aux, "raw"); @@ -1752,15 +1761,9 @@ _asl_auxiliary(asl_msg_t *msg, const char *title, const char *uti, const char *u kstatus = _asl_server_create_aux_link(_asl_global.server_port, (caddr_t)str, len, &fileport, &newurl, &newurllen, &status); if (kstatus != KERN_SUCCESS) { - /* retry once if the call failed */ - _asl_global_init(1); - kstatus = _asl_server_create_aux_link(_asl_global.server_port, (caddr_t)str, len, &fileport, &newurl, &newurllen, &status); - if (kstatus != KERN_SUCCESS) - { - vm_deallocate(mach_task_self(), (vm_address_t)str, vmsize); - asl_msg_release(aux); - return ASL_STATUS_FAILED; - } + vm_deallocate(mach_task_self(), (vm_address_t)str, vmsize); + asl_msg_release(aux); + return ASL_STATUS_FAILED; } if (status != 0) @@ -1913,7 +1916,7 @@ _asl_server_control_query(void) asl_msg_t *m = NULL; static const char ctlstr[] = "1\nQ [= ASLOption control]\n"; - _asl_global_init(0); + _asl_global_init(); if (_asl_global.server_port == MACH_PORT_NULL) return NULL; len = strlen(ctlstr) + 1; @@ -1930,12 +1933,7 @@ _asl_server_control_query(void) status = 0; kstatus = _asl_server_query_2(_asl_global.server_port, vmstr, len, qmin, FETCH_BATCH, 0, (caddr_t *)&res, &reslen, &cmax, (int *)&status); - if (kstatus != KERN_SUCCESS) - { - /* retry once if the call failed */ - _asl_global_init(1); - kstatus = _asl_server_query_2(_asl_global.server_port, vmstr, len, qmin, FETCH_BATCH, 0, (caddr_t *)&res, &reslen, &cmax, (int *)&status); - } + if (kstatus != KERN_SUCCESS) return NULL; list = asl_msg_list_from_string(res); vm_deallocate(mach_task_self(), (vm_address_t)res, reslen); @@ -1957,7 +1955,7 @@ asl_store_location() uint32_t reslen, status; uint64_t cmax; - _asl_global_init(0); + _asl_global_init(); if (_asl_global.server_port == MACH_PORT_NULL) return ASL_STORE_LOCATION_FILE; res = NULL; @@ -1966,17 +1964,11 @@ asl_store_location() status = ASL_STATUS_OK; kstatus = _asl_server_query_2(_asl_global.server_port, NULL, 0, 0, -1, 0, (caddr_t *)&res, &reslen, &cmax, (int *)&status); - if (kstatus != KERN_SUCCESS) - { - /* retry once if the call failed */ - _asl_global_init(1); - kstatus = _asl_server_query_2(_asl_global.server_port, NULL, 0, 0, -1, 0, (caddr_t *)&res, &reslen, &cmax, (int *)&status); - } + if (kstatus != KERN_SUCCESS) return ASL_STORE_LOCATION_FILE; /* res should never be returned, but just to be certain we don't leak VM ... */ if (res != NULL) vm_deallocate(mach_task_self(), (vm_address_t)res, reslen); - if (kstatus != KERN_SUCCESS) return ASL_STORE_LOCATION_FILE; if (status == ASL_STATUS_OK) return ASL_STORE_LOCATION_MEMORY; return ASL_STORE_LOCATION_FILE; } diff --git a/libsystem_asl.tproj/src/asl_core.c b/libsystem_asl.tproj/src/asl_core.c index 30de51b..fd589b4 100644 --- a/libsystem_asl.tproj/src/asl_core.c +++ b/libsystem_asl.tproj/src/asl_core.c @@ -72,44 +72,6 @@ static pthread_mutex_t core_lock = PTHREAD_MUTEX_INITIALIZER; c -= a; c -= b; c ^= (b>>15); \ } -/* - * Get ASL server mach port. - * reset != 0 flushes cached port. - * reset < 0 returns MACH_PORT_NULL - */ -mach_port_t -asl_core_get_service_port(int reset) -{ - static mach_port_t server_port = MACH_PORT_NULL; - mach_port_t tmp; - kern_return_t kstatus; - - if ((reset != 0) && (server_port != MACH_PORT_NULL)) - { - mach_port_t tmp = server_port; - server_port = MACH_PORT_NULL; - mach_port_deallocate(mach_task_self(), tmp); - } - - if (reset < 0) return MACH_PORT_NULL; - - if (server_port != MACH_PORT_NULL) return server_port; - - tmp = MACH_PORT_NULL; - char *str = getenv("ASL_DISABLE"); - if ((str != NULL) && (!strcmp(str, "1"))) return MACH_PORT_NULL; - - kstatus = bootstrap_look_up2(bootstrap_port, ASL_SERVICE_NAME, &tmp, 0, BOOTSTRAP_PRIVILEGED_SERVER); - if ((kstatus != KERN_SUCCESS) || (tmp == MACH_PORT_NULL)) return MACH_PORT_NULL; - - if (!OSAtomicCompareAndSwap32Barrier(MACH_PORT_NULL, tmp, (int32_t *)&server_port)) - { - mach_port_deallocate(mach_task_self(), tmp); - } - - return server_port; -} - /* * Hash is used to improve string search. */ diff --git a/syslogd.tproj/com.apple.syslogd.plist b/syslogd.tproj/com.apple.syslogd.plist index 05ab013..bd9c2b7 100644 --- a/syslogd.tproj/com.apple.syslogd.plist +++ b/syslogd.tproj/com.apple.syslogd.plist @@ -43,10 +43,7 @@ MachServices com.apple.system.logger - - ResetAtClose - - + Sockets diff --git a/syslogd.tproj/com.apple.syslogd_sim.plist b/syslogd.tproj/com.apple.syslogd_sim.plist index 4c7d9a2..2a37fba 100644 --- a/syslogd.tproj/com.apple.syslogd_sim.plist +++ b/syslogd.tproj/com.apple.syslogd_sim.plist @@ -22,10 +22,7 @@ MachServices com.apple.system.logger - - ResetAtClose - - + Sockets diff --git a/syslogd.tproj/dbserver.c b/syslogd.tproj/dbserver.c index 7c355b6..4315290 100644 --- a/syslogd.tproj/dbserver.c +++ b/syslogd.tproj/dbserver.c @@ -655,6 +655,7 @@ register_session(task_name_t task_name, pid_t pid) asldebug("register_session: %u PID %d\n", (unsigned int)task_name, (int)pid); /* register for port death notification */ + previous = MACH_PORT_NULL; mach_port_request_notification(mach_task_self(), task_name, MACH_NOTIFY_DEAD_NAME, 0, global.dead_session_port, MACH_MSG_TYPE_MAKE_SEND_ONCE, &previous); mach_port_deallocate(mach_task_self(), previous); @@ -1284,12 +1285,15 @@ __asl_server_query_internal uint32_t outlen; kern_return_t kstatus; + *reply = NULL; + *replyCnt = 0; + *lastid = 0; *status = ASL_STATUS_OK; if ((request != NULL) && (request[requestCnt - 1] != '\0')) { - *status = ASL_STATUS_INVALID_ARG; vm_deallocate(mach_task_self(), (vm_address_t)request, requestCnt); + *status = ASL_STATUS_INVALID_ARG; return KERN_SUCCESS; } @@ -1341,7 +1345,8 @@ __asl_server_query_internal if (kstatus != KERN_SUCCESS) { free(out); - return kstatus; + *status = ASL_STATUS_FAILED; + return KERN_SUCCESS; } memmove(vmbuffer, out, outlen); @@ -1466,7 +1471,7 @@ __asl_server_prune security_token_t *token ) { - return KERN_SUCCESS; + return KERN_FAILURE; } /* @@ -1594,9 +1599,10 @@ __asl_server_create_aux_link char *url, *vmbuffer; int fd; - *status = ASL_STATUS_OK; *fileport = MACH_PORT_NULL; - *newurl = 0; + *newurl = NULL; + *newurlCnt = 0; + *status = ASL_STATUS_OK; if (message == NULL) { @@ -1606,8 +1612,8 @@ __asl_server_create_aux_link if (message[messageCnt - 1] != '\0') { - *status = ASL_STATUS_INVALID_ARG; vm_deallocate(mach_task_self(), (vm_address_t)message, messageCnt); + *status = ASL_STATUS_INVALID_ARG; return KERN_SUCCESS; } @@ -1615,12 +1621,11 @@ __asl_server_create_aux_link if ((global.dbtype & DB_TYPE_FILE) == 0) { + vm_deallocate(mach_task_self(), (vm_address_t)message, messageCnt); *status = ASL_STATUS_INVALID_STORE; return KERN_SUCCESS; } - *fileport = MACH_PORT_NULL; - msg = asl_msg_from_string(message); vm_deallocate(mach_task_self(), (vm_address_t)message, messageCnt); @@ -1671,7 +1676,8 @@ __asl_server_create_aux_link if (kstatus != KERN_SUCCESS) { free(url); - return kstatus; + *status = ASL_STATUS_FAILED; + return KERN_SUCCESS; } memmove(vmbuffer, url, *newurlCnt); diff --git a/xcodeconfig/libasl.xcconfig b/xcodeconfig/libasl.xcconfig index 82e6122..d55394e 100644 --- a/xcodeconfig/libasl.xcconfig +++ b/xcodeconfig/libasl.xcconfig @@ -35,3 +35,5 @@ LIBUNWIND_LDFLAGS = -lunwind OTHER_LDFLAGS = -all_load -L/usr/lib/system -umbrella System $(CR_LDFLAGS) $(LIBCOMPILER_RT_LDFLAGS) $(LIBDYLD_LDFLAGS) $(LIBSYSCALL_LDFLAGS) $(LIBPLATFORM_LDFLAGS) $(LIBPTHREAD_LDFLAGS) $(LIBMALLOC_LDFLAGS) $(LIBC_LDFLAGS) $(LIBUNWIND_LDFLAGS) $(LIBCLOSURE_LDFLAGS) -ldispatch $(LIBLAUNCH_LDFLAGS) -lxpc $(LIBTRACE_LDFLAGS) $(LIBNOTIFY_LDFLAGS) $(UPWARD_LINKS) UPWARD_LINKS = -Wl,-upward-lsystem_info + +IS_ZIPPERED = YES -- 2.45.2