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.
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.
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]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
37 extern FILE *__auditd_debug_file_open();
38 #define DPRINT(x) { (void) fprintf x; }
44 audit_queue_init(au_queue_t
*q
)
48 (void) pthread_mutex_init(&q
->auq_lock
, NULL
);
52 dbfp
= __auditd_debug_file_open();
58 * enqueue() caller creates queue entry
62 audit_enqueue(au_queue_t
*q
, void *p
)
64 (void) pthread_mutex_lock(&q
->auq_lock
);
66 DPRINT((dbfp
, "enqueue0(%p): p=%p, head=%p, tail=%p, count=%d\n",
67 (void *)q
, (void *)p
, (void *)q
->auq_head
, (void *)q
->auq_tail
,
70 if (q
->auq_head
== NULL
)
73 DPRINT((dbfp
, "\tindirect tail=%p\n",
74 (void *)&(((audit_link_t
*)(q
->auq_tail
))->aln_next
)));
76 ((audit_link_t
*)(q
->auq_tail
))->aln_next
= p
;
79 ((audit_link_t
*)p
)->aln_next
= NULL
;
82 DPRINT((dbfp
, "enqueue1(%p): p=%p, head=%p, tail=%p, "
83 "count=%d, pnext=%p\n", (void *)q
, (void *)p
, (void *)q
->auq_head
,
84 (void *)q
->auq_tail
, q
->auq_count
,
85 (void *)((audit_link_t
*)p
)->aln_next
));
87 (void) pthread_mutex_unlock(&q
->auq_lock
);
91 * audit_dequeue() returns entry; caller is responsible for free
95 audit_dequeue(au_queue_t
*q
, void **p
)
97 (void) pthread_mutex_lock(&q
->auq_lock
);
99 if ((*p
= q
->auq_head
) == NULL
) {
100 DPRINT((dbfp
, "dequeue1(%p): p=%p, head=%p, "
101 "tail=%p, count=%d\n", (void *)q
, (void *)*p
,
102 (void *)q
->auq_head
, (void *)q
->auq_tail
, q
->auq_count
));
104 (void) pthread_mutex_unlock(&q
->auq_lock
);
109 /* if *p is the last, next is NULL */
110 q
->auq_head
= ((audit_link_t
*)*p
)->aln_next
;
112 DPRINT((dbfp
, "dequeue0(%p): p=%p, head=%p, tail=%p, "
113 "count=%d, pnext=%p\n", (void *)q
, (void *)*p
, (void *)q
->auq_head
,
114 (void *)q
->auq_tail
, q
->auq_count
,
115 (void *)((audit_link_t
*)*p
)->aln_next
));
117 (void) pthread_mutex_unlock(&q
->auq_lock
);
122 * increment ref count
125 audit_incr_ref(pthread_mutex_t
*l
, audit_rec_t
*p
)
127 (void) pthread_mutex_lock(l
);
129 DPRINT((dbfp
, "incr_ref: p=%p, count=%d\n",
130 (void *)p
, p
->abq_ref_count
));
131 (void) pthread_mutex_unlock(l
);
134 * decrement reference count; if it reaches zero,
135 * return a pointer to it. Otherwise, return NULL.
138 audit_release(pthread_mutex_t
*l
, audit_rec_t
*p
)
142 (void) pthread_mutex_lock(l
);
144 DPRINT((dbfp
, "release: p=%p , count=%d\n",
145 (void *)p
, p
->abq_ref_count
));
147 if (--(p
->abq_ref_count
) > 0) {
148 (void) pthread_mutex_unlock(l
);
151 (void) pthread_mutex_unlock(l
);
157 audit_queue_size(au_queue_t
*q
)
161 (void) pthread_mutex_lock(&q
->auq_lock
);
163 (void) pthread_mutex_unlock(&q
->auq_lock
);
170 audit_queue_destroy(au_queue_t
*q
)
172 (void) pthread_mutex_destroy(&q
->auq_lock
);