X-Git-Url: https://git.saurik.com/apple/syslog.git/blobdiff_plain/a83ff38ad0cc43a63f99b6982a830798989e73bb..f3df4c032d7a59379e2d8e1a5cf8a8f0e9ea9f63:/syslogd.tproj/bsd_in.c diff --git a/syslogd.tproj/bsd_in.c b/syslogd.tproj/bsd_in.c index fa10fd4..a1beed7 100644 --- a/syslogd.tproj/bsd_in.c +++ b/syslogd.tproj/bsd_in.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2010 Apple Inc. All rights reserved. + * Copyright (c) 2004-2011 Apple Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * @@ -21,6 +21,8 @@ * @APPLE_LICENSE_HEADER_END@ */ +#include + #include #include #include @@ -39,34 +41,47 @@ #define MAXLINE 4096 static int sock = -1; +static dispatch_source_t in_src; +static dispatch_queue_t in_queue; -aslmsg +void bsd_in_acceptmsg(int fd) { uint32_t len; int n; - char line[MAXLINE + 1]; + char line[MAXLINE]; struct sockaddr_un sun; + asl_msg_t *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, SOURCE_BSD_SOCKET); + m = asl_input_parse(line, n, NULL, SOURCE_BSD_SOCKET); + 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; + +#if TARGET_IPHONE_SIMULATOR + const char *_PATH_SYSLOG_IN = getenv("IOS_SIMULATOR_SYSLOG_SOCKET"); +#endif + + 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 (global.launch_dict == NULL) { @@ -128,7 +143,11 @@ bsd_in_init(void) return -1; } - return aslevent_addfd(SOURCE_BSD_SOCKET, sock, ADDFD_FLAGS_LOCAL, bsd_in_acceptmsg, NULL, NULL); + 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; } int @@ -136,7 +155,10 @@ bsd_in_close(void) { if (sock < 0) return 1; - aslevent_removefd(sock); + dispatch_source_cancel(in_src); + dispatch_release(in_src); + in_src = NULL; + close(sock); sock = -1;