Print this page
5218 posix definition of NULL
correct unistd.h and iso/stddef_iso.h
update gate source affected
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/syseventd/modules/sysevent_reg_mod/sysevent_reg_mod.c
+++ new/usr/src/cmd/syseventd/modules/sysevent_reg_mod/sysevent_reg_mod.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22 /*
23 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 #pragma ident "%Z%%M% %I% %E% SMI"
28 28
29 29 #include <unistd.h>
30 30 #include <stdlib.h>
31 31 #include <string.h>
32 32 #include <strings.h>
33 33 #include <stdio.h>
34 34 #include <limits.h>
35 35 #include <thread.h>
36 36 #include <wait.h>
37 37 #include <synch.h>
38 38 #include <errno.h>
39 39 #include <locale.h>
40 40 #include <sys/stat.h>
41 41 #include <sys/mnttab.h>
42 42 #include <sys/sunddi.h>
43 43 #include <sys/modctl.h>
44 44 #include <sys/sysevent.h>
45 45 #include <sys/sysevent_impl.h>
46 46
47 47 #include <libsysevent.h>
48 48
49 49 #include "message_reg_mod.h"
50 50
51 51 /*
52 52 * SLM for sysevent event subscribers
53 53 */
54 54
55 55 extern char *root_dir;
56 56 extern void syseventd_print(int level, char *format, ...);
57 57 extern void syseventd_err_print(char *format, ...);
58 58
59 59 sysevent_handle_t *sysevent_hp;
60 60
61 61 typedef struct ev_queue {
62 62 struct ev_queue *evq_next;
63 63 sysevent_t *evq_ev;
64 64 } ev_queue_t;
65 65
66 66 static mutex_t evq_lock;
67 67 static cond_t evq_cv;
68 68 static ev_queue_t *event_q = NULL;
69 69 static int cleanup;
70 70 static thread_t deliver_thr_id;
71 71
72 72 static int
73 73 init_channel()
74 74 {
75 75 /*
76 76 * This functionality is not supported in the mini-root
77 77 * environment, ie install. If root_dir is set, implying
78 78 * install, we quietly fail.
79 79 */
80 80 if (strcmp(root_dir, "") != 0) {
81 81 return (EACCES);
82 82 }
83 83
84 84 /*
85 85 * Initialize the private sysevent handle
86 86 */
87 87 sysevent_hp = sysevent_open_channel(SYSEVENTD_CHAN);
88 88 if (sysevent_hp == NULL) {
89 89 if (errno == EACCES) {
90 90 syseventd_print(3, "sysevent_reg_mod: "
91 91 "sysevent_open_channel failed with %s init "
92 92 "deferred\n", strerror(errno));
93 93 return (errno);
94 94 } else {
95 95 syseventd_err_print(INIT_SUB_OPEN_CHAN_ERR,
96 96 strerror(errno));
97 97 return (errno);
98 98 }
99 99 }
100 100
101 101 if (sysevent_bind_publisher(sysevent_hp) != 0) {
102 102 /*
103 103 * Only one publisher allowed on the syseventd channel,
104 104 * cleanup previously allocated syseventd channel publishers
105 105 */
106 106 if (errno == EBUSY) {
107 107 sysevent_cleanup_publishers(sysevent_hp);
108 108 if (sysevent_bind_publisher(sysevent_hp) == 0)
109 109 return (0);
110 110 }
111 111
112 112 syseventd_err_print(INIT_SUB_BIND_PUB_ERR,
113 113 strerror(errno));
114 114 sysevent_close_channel(sysevent_hp);
115 115 sysevent_hp = NULL;
116 116 return (errno);
117 117 }
118 118
119 119 return (0);
120 120 }
121 121
122 122 static int
123 123 deliver_event(sysevent_t *ev, int flag)
124 124 {
125 125 int ret, ev_size;
126 126 ev_queue_t *new_evq, *tmp_evq;
127 127
128 128 /* Not initialized */
129 129 if (sysevent_hp == NULL) {
130 130
131 131 ret = init_channel();
132 132 if (ret != 0) {
133 133 if (ret == EBUSY && flag != SE_NO_RETRY) {
134 134 return (EAGAIN);
135 135 } else if (ret == EACCES) {
136 136 return (0);
137 137 } else {
138 138 syseventd_err_print(INIT_SUB_OPEN_CHAN_ERR,
139 139 strerror(ret));
140 140 return (0);
141 141 }
142 142 }
143 143 /* Check for stale syseventd subscribers */
144 144 sysevent_cleanup_subscribers(sysevent_hp);
145 145 syseventd_print(3, "sysevent_reg_mod: init successful");
146 146 }
147 147
148 148 /* Queue event for delivery to all subscribers */
149 149 new_evq = (ev_queue_t *)calloc(1, sizeof (ev_queue_t));
150 150 if (new_evq == NULL) {
151 151 return (EAGAIN);
152 152 }
153 153 ev_size = sysevent_get_size(ev);
154 154 new_evq->evq_ev = (sysevent_t *)malloc(ev_size);
155 155 if (new_evq->evq_ev == NULL) {
156 156 free(new_evq);
157 157 return (EAGAIN);
158 158 }
159 159 bcopy(ev, new_evq->evq_ev, ev_size);
160 160
161 161 (void) mutex_lock(&evq_lock);
162 162 if (event_q == NULL) {
163 163 event_q = new_evq;
164 164 } else {
165 165 tmp_evq = event_q;
166 166 while (tmp_evq->evq_next != NULL)
167 167 tmp_evq = tmp_evq->evq_next;
168 168 tmp_evq->evq_next = new_evq;
169 169 }
170 170 syseventd_print(3, "sysevent_reg_mod: queue event 0X%llx\n",
171 171 sysevent_get_seq(ev));
172 172
173 173 (void) cond_signal(&evq_cv);
174 174 (void) mutex_unlock(&evq_lock);
175 175
176 176 return (0);
177 177 }
178 178
179 179 void
180 180 subscriber_deliver_thr()
181 181 {
182 182 ev_queue_t *evqp;
183 183
184 184 (void) mutex_lock(&evq_lock);
185 185 for (;;) {
186 186 while (event_q == NULL && cleanup == 0) {
187 187 (void) cond_wait(&evq_cv, &evq_lock);
188 188 }
189 189
190 190 /* Send events on to all current subscribers */
191 191 evqp = event_q;
192 192 while (evqp) {
193 193 (void) mutex_unlock(&evq_lock);
194 194 syseventd_print(3, "sysevent_reg_mod: sending event "
195 195 "0X%llx\n", sysevent_get_seq(evqp->evq_ev));
196 196 if (sysevent_send_event(sysevent_hp,
197 197 evqp->evq_ev) != 0) {
198 198 syseventd_print(3, "sysevent_reg_mod: "
199 199 "failed to send event\n");
200 200 }
201 201 syseventd_print(3, "sysevent_reg_mod: event sent "
202 202 "0X%llx\n", sysevent_get_seq(evqp->evq_ev));
203 203 (void) mutex_lock(&evq_lock);
204 204 event_q = evqp->evq_next;
205 205 free(evqp->evq_ev);
206 206 free(evqp);
207 207 evqp = event_q;
208 208 }
209 209 if (cleanup) {
210 210 syseventd_print(3, "sysevent_reg_mod: deliver "
211 211 "thread exiting\n");
212 212 (void) mutex_unlock(&evq_lock);
213 213 (void) thr_exit(NULL);
214 214 /* NOTREACHED */
215 215 }
216 216 }
217 217
218 218 /* NOTREACHED */
219 219 }
220 220
221 221 static struct slm_mod_ops sysevent_reg_mod_ops = {
222 222 SE_MAJOR_VERSION, SE_MINOR_VERSION, SE_MAX_RETRY_LIMIT, deliver_event};
223 223
224 224 struct slm_mod_ops *
↓ open down ↓ |
224 lines elided |
↑ open up ↑ |
225 225 slm_init()
226 226 {
227 227 cleanup = 0;
228 228 sysevent_hp = NULL;
229 229
230 230 (void) init_channel();
231 231
232 232 (void) mutex_init(&evq_lock, USYNC_THREAD, NULL);
233 233 (void) cond_init(&evq_cv, USYNC_THREAD, NULL);
234 234
235 - if (thr_create(NULL, NULL, (void *(*)(void *))subscriber_deliver_thr,
235 + if (thr_create(NULL, 0, (void *(*)(void *))subscriber_deliver_thr,
236 236 NULL, 0, &deliver_thr_id) != 0) {
237 237 syseventd_err_print(INIT_SUB_THR_CREATE_ERR, strerror(errno));
238 238 return (NULL);
239 239 }
240 240
241 241 return (&sysevent_reg_mod_ops);
242 242 }
243 243
244 244 void
245 245 slm_fini()
246 246 {
247 247 (void) mutex_lock(&evq_lock);
248 248 cleanup = 1;
249 249 (void) cond_signal(&evq_cv);
250 250 (void) mutex_unlock(&evq_lock);
251 251
252 252 /* Wait for delivery threads to exit */
253 253 (void) thr_join(deliver_thr_id, NULL, NULL);
254 254
255 255 (void) mutex_destroy(&evq_lock);
256 256 (void) cond_destroy(&evq_cv);
257 257
258 258 sysevent_close_channel(sysevent_hp);
259 259 sysevent_hp = NULL;
260 260 }
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX