xref: /illumos-gate/usr/src/cmd/auditd/queue.h (revision a386cc11a86ecb60f5a48078d22c1500e2ad003e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  *
25  */
26 
27 #ifndef	_QUEUE_H
28 #define	_QUEUE_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <pthread.h>
35 #include <stddef.h>
36 
37 typedef struct aln audit_link_t;
38 struct aln {
39 	audit_link_t	*aln_next;
40 };
41 
42 /* one audit_rec_t per audit record */
43 
44 typedef struct abq audit_rec_t;
45 struct abq {
46 	audit_link_t	abq_l;
47 	int		abq_ref_count;
48 	size_t		abq_buf_len;	/* space allocated */
49 	size_t		abq_data_len;	/* space used	   */
50 	char		abq_buffer[1];	/* variable length */
51 };
52 #define	AUDIT_REC_HEADER  offsetof(audit_rec_t, abq_buffer[0])
53 
54 /* one audit_q_t entry per audit record per plugin */
55 
56 typedef struct aqq audit_q_t;		/* plugin queued data */
57 struct aqq {
58 	audit_link_t	aqq_l;
59 	audit_rec_t	*aqq_data;
60 	uint64_t	aqq_sequence;
61 };
62 
63 /* queue head */
64 
65 typedef struct auq au_queue_t;
66 
67 struct auq {
68 	void		*auq_head;
69 	void		*auq_tail;
70 	int		auq_count;
71 	pthread_mutex_t	auq_lock;
72 };
73 
74 int		audit_dequeue(au_queue_t *, void **);
75 void		audit_queue_destroy(au_queue_t *);
76 void		audit_enqueue(au_queue_t *, void *);
77 int		audit_queue_size(au_queue_t *);
78 void		audit_queue_init(au_queue_t *);
79 audit_rec_t	*audit_release(pthread_mutex_t *, audit_rec_t *);
80 void		audit_incr_ref(pthread_mutex_t *, audit_rec_t *);
81 
82 #ifdef __cplusplus
83 }
84 #endif
85 
86 #endif	/* _QUEUE_H */
87