]> git.saurik.com Git - apple/syslog.git/blobdiff - libsystem_asl.tproj/src/asl_client.c
syslog-385.tar.gz
[apple/syslog.git] / libsystem_asl.tproj / src / asl_client.c
index 4dd77db345c98e670b1f18962fe1ffa999d13776..7aa045502834cf7eddbe15d27be5f63746a51841 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2013 Apple Inc. All rights reserved.
+ * Copyright (c) 2015 Apple Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  *
  *
  * @APPLE_LICENSE_HEADER_START@
  *
@@ -48,7 +48,7 @@
 __private_extern__ ASL_STATUS asl_file_open_write_fd(int descriptor, asl_file_t **s);
 
 /* private asl SPI */
 __private_extern__ ASL_STATUS asl_file_open_write_fd(int descriptor, asl_file_t **s);
 
 /* private asl SPI */
-__private_extern__ ASL_STATUS asl_client_internal_send(asl_object_t client, asl_object_t msg);
+__private_extern__ ASL_STATUS asl_client_internal_send(asl_object_t client, asl_object_t msg, void *addr);
 
 #pragma mark -
 #pragma mark asl_client_t
 
 #pragma mark -
 #pragma mark asl_client_t
@@ -136,6 +136,10 @@ asl_client_open(const char *ident, const char *facility, uint32_t opts)
 
        client->filter = ASL_FILTER_MASK_UPTO(ASL_LEVEL_NOTICE);
 
 
        client->filter = ASL_FILTER_MASK_UPTO(ASL_LEVEL_NOTICE);
 
+       client->filter |= EVAL_ACTIVE;
+       if (!(opts & ASL_OPT_SHIM_NO_ASL)) client->filter |= EVAL_SEND_ASL;
+       if (!(opts & ASL_OPT_SHIM_NO_TRACE)) client->filter |= EVAL_SEND_TRACE;
+       
        if (client->options & ASL_OPT_STDERR)
        {
                /* only add stderr if it is valid */
        if (client->options & ASL_OPT_STDERR)
        {
                /* only add stderr if it is valid */
@@ -161,6 +165,7 @@ asl_client_open_from_file(int descriptor, const char *ident, const char *facilit
        if (client == NULL) return NULL;
 
        client->filter = ASL_FILTER_MASK_UPTO(ASL_LEVEL_DEBUG);
        if (client == NULL) return NULL;
 
        client->filter = ASL_FILTER_MASK_UPTO(ASL_LEVEL_DEBUG);
+       client->filter |= (EVAL_ACTIVE | EVAL_SEND_ASL);
 
        status = asl_file_open_write_fd(descriptor, &(client->aslfile));
        if (status != ASL_STATUS_OK)
 
        status = asl_file_open_write_fd(descriptor, &(client->aslfile));
        if (status != ASL_STATUS_OK)
@@ -195,7 +200,7 @@ asl_client_release(asl_client_t *client)
 ASL_STATUS
 asl_client_send(asl_client_t *client, asl_msg_t *msg)
 {
 ASL_STATUS
 asl_client_send(asl_client_t *client, asl_msg_t *msg)
 {
-       return asl_client_internal_send((asl_object_t)client, (asl_object_t)msg);
+       return asl_client_internal_send((asl_object_t)client, (asl_object_t)msg, __builtin_return_address(0));
 }
 
 static asl_msg_list_t *
 }
 
 static asl_msg_list_t *
@@ -224,7 +229,7 @@ _do_server_match(asl_msg_list_t *qlist, size_t *last, size_t start, size_t count
 
        if (str == NULL) return NULL;
 
 
        if (str == NULL) return NULL;
 
-       kstatus = vm_allocate(mach_task_self(), (vm_address_t *)&vmstr, len, TRUE);
+       kstatus = vm_allocate(mach_task_self(), (vm_address_t *)&vmstr, len, VM_FLAGS_ANYWHERE | VM_MAKE_TAG(VM_MEMORY_ASL));
        if (kstatus != KERN_SUCCESS) return NULL;
 
        memmove(vmstr, str, len);
        if (kstatus != KERN_SUCCESS) return NULL;
 
        memmove(vmstr, str, len);
@@ -235,8 +240,9 @@ _do_server_match(asl_msg_list_t *qlist, size_t *last, size_t start, size_t count
        count64 = count;
 
        kstatus = _asl_server_match(asl_server_port, vmstr, len, start64, count64, duration, dir, (caddr_t *)&res, &reslen, &last64, (int *)&status);
        count64 = count;
 
        kstatus = _asl_server_match(asl_server_port, vmstr, len, start64, count64, duration, dir, (caddr_t *)&res, &reslen, &last64, (int *)&status);
-       *last = last64;
+       if (kstatus != KERN_SUCCESS) return NULL;
 
 
+       *last = last64;
        out = asl_msg_list_from_string(res);
        vm_deallocate(mach_task_self(), (vm_address_t)res, reslen);
 
        out = asl_msg_list_from_string(res);
        vm_deallocate(mach_task_self(), (vm_address_t)res, reslen);
 
@@ -274,7 +280,7 @@ _do_server_search(asl_msg_t *q)
 
        if (str == NULL) return NULL;
 
 
        if (str == NULL) return NULL;
 
-       kstatus = vm_allocate(mach_task_self(), (vm_address_t *)&vmstr, len, TRUE);
+       kstatus = vm_allocate(mach_task_self(), (vm_address_t *)&vmstr, len, VM_FLAGS_ANYWHERE | VM_MAKE_TAG(VM_MEMORY_ASL));
        if (kstatus != KERN_SUCCESS) return NULL;
 
        memmove(vmstr, str, len);
        if (kstatus != KERN_SUCCESS) return NULL;
 
        memmove(vmstr, str, len);
@@ -367,18 +373,40 @@ asl_client_search(asl_client_t *client, asl_msg_t *query)
 #pragma mark -
 #pragma mark output control
 
 #pragma mark -
 #pragma mark output control
 
-/* returns last filter value, or -1 on error */
+/*
+ * Returns last filter value, or -1 on error.
+ * Note that this allows ASL_FILTER_MASK_TUNNEL (0x100) to be set.
+ * That is SPI that's used by some clients.
+ */
 int
 asl_client_set_filter(asl_client_t *client, int filter)
 {
 int
 asl_client_set_filter(asl_client_t *client, int filter)
 {
-       int last;
-
        if (client == NULL) return -1;
        if (client == NULL) return -1;
-       last = client->filter;
+
+       uint32_t allbits = client->filter;
+       int last = allbits & (~EVAL_ACTION_MASK);
+       client->filter = (allbits & EVAL_ACTION_MASK) | (filter & (~EVAL_ACTION_MASK));
+       return last;
+}
+
+/* SPI */
+uint32_t
+asl_client_set_control(asl_client_t *client, uint32_t filter)
+{
+       if (client == NULL) return UINT32_MAX;
+
+       uint32_t last = client->filter;
        client->filter = filter;
        return last;
 }
 
        client->filter = filter;
        return last;
 }
 
+uint32_t
+asl_client_get_control(asl_client_t *client)
+{
+       if (client == NULL) return UINT32_MAX;
+       return client->filter;
+}
+
 ASL_STATUS
 asl_client_add_output_file(asl_client_t *client, int descriptor, const char *mfmt, const char *tfmt, int filter, int text_encoding)
 {
 ASL_STATUS
 asl_client_add_output_file(asl_client_t *client, int descriptor, const char *mfmt, const char *tfmt, int filter, int text_encoding)
 {
@@ -414,7 +442,9 @@ asl_client_add_output_file(asl_client_t *client, int descriptor, const char *mfm
        client->out_list[client->out_count].fd = descriptor;
        client->out_list[client->out_count].encoding = text_encoding;
        client->out_list[client->out_count].filter = filter;
        client->out_list[client->out_count].fd = descriptor;
        client->out_list[client->out_count].encoding = text_encoding;
        client->out_list[client->out_count].filter = filter;
+       client->out_list[client->out_count].mfmt = NULL;
        if (mfmt != NULL) client->out_list[client->out_count].mfmt = strdup(mfmt);
        if (mfmt != NULL) client->out_list[client->out_count].mfmt = strdup(mfmt);
+       client->out_list[client->out_count].tfmt = NULL;
        if (tfmt != NULL) client->out_list[client->out_count].tfmt = strdup(tfmt);
 
        client->out_count++;
        if (tfmt != NULL) client->out_list[client->out_count].tfmt = strdup(tfmt);
 
        client->out_count++;
@@ -516,7 +546,7 @@ _jump_dealloc(asl_object_private_t *obj)
 }
 
 static void
 }
 
 static void
-_jump_append(asl_object_private_t *obj, asl_object_private_t *newobj)
+_jump_append(asl_object_private_t *obj, asl_object_private_t *newobj, void *addr)
 {
        int type = asl_get_type((asl_object_t)newobj);
 
 {
        int type = asl_get_type((asl_object_t)newobj);
 
@@ -526,12 +556,12 @@ _jump_append(asl_object_private_t *obj, asl_object_private_t *newobj)
                asl_msg_list_reset_iteration((asl_msg_list_t *)newobj, 0);
                while (NULL != (msg = asl_msg_list_next((asl_msg_list_t *)newobj)))
                {
                asl_msg_list_reset_iteration((asl_msg_list_t *)newobj, 0);
                while (NULL != (msg = asl_msg_list_next((asl_msg_list_t *)newobj)))
                {
-                       if (asl_client_internal_send((asl_object_t)obj, (asl_object_t)msg) != ASL_STATUS_OK) return;
+                       if (asl_client_internal_send((asl_object_t)obj, (asl_object_t)msg, addr) != ASL_STATUS_OK) return;
                }
        }
        else if ((type == ASL_TYPE_MSG) || (type == ASL_TYPE_QUERY))
        {
                }
        }
        else if ((type == ASL_TYPE_MSG) || (type == ASL_TYPE_QUERY))
        {
-               asl_client_internal_send((asl_object_t)obj, (asl_object_t)newobj);
+               asl_client_internal_send((asl_object_t)obj, (asl_object_t)newobj, addr);
        }
 }
 
        }
 }