X-Git-Url: https://git.saurik.com/apple/syslog.git/blobdiff_plain/5dd30d768c7cd795c2a3b974a6a1809dd8a3becf..db78b1bd5c8e2c516f88095d137ca8751a0f734b:/syslogd.tproj/bsd_in.c diff --git a/syslogd.tproj/bsd_in.c b/syslogd.tproj/bsd_in.c index 75727fb..7595f9c 100644 --- a/syslogd.tproj/bsd_in.c +++ b/syslogd.tproj/bsd_in.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2004-2011 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -39,71 +39,80 @@ #define MAXLINE 4096 static int sock = -1; +static dispatch_source_t in_src; +static dispatch_queue_t in_queue; -asl_msg_t * +void bsd_in_acceptmsg(int fd) { uint32_t len; int n; - char line[MAXLINE + 1]; + char line[MAXLINE]; struct sockaddr_un sun; + aslmsg m; len = sizeof(struct sockaddr_un); n = recvfrom(fd, line, MAXLINE, 0, (struct sockaddr *)&sun, &len); - if (n <= 0) return NULL; + if (n <= 0) return; line[n] = '\0'; - return asl_input_parse(line, n, NULL, 0); + m = asl_input_parse(line, n, NULL, SOURCE_BSD_SOCKET); + dispatch_async(global.work_queue, ^{ process_message(m, SOURCE_BSD_SOCKET); }); } int -bsd_in_init(void) +bsd_in_init() { int rbufsize; int len; launch_data_t sockets_dict, fd_array, fd_dict; + static dispatch_once_t once; + + dispatch_once(&once, ^{ + in_queue = dispatch_queue_create(MY_ID, NULL); + }); asldebug("%s: init\n", MY_ID); - if (sock >= 0) return sock; + if (sock >= 0) return -1; - if (launch_dict == NULL) + if (global.launch_dict == NULL) { - asldebug("%s: laucnchd dict is NULL\n", MY_ID); + asldebug("%s: launchd dict is NULL\n", MY_ID); return -1; } - sockets_dict = launch_data_dict_lookup(launch_dict, LAUNCH_JOBKEY_SOCKETS); + sockets_dict = launch_data_dict_lookup(global.launch_dict, LAUNCH_JOBKEY_SOCKETS); if (sockets_dict == NULL) { - asldebug("%s: laucnchd lookup of LAUNCH_JOBKEY_SOCKETS failed\n", MY_ID); + asldebug("%s: launchd lookup of LAUNCH_JOBKEY_SOCKETS failed\n", MY_ID); return -1; } fd_array = launch_data_dict_lookup(sockets_dict, BSD_SOCKET_NAME); if (fd_array == NULL) { - asldebug("%s: laucnchd lookup of BSD_SOCKET_NAME failed\n", MY_ID); + asldebug("%s: launchd lookup of BSD_SOCKET_NAME failed\n", MY_ID); return -1; } len = launch_data_array_get_count(fd_array); if (len <= 0) { - asldebug("%s: laucnchd fd array is empty\n", MY_ID); + asldebug("%s: launchd fd array is empty\n", MY_ID); return -1; } if (len > 1) { - asldebug("%s: warning! laucnchd fd array has %d sockets\n", MY_ID, len); + asldebug("%s: warning! launchd fd array has %d sockets\n", MY_ID, len); } fd_dict = launch_data_array_get_index(fd_array, 0); if (fd_dict == NULL) { - asldebug("%s: laucnchd file discriptor array element 0 is NULL\n", MY_ID); + asldebug("%s: launchd file discriptor array element 0 is NULL\n", MY_ID); return -1; } @@ -128,12 +137,10 @@ bsd_in_init(void) return -1; } - return aslevent_addfd(sock, ADDFD_FLAGS_LOCAL, bsd_in_acceptmsg, NULL, NULL); -} - -int -bsd_in_reset(void) -{ + in_src = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, (uintptr_t)sock, 0, in_queue); + dispatch_source_set_event_handler(in_src, ^{ bsd_in_acceptmsg(sock); }); + + dispatch_resume(in_src); return 0; } @@ -142,7 +149,18 @@ bsd_in_close(void) { if (sock < 0) return 1; + dispatch_source_cancel(in_src); + dispatch_release(in_src); + in_src = NULL; + close(sock); - unlink(_PATH_SYSLOG_IN); + sock = -1; + + return 0; +} + +int +bsd_in_reset(void) +{ return 0; }