* Append individual record to a queue -- allocate queue-local buffer, and * add to the queue. If the queue is full or we can't allocate memory, drop * the newest record. */
| 458 | * the newest record. |
| 459 | */ |
| 460 | static void |
| 461 | audit_pipe_append(struct audit_pipe *ap, void *record, u_int record_len) |
| 462 | { |
| 463 | struct audit_pipe_entry *ape; |
| 464 | |
| 465 | AUDIT_PIPE_LOCK_ASSERT(ap); |
| 466 | |
| 467 | if (ap->ap_qlen >= ap->ap_qlimit) { |
| 468 | ap->ap_drops++; |
| 469 | audit_pipe_drops++; |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | ape = malloc(sizeof(*ape), M_AUDIT_PIPE_ENTRY, M_NOWAIT | M_ZERO); |
| 474 | if (ape == NULL) { |
| 475 | ap->ap_drops++; |
| 476 | audit_pipe_drops++; |
| 477 | return; |
| 478 | } |
| 479 | |
| 480 | ape->ape_record = malloc(record_len, M_AUDIT_PIPE_ENTRY, M_NOWAIT); |
| 481 | if (ape->ape_record == NULL) { |
| 482 | free(ape, M_AUDIT_PIPE_ENTRY); |
| 483 | ap->ap_drops++; |
| 484 | audit_pipe_drops++; |
| 485 | return; |
| 486 | } |
| 487 | |
| 488 | bcopy(record, ape->ape_record, record_len); |
| 489 | ape->ape_record_len = record_len; |
| 490 | |
| 491 | TAILQ_INSERT_TAIL(&ap->ap_queue, ape, ape_queue); |
| 492 | ap->ap_inserts++; |
| 493 | ap->ap_qlen++; |
| 494 | ap->ap_qbyteslen += ape->ape_record_len; |
| 495 | selwakeuppri(&ap->ap_selinfo, PSOCK); |
| 496 | KNOTE_LOCKED(&ap->ap_selinfo.si_note, 0); |
| 497 | if (ap->ap_flags & AUDIT_PIPE_ASYNC) |
| 498 | pgsigio(&ap->ap_sigio, SIGIO, 0); |
| 499 | cv_broadcast(&ap->ap_cv); |
| 500 | } |
| 501 | |
| 502 | /* |
| 503 | * audit_pipe_submit(): audit_worker submits audit records via this |
no test coverage detected