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;
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"};
_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);
#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 -
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;
return outstatus;
}
- _asl_global_init(0);
+ _asl_global_init();
outstatus = 0;
/*
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);
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");
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)
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;
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);
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;
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;
}
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.
*/
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);
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;
}
if (kstatus != KERN_SUCCESS)
{
free(out);
- return kstatus;
+ *status = ASL_STATUS_FAILED;
+ return KERN_SUCCESS;
}
memmove(vmbuffer, out, outlen);
security_token_t *token
)
{
- return KERN_SUCCESS;
+ return KERN_FAILURE;
}
/*
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)
{
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;
}
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);
if (kstatus != KERN_SUCCESS)
{
free(url);
- return kstatus;
+ *status = ASL_STATUS_FAILED;
+ return KERN_SUCCESS;
}
memmove(vmbuffer, url, *newurlCnt);