* Insert a event to class mapping. If the event already exists in the * mapping, then replace the mapping with the new one. * * XXX There is currently no constraints placed on the number of mappings. * May want to either limit to a number, or in terms of memory usage. */
| 140 | * May want to either limit to a number, or in terms of memory usage. |
| 141 | */ |
| 142 | void |
| 143 | au_evclassmap_insert(au_event_t event, au_class_t class) |
| 144 | { |
| 145 | struct evclass_list *evcl; |
| 146 | struct evclass_elem *evc, *evc_new; |
| 147 | |
| 148 | /* |
| 149 | * Pessimistically, always allocate storage before acquiring mutex. |
| 150 | * Free if there is already a mapping for this event. |
| 151 | */ |
| 152 | evc_new = malloc(sizeof(*evc), M_AUDITEVCLASS, M_WAITOK); |
| 153 | |
| 154 | EVCLASS_WLOCK(); |
| 155 | evcl = &evclass_hash[event % EVCLASSMAP_HASH_TABLE_SIZE]; |
| 156 | LIST_FOREACH(evc, &evcl->head, entry) { |
| 157 | if (evc->event == event) { |
| 158 | evc->class = class; |
| 159 | EVCLASS_WUNLOCK(); |
| 160 | free(evc_new, M_AUDITEVCLASS); |
| 161 | return; |
| 162 | } |
| 163 | } |
| 164 | evc = evc_new; |
| 165 | evc->event = event; |
| 166 | evc->class = class; |
| 167 | LIST_INSERT_HEAD(&evcl->head, evc, entry); |
| 168 | EVCLASS_WUNLOCK(); |
| 169 | } |
| 170 | |
| 171 | void |
| 172 | au_evclassmap_init(void) |
no test coverage detected