/* * This function returns a malloc'd buffer of the next record in the audit * logs. It returns 0 on success, 1 on eof, -1 on error. */ static int get_record(llist **l) { char *rc; char *buff = NULL; *l = get_ready_event(&lo); if (*l) return 0; while (1) { if (!buff) { buff = malloc(MAX_AUDIT_MESSAGE_LENGTH); if (!buff) return -1; } rc = fgets_unlocked(buff, MAX_AUDIT_MESSAGE_LENGTH, log_fd); if (rc) { if (lol_add_record(&lo, buff)) { *l = get_ready_event(&lo); if (*l) break; } } else { free(buff); if (feof_unlocked(log_fd)) { // Only mark all events complete if this is // the last file. if (files_to_process == 0) { terminate_all_events(&lo); } *l = get_ready_event(&lo); if (*l) return 0; else return 1; } else return -1; } } free(buff); return 0; }
/* * This function returns a malloc'd buffer of the next record in the audit * logs. It returns 0 on success, 1 on eof, -1 on error. */ static int get_record(llist **l) { char *rc; char *buff = NULL; *l = get_ready_event(&lo); if (*l) return 0; while (1) { if (!buff) { buff = malloc(MAX_AUDIT_MESSAGE_LENGTH); if (!buff) return -1; } rc = fgets_unlocked(buff, MAX_AUDIT_MESSAGE_LENGTH, log_fd); if (rc) { if (lol_add_record(&lo, buff)) { *l = get_ready_event(&lo); if (*l) break; } } else { free(buff); if (feof_unlocked(log_fd)) { terminate_all_events(&lo); *l = get_ready_event(&lo); if (*l) return 0; else return 1; } else return -1; } } free(buff); return 0; }