]> git.saurik.com Git - apple/syslog.git/commitdiff
syslog-356.200.4.tar.gz macos-1014 macos-10141 macos-10142 macos-10143 macos-10144 macos-10145 macos-10146 v356.200.4
authorApple <opensource@apple.com>
Thu, 5 Jul 2018 18:32:40 +0000 (18:32 +0000)
committerApple <opensource@apple.com>
Thu, 5 Jul 2018 18:32:40 +0000 (18:32 +0000)
libsystem_asl.tproj/src/asl.c
libsystem_asl.tproj/src/asl_core.c
syslogd.tproj/com.apple.syslogd.plist
syslogd.tproj/com.apple.syslogd_sim.plist
syslogd.tproj/dbserver.c
xcodeconfig/libasl.xcconfig

index 8e4777ee97a7c51ffff546d89a866b295d513446..027516e0590c64aa2ea46cfcda8dd08f0ecea37f 100644 (file)
@@ -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;
 }
index 30de51b989b2446f9149e321cdbafb9ec8bc4306..fd589b4cc5652f3930a2fe746e5df662caa2d08f 100644 (file)
@@ -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.
  */
index 05ab013451369fb72dfb09427f1e51c0dce7a976..bd9c2b7839714147667093b0eb99fee3a407ef22 100644 (file)
        <key>MachServices</key>
        <dict>
                <key>com.apple.system.logger</key>
-               <dict>
-                       <key>ResetAtClose</key>
-                       <true/>
-               </dict>
+               <true/>
        </dict>
        <key>Sockets</key>
        <dict>
index 4c7d9a22dead6d2ac7f633982ed9e651ef7f972a..2a37fbac81c0b201f184e471dfd0680e084954a9 100644 (file)
        <key>MachServices</key>
        <dict>
                <key>com.apple.system.logger</key>
-               <dict>
-                       <key>ResetAtClose</key>
-                       <true/>
-               </dict>
+               <true/>
        </dict>
        <key>Sockets</key>
        <dict>
index 7c355b62c1c17b26654bd189fa9e7c0d2b6af24f..43152902a9b618a18cb29c02492414a13d843bd3 100644 (file)
@@ -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);
index 82e61226bde6b3260bb5ce90dcd2d0a6e3e18bcd..d55394edb0debaff6425d024fdc30516e95e1626 100644 (file)
@@ -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