#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)
{
if (n == 0)
{
+ asl_client_count_decrement();
+
close(fd);
aslevent_removefd(fd);
return NULL;
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;
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);
}
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;
}
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
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;
}
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
{
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);