MCPcopy Create free account
hub / github.com/F-Stack/f-stack / audit_worker

Function audit_worker

freebsd/security/audit/audit_worker.c:437–481  ·  view source on GitHub ↗

* The audit_worker thread is responsible for watching the event queue, * dequeueing records, converting them to BSM format, and committing them to * disk. In order to minimize lock thrashing, records are dequeued in sets * to a thread-local work queue. * * Note: this means that the effect bound on the size of the pending record * queue is 2x the length of the global queue. */

Source from the content-addressed store, hash-verified

435 * queue is 2x the length of the global queue.
436 */
437static void
438audit_worker(void *arg)
439{
440 struct kaudit_queue ar_worklist;
441 struct kaudit_record *ar;
442 int lowater_signal;
443
444 TAILQ_INIT(&ar_worklist);
445 mtx_lock(&audit_mtx);
446 while (1) {
447 mtx_assert(&audit_mtx, MA_OWNED);
448
449 /*
450 * Wait for a record.
451 */
452 while (TAILQ_EMPTY(&audit_q))
453 cv_wait(&audit_worker_cv, &audit_mtx);
454
455 /*
456 * If there are records in the global audit record queue,
457 * transfer them to a thread-local queue and process them
458 * one by one. If we cross the low watermark threshold,
459 * signal any waiting processes that they may wake up and
460 * continue generating records.
461 */
462 lowater_signal = 0;
463 while ((ar = TAILQ_FIRST(&audit_q))) {
464 TAILQ_REMOVE(&audit_q, ar, k_q);
465 audit_q_len--;
466 if (audit_q_len == audit_qctrl.aq_lowater)
467 lowater_signal++;
468 TAILQ_INSERT_TAIL(&ar_worklist, ar, k_q);
469 }
470 if (lowater_signal)
471 cv_broadcast(&audit_watermark_cv);
472
473 mtx_unlock(&audit_mtx);
474 while ((ar = TAILQ_FIRST(&ar_worklist))) {
475 TAILQ_REMOVE(&ar_worklist, ar, k_q);
476 audit_worker_process_record(ar);
477 audit_free(ar);
478 }
479 mtx_lock(&audit_mtx);
480 }
481}
482
483/*
484 * audit_rotate_vnode() is called by a user or kernel thread to configure or

Callers

nothing calls this directly

Calls 7

mtx_assertFunction · 0.85
cv_waitFunction · 0.85
cv_broadcastFunction · 0.85
audit_freeFunction · 0.85
mtx_lockFunction · 0.50
mtx_unlockFunction · 0.50

Tested by

no test coverage detected