Deleted Added
full compact
bsm_mask.c (185573) bsm_mask.c (186647)
1/*-
2 * Copyright (c) 2004 Apple Inc.
3 * Copyright (c) 2005 Robert N. M. Watson
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 13 unchanged lines hidden (view full) ---

22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 *
1/*-
2 * Copyright (c) 2004 Apple Inc.
3 * Copyright (c) 2005 Robert N. M. Watson
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 13 unchanged lines hidden (view full) ---

22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_mask.c#14 $
30 * $P4: //depot/projects/trustedbsd/openbsm/libbsm/bsm_mask.c#15 $
31 */
32
33#include <sys/types.h>
34
35#include <config/config.h>
36#ifdef HAVE_FULL_QUEUE_H
37#include <sys/queue.h>
38#else /* !HAVE_FULL_QUEUE_H */
39#include <compat/queue.h>
40#endif /* !HAVE_FULL_QUEUE_H */
41
42#include <bsm/libbsm.h>
43
31 */
32
33#include <sys/types.h>
34
35#include <config/config.h>
36#ifdef HAVE_FULL_QUEUE_H
37#include <sys/queue.h>
38#else /* !HAVE_FULL_QUEUE_H */
39#include <compat/queue.h>
40#endif /* !HAVE_FULL_QUEUE_H */
41
42#include <bsm/libbsm.h>
43
44#ifdef HAVE_PTHREAD_MUTEX_LOCK
44#include <pthread.h>
45#include <pthread.h>
46#endif
45#include <stdlib.h>
46#include <string.h>
47
48/* MT-Safe */
47#include <stdlib.h>
48#include <string.h>
49
50/* MT-Safe */
51#ifdef HAVE_PTHREAD_MUTEX_LOCK
49static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
52static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
53#endif
50static int firsttime = 1;
51
52/*
53 * XXX ev_cache, once created, sticks around until the calling program exits.
54 * This may or may not be a problem as far as absolute memory usage goes, but
55 * at least there don't appear to be any leaks in using the cache.
56 *
57 * XXXRW: Note that despite (mutex), load_event_table() could race with

--- 99 unchanged lines hidden (view full) ---

157{
158 struct au_event_ent *ev;
159 au_class_t effmask = 0;
160
161 if (mask_p == NULL)
162 return (-1);
163
164
54static int firsttime = 1;
55
56/*
57 * XXX ev_cache, once created, sticks around until the calling program exits.
58 * This may or may not be a problem as far as absolute memory usage goes, but
59 * at least there don't appear to be any leaks in using the cache.
60 *
61 * XXXRW: Note that despite (mutex), load_event_table() could race with

--- 99 unchanged lines hidden (view full) ---

161{
162 struct au_event_ent *ev;
163 au_class_t effmask = 0;
164
165 if (mask_p == NULL)
166 return (-1);
167
168
169#ifdef HAVE_PTHREAD_MUTEX_LOCK
165 pthread_mutex_lock(&mutex);
170 pthread_mutex_lock(&mutex);
171#endif
166 if (firsttime) {
167 firsttime = 0;
168 if ( -1 == load_event_table()) {
172 if (firsttime) {
173 firsttime = 0;
174 if ( -1 == load_event_table()) {
175#ifdef HAVE_PTHREAD_MUTEX_LOCK
169 pthread_mutex_unlock(&mutex);
176 pthread_mutex_unlock(&mutex);
177#endif
170 return (-1);
171 }
172 }
173 switch (flag) {
174 case AU_PRS_REREAD:
175 flush_cache();
176 if (load_event_table() == -1) {
178 return (-1);
179 }
180 }
181 switch (flag) {
182 case AU_PRS_REREAD:
183 flush_cache();
184 if (load_event_table() == -1) {
185#ifdef HAVE_PTHREAD_MUTEX_LOCK
177 pthread_mutex_unlock(&mutex);
186 pthread_mutex_unlock(&mutex);
187#endif
178 return (-1);
179 }
180 ev = read_from_cache(event);
181 break;
182 case AU_PRS_USECACHE:
183 ev = read_from_cache(event);
184 break;
185 default:
186 ev = NULL;
187 }
188 if (ev == NULL) {
188 return (-1);
189 }
190 ev = read_from_cache(event);
191 break;
192 case AU_PRS_USECACHE:
193 ev = read_from_cache(event);
194 break;
195 default:
196 ev = NULL;
197 }
198 if (ev == NULL) {
199#ifdef HAVE_PTHREAD_MUTEX_LOCK
189 pthread_mutex_unlock(&mutex);
200 pthread_mutex_unlock(&mutex);
201#endif
190 return (-1);
191 }
192 if (sorf & AU_PRS_SUCCESS)
193 effmask |= (mask_p->am_success & ev->ae_class);
194 if (sorf & AU_PRS_FAILURE)
195 effmask |= (mask_p->am_failure & ev->ae_class);
202 return (-1);
203 }
204 if (sorf & AU_PRS_SUCCESS)
205 effmask |= (mask_p->am_success & ev->ae_class);
206 if (sorf & AU_PRS_FAILURE)
207 effmask |= (mask_p->am_failure & ev->ae_class);
208#ifdef HAVE_PTHREAD_MUTEX_LOCK
196 pthread_mutex_unlock(&mutex);
209 pthread_mutex_unlock(&mutex);
210#endif
197 if (effmask != 0)
198 return (1);
199 return (0);
200}
211 if (effmask != 0)
212 return (1);
213 return (0);
214}