#include #include #include #include #include #include #include #include #include #include #include "libaudit.h" #include "auparse.h" /* Global Data */ static auparse_state_t *au = NULL; /* Local declarations */ static void handle_event(auparse_state_t *au, auparse_cb_event_t cb_event_type, void *user_data); int main(int argc, char *argv[]) { char tmp[MAX_AUDIT_MESSAGE_LENGTH+1]; /* Initialize the auparse library */ au = auparse_init(AUSOURCE_FEED, 0); if (au == NULL) { return -1; } auparse_add_callback(au, handle_event, NULL, NULL); do { fd_set read_mask; struct timeval tv; int retval; do { tv.tv_sec = 5; tv.tv_usec = 0; FD_ZERO(&read_mask); FD_SET(0, &read_mask); retval= select(1, &read_mask, NULL, NULL, &tv); } while (retval == -1 && errno == EINTR); /* Now the event loop */ if (retval > 0) { if (fgets_unlocked(tmp, MAX_AUDIT_MESSAGE_LENGTH, stdin)){ auparse_feed(au, tmp, strnlen(tmp, MAX_AUDIT_MESSAGE_LENGTH)); } } else if (retval == 0) auparse_flush_feed(au); if (feof(stdin)) break; } while (1); /* Flush any accumulated events from queue */ auparse_flush_feed(au); auparse_destroy(au); return 0; } static void handle_event(auparse_state_t *au, auparse_cb_event_t cb_event_type, void *user_data) { return; }