X-Git-Url: https://git.saurik.com/apple/syslog.git/blobdiff_plain/57b0aad2c678a02fcc3e8b5756d4a13d9061babf..e125da38929cd700d1ef4f2d364c6fbcbb2247cc:/syslogd.tproj/asl_in.c diff --git a/syslogd.tproj/asl_in.c b/syslogd.tproj/asl_in.c index d62be08..1bd0883 100644 --- a/syslogd.tproj/asl_in.c +++ b/syslogd.tproj/asl_in.c @@ -37,19 +37,9 @@ #define forever for(;;) #define ASL_SOCKET_NAME "AppleSystemLogger" -#define MY_ID "asl" +#define MY_ID "asl_in" static int sock = -1; -static asl_msg_t *query = NULL; - -#define MATCH_EOF -1 -#define MATCH_NULL 0 -#define MATCH_TRUE 1 -#define MATCH_FALSE 2 - -extern void db_enqueue(asl_msg_t *m); - -static int filter_token = -1; asl_msg_t * asl_in_getmsg(int fd) @@ -67,6 +57,8 @@ asl_in_getmsg(int fd) { if (n == 0) { + asl_client_count_decrement(); + close(fd); aslevent_removefd(fd); return NULL; @@ -77,6 +69,8 @@ asl_in_getmsg(int fd) asldebug("%s: read error (len=%d): %s\n", MY_ID, n, strerror(errno)); if (errno != EINTR) { + asl_client_count_decrement(); + close(fd); aslevent_removefd(fd); return NULL; @@ -100,6 +94,8 @@ asl_in_getmsg(int fd) asldebug("%s: read error (body): %s\n", MY_ID, strerror(errno)); if (errno != EINTR) { + asl_client_count_decrement(); + close(fd); aslevent_removefd(fd); free(out); @@ -132,15 +128,15 @@ asl_in_getmsg(int fd) } asl_msg_t * -asl_in_acceptmsg(int fd) +asl_in_new_connection(int fd) { int clientfd; - asldebug("%s: accepting message\n", MY_ID); + asldebug("%s: accepting connection\n", MY_ID); clientfd = accept(fd, NULL, 0); if (clientfd < 0) { - asldebug("%s: error accepting socket fd %d: %s\n", MY_ID, fd, strerror(errno)); + asldebug("%s: error connecting socket fd %d: %s\n", MY_ID, fd, strerror(errno)); return NULL; } @@ -152,78 +148,10 @@ asl_in_acceptmsg(int fd) return NULL; } - aslevent_addfd(clientfd, ADDFD_FLAGS_LOCAL, asl_in_getmsg, NULL, NULL); - return NULL; -} - -int -aslmod_sendmsg(asl_msg_t *msg, const char *outid) -{ - const char *vlevel, *facility, *sender, *ignore; - uint32_t lmask; - uint64_t v64; - int status, x, level, log_me; + asl_client_count_increment(); - /* set up com.apple.syslog.asl_filter */ - if (filter_token == -1) - { - status = notify_register_check(NOTIFY_SYSTEM_ASL_FILTER, &filter_token); - if (status != NOTIFY_STATUS_OK) - { - filter_token = -1; - } - else - { - status = notify_check(filter_token, &x); - if (status == NOTIFY_STATUS_OK) - { - v64 = global.asl_log_filter; - status = notify_set_state(filter_token, v64); - } - if (status != NOTIFY_STATUS_OK) - { - notify_cancel(filter_token); - filter_token = -1; - } - } - } - - if (filter_token >= 0) - { - x = 0; - status = notify_check(filter_token, &x); - if ((status == NOTIFY_STATUS_OK) && (x == 1)) - { - v64 = 0; - status = notify_get_state(filter_token, &v64); - if ((status == NOTIFY_STATUS_OK) && (v64 != 0)) global.asl_log_filter = v64; - } - } - - facility = asl_get(msg, ASL_KEY_FACILITY); - sender = asl_get(msg, ASL_KEY_SENDER); - - log_me = 0; - if ((facility != NULL) && (!strcmp(facility, "kern"))) log_me = 1; - else if ((sender != NULL) && (!strcmp(sender, "launchd"))) log_me = 1; - else - { - vlevel = asl_get(msg, ASL_KEY_LEVEL); - level = 7; - if (vlevel != NULL) level = atoi(vlevel); - lmask = ASL_FILTER_MASK(level); - if ((lmask & global.asl_log_filter) != 0) log_me = 1; - } - - if (log_me == 1) - { - ignore = asl_get(msg, ASL_KEY_IGNORE); - if ((ignore != NULL) && (!strcasecmp(ignore, "yes"))) log_me = 0; - } - - if (log_me == 1) db_enqueue(msg); - - return 0; + aslevent_addfd(SOURCE_ASL_SOCKET, clientfd, ADDFD_FLAGS_LOCAL, asl_in_getmsg, NULL, NULL); + return NULL; } int @@ -237,40 +165,40 @@ asl_in_init(void) if (sock >= 0) return sock; 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(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, ASL_SOCKET_NAME); if (fd_array == NULL) { - asldebug("%s: laucnchd lookup of ASL_SOCKET_NAME failed\n", MY_ID); + asldebug("%s: launchd lookup of ASL_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; } @@ -295,11 +223,7 @@ asl_in_init(void) return -1; } - query = asl_new(ASL_TYPE_QUERY); - aslevent_addmatch(query, MY_ID); - aslevent_addoutput(aslmod_sendmsg, MY_ID); - - return aslevent_addfd(sock, ADDFD_FLAGS_LOCAL, asl_in_acceptmsg, NULL, NULL); + return aslevent_addfd(SOURCE_ASL_SOCKET, sock, ADDFD_FLAGS_LOCAL, asl_in_new_connection, NULL, NULL); } int @@ -313,11 +237,6 @@ asl_in_close(void) { if (sock < 0) return 1; - if (filter_token >= 0) notify_cancel(filter_token); - filter_token = -1; - global.asl_log_filter = 0; - - asl_free(query); close(sock); unlink(_PATH_ASL_IN);