/*
- * Copyright (c) 2013 Apple Inc. All rights reserved.
+ * Copyright (c) 2015 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
__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
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 == 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)
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 *
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);
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);
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);
#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 last;
-
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;
}
+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)
{
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);
+ client->out_list[client->out_count].tfmt = NULL;
if (tfmt != NULL) client->out_list[client->out_count].tfmt = strdup(tfmt);
client->out_count++;
}
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);
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))
{
- 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);
}
}