static void start_next_op(opq_t *opq) { ilist_iter_t iter; opq_elem_t *elem; int success; ilist_init_iter(&iter, opq->ops); ilist_first(&iter); elem = ilist_get(&iter); while (elem) { ilist_delete(&iter); opq->done_handler = elem->done; opq->done_data = elem->done_data; opq_unlock(opq); success = elem->handler(elem->handler_data, 0); opq_free_elem(elem); opq_lock(opq); if (success == OPQ_HANDLER_STARTED) break; ilist_first(&iter); elem = ilist_get(&iter); } if (!elem) opq->in_handler = 0; }
void opq_op_done(opq_t *opq) { ilist_iter_t iter; opq_elem_t *elem; opq_elem_t *list = NULL; opq_elem_t *next; opq_elem_t **list_end = &list; opq_done_cb done_handler; void *done_data; /* First check for done handlers. */ opq_lock(opq); ilist_init_iter(&iter, opq->ops); ilist_first(&iter); elem = ilist_get(&iter); while (elem && (!elem->block)) { ilist_delete(&iter); elem->next = NULL; *list_end = elem; list_end = &(elem->next); elem = ilist_get(&iter); } done_handler = opq->done_handler; done_data = opq->done_data; opq->done_handler = NULL; if (done_handler || list) { /* There are done handlers to call, unlock and call them. */ opq_unlock(opq); if (done_handler) done_handler(done_data, 0); while (list) { next = list->next; list->done(list->done_data, 0); opq_free_elem(list); list = next; } opq_lock(opq); /* During the time we were unlocked, handlers may have been added. */ ilist_first(&iter); elem = ilist_get(&iter); } start_next_op(opq); opq_unlock(opq); }
int main(void) { int i = 0; ilist e; int_node *node; ilist_create(&e); ilist_add_if_uniq(&e, 6, 0); ilist_add_if_uniq(&e, 5, 0); ilist_add_if_uniq(&e, 7, 0); ilist_add_if_uniq(&e, 1, 0); ilist_add_if_uniq(&e, 8, 0); ilist_add_if_uniq(&e, 2, 0); ilist_add_if_uniq(&e, 9, 0); ilist_add_if_uniq(&e, 0, 0); ilist_add_if_uniq(&e, 4, 0); ilist_add_if_uniq(&e, 3, 0); ilist_first(&e); do { node = ilist_get_cur(&e); if (i != node->num) { printf("Test failed - i:%d != num:%d\n", i, node->num); return 1; } i++; } while ((node = ilist_next(&e))); ilist_clear(&e); printf("ilist test passed\n"); return 0; }
static void do_int_summary_output(ilist *sptr) { const int_node *in; if (sptr->cnt == 0) { printf("<no events of interest were found>\n\n"); return; } ilist_first(sptr); in=ilist_get_cur(sptr); while (in) { printf("%u %d\n", in->hits, in->num); in=ilist_next(sptr); } }
static void do_type_summary_output(ilist *sptr) { const int_node *in; if (sptr->cnt == 0) { printf("<no events of interest were found>\n\n"); return; } ilist_first(sptr); in=ilist_get_cur(sptr); while (in) { const char *name = audit_msg_type_to_name(in->num); if (report_format == RPT_DEFAULT) printf("%u %d\n", in->hits, in->num); else printf("%u %s\n", in->hits, name); in=ilist_next(sptr); } }
int main(void) { int i = 0; ilist e; int_node *node; ilist_create(&e); // This first test checks to see if list is // created in a numeric order ilist_add_if_uniq(&e, 6, 0); ilist_add_if_uniq(&e, 5, 0); ilist_add_if_uniq(&e, 7, 0); ilist_add_if_uniq(&e, 1, 0); ilist_add_if_uniq(&e, 8, 0); ilist_add_if_uniq(&e, 2, 0); ilist_add_if_uniq(&e, 9, 0); ilist_add_if_uniq(&e, 0, 0); ilist_add_if_uniq(&e, 4, 0); ilist_add_if_uniq(&e, 3, 0); ilist_first(&e); do { node = ilist_get_cur(&e); if (i != node->num) { printf("Test failed - i:%d != num:%d\n", i, node->num); return 1; } i++; } while ((node = ilist_next(&e))); ilist_clear(&e); puts("starting sort test"); // Now test to see if the sort function works // Fill the list exactly backwards ilist_add_if_uniq(&e, 3, 0); ilist_add_if_uniq(&e, 3, 0); ilist_add_if_uniq(&e, 4, 0); ilist_add_if_uniq(&e, 3, 0); ilist_add_if_uniq(&e, 4, 0); ilist_add_if_uniq(&e, 2, 0); ilist_add_if_uniq(&e, 4, 0); ilist_add_if_uniq(&e, 2, 0); ilist_add_if_uniq(&e, 4, 0); ilist_add_if_uniq(&e, 1, 0); ilist_sort_by_hits(&e); i = 0; ilist_first(&e); do { node = ilist_get_cur(&e); if (node->hits != (4-i)) { printf("Sort test failed - i:%d != ihits:%d\n", i, node->hits); return 1; } i++; } while ((node = ilist_next(&e))); ilist_clear(&e); printf("ilist tests passed\n"); return 0; }
int match(llist *l) { // Are we within time range? if (start_time == 0 || l->e.sec >= start_time) { if (end_time == 0 || l->e.sec <= end_time) { if (event_id == -1 || event_id == l->e.serial) { // OK - do the heavier checking if (extract_search_items(l)) { return 0; } // perform additional tests for the field if (event_node_list) { const snode *sn; int found=0; slist *sptr = event_node_list; if (l->e.node == NULL) return 0; slist_first(sptr); sn=slist_get_cur(sptr); while (sn && !found) { if (sn->str && (!strcmp(sn->str, l->e.node))) found++; else sn=slist_next(sptr); } if (!found) return 0; } if (user_match(l) == 0) return 0; if (group_match(l) == 0) return 0; if ((event_ppid != -1) && (event_ppid != l->s.ppid)) return 0; if ((event_pid != -1) && (event_pid != l->s.pid)) return 0; if (event_machine != -1 && (event_machine != audit_elf_to_machine(l->s.arch))) return 0; if ((event_syscall != -1) && (event_syscall != l->s.syscall)) return 0; if ((event_session_id != -2) && (event_session_id != l->s.session_id)) return 0; if (event_exit_is_set) { if (l->s.exit_is_set == 0) return 0; if (event_exit != l->s.exit) return 0; } if ((event_success != S_UNSET) && (event_success != l->s.success)) return 0; // event_type requires looking at each item if (event_type != NULL) { int found = 0; const lnode *n; list_first(l); n = list_get_cur(l); do { int_node *in; ilist_first(event_type); in = ilist_get_cur(event_type); do { if (in->num == n->type){ found = 1; break; } } while((in = ilist_next(event_type))); if (found) break; } while ((n = list_next(l))); if (!found) return 0; } // Done all the easy compares, now do the // string searches. if (event_filename) { int found = 0; if (l->s.filename == NULL && l->s.cwd == NULL) return 0; if (l->s.filename) { const snode *sn; slist *sptr = l->s.filename; slist_first(sptr); sn=slist_get_cur(sptr); do { if (sn->str == NULL) return 0; if (strmatch( event_filename, sn->str)) { found = 1; break; } } while ((sn=slist_next(sptr))); if (!found && l->s.cwd == NULL) return 0; } if (l->s.cwd && !found) { /* Check cwd, too */ if (strmatch(event_filename, l->s.cwd) == 0) return 0; } } if (event_hostname) { if (l->s.hostname == NULL) return 0; if (strmatch(event_hostname, l->s.hostname) == 0) return 0; } if (event_terminal) { if (l->s.terminal == NULL) return 0; if (strmatch(event_terminal, l->s.terminal) == 0) return 0; } if (event_exe) { if (l->s.exe == NULL) return 0; if (strmatch(event_exe, l->s.exe) == 0) return 0; } if (event_comm) { if (l->s.comm == NULL) return 0; if (strmatch(event_comm, l->s.comm) == 0) return 0; } if (event_key) { if (l->s.key == NULL) return 0; else { int found = 0; const snode *sn; slist *sptr = l->s.key; slist_first(sptr); sn=slist_get_cur(sptr); do { if (sn->str == NULL) return 0; if (strmatch( event_key, sn->str)) { found = 1; break; } } while ((sn=slist_next(sptr))); if (!found) return 0; } } if (event_vmname) { if (l->s.vmname == NULL) return 0; if (strmatch(event_vmname, l->s.vmname) == 0) return 0; } if (event_uuid) { if (l->s.uuid == NULL) return 0; if (strmatch(event_uuid, l->s.uuid) == 0) return 0; } if (context_match(l) == 0) return 0; return 1; } } } return 0; }