Mercurial > illumos > illumos-gate
annotate usr/src/lib/libsysevent/libevchannel.c @ 12979:ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
PSARC/2009/618 snmp-notify: SNMP Notification Daemon for Software Events
PSARC/2009/619 smtp-notify: Email Notification Daemon for Software Events
PSARC/2010/225 fmd for non-global Solaris zones
PSARC/2010/226 Solaris Instance UUID
PSARC/2010/227 nvlist_nvflag(3NVPAIR)
PSARC/2010/228 libfmevent additions
PSARC/2010/257 sysevent_evc_setpropnvl and sysevent_evc_getpropnvl
PSARC/2010/265 FMRI and FMA Event Stabilty, 'ireport' category 1 event class, and the 'sw' FMRI scheme
PSARC/2010/278 FMA/SMF integration: instance state transitions
PSARC/2010/279 Modelling panics within FMA
PSARC/2010/290 logadm.conf upgrade
6392476 fmdump needs to pretty-print
6393375 userland ereport/ireport event generation interfaces
6445732 Add email notification agent for FMA and software events
6804168 RFE: Allow an efficient means to monitor SMF services status changes
6866661 scf_values_destroy(3SCF) will segfault if is passed NULL
6884709 Add snmp notification agent for FMA and software events
6884712 Add private interface to tap into libfmd_msg macro expansion capabilities
6897919 fmd to run in a non-global zone
6897937 fmd use of non-private doors is not safe
6900081 add a UUID to Solaris kernel image for use in crashdump identification
6914884 model panic events as a defect diagnosis in FMA
6944862 fmd_case_open_uuid, fmd_case_uuisresolved, fmd_nvl_create_defect
6944866 log legacy sysevents in fmd
6944867 enumerate svc scheme in topo
6944868 software-diagnosis and software-response fmd modules
6944870 model SMF maintenance state as a defect diagnosis in FMA
6944876 savecore runs in foreground for systems with zfs root and dedicated dump
6965796 Implement notification parameters for SMF state transitions and FMA events
6968287 SUN-FM-MIB.mib needs to be updated to reflect Oracle information
6972331 logadm.conf upgrade PSARC/2010/290
author | Gavin Maltby <gavin.maltby@oracle.com> |
---|---|
date | Fri, 30 Jul 2010 17:04:17 +1000 |
parents | b91faef0c984 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 * CDDL HEADER START | |
3 * | |
4 * The contents of this file are subject to the terms of the | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
5 * Common Development and Distribution License (the "License"). |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
6 * You may not use this file except in compliance with the License. |
0 | 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 /* | |
12979
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
22 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 23 */ |
24 | |
25 #include <stdio.h> | |
26 #include <ctype.h> | |
27 #include <fcntl.h> | |
28 #include <errno.h> | |
29 #include <door.h> | |
30 #include <unistd.h> | |
31 #include <stddef.h> | |
32 #include <stdlib.h> | |
33 #include <strings.h> | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
34 #include <pthread.h> |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
35 #include <atomic.h> |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
36 #include <signal.h> |
0 | 37 #include <sys/types.h> |
38 #include <sys/varargs.h> | |
39 #include <sys/sysevent.h> | |
40 #include <sys/sysevent_impl.h> | |
41 | |
42 #include "libsysevent.h" | |
43 #include "libsysevent_impl.h" | |
44 | |
45 /* | |
46 * The functions below deal with the General Purpose Event Handling framework | |
47 * | |
48 * sysevent_evc_bind - create/bind application to named channel | |
49 * sysevent_evc_unbind - unbind from previously bound/created channel | |
50 * sysevent_evc_subscribe - subscribe to existing event channel | |
51 * sysevent_evc_unsubscribe - unsubscribe from existing event channel | |
52 * sysevent_evc_publish - generate a system event via an event channel | |
53 * sysevent_evc_control - various channel based control operation | |
54 */ | |
55 | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
56 static void kill_door_servers(evchan_subscr_t *); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
57 |
0 | 58 #define misaligned(p) ((uintptr_t)(p) & 3) /* 4-byte alignment required */ |
59 | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
60 static pthread_key_t nrkey = PTHREAD_ONCE_KEY_NP; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
61 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
62 /* |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
63 * If the current thread is a door server thread servicing a door created |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
64 * for us in sysevent_evc_xsubscribe, then an attempt to unsubscribe from |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
65 * within door invocation context on the same channel will deadlock in the |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
66 * kernel waiting for our own invocation to complete. Such calls are |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
67 * forbidden, and we abort if they are encountered (better than hanging |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
68 * unkillably). |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
69 * |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
70 * We'd like to offer this detection to subscriptions established with |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
71 * sysevent_evc_subscribe, but we don't have control over the door service |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
72 * threads in that case. Perhaps the fix is to always use door_xcreate |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
73 * even for sysevent_evc_subscribe? |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
74 */ |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
75 static boolean_t |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
76 will_deadlock(evchan_t *scp) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
77 { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
78 evchan_subscr_t *subp = pthread_getspecific(nrkey); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
79 evchan_impl_hdl_t *hdl = EVCHAN_IMPL_HNDL(scp); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
80 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
81 return (subp != NULL && subp->ev_subhead == hdl ? B_TRUE : B_FALSE); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
82 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
83 |
0 | 84 /* |
85 * Check syntax of a channel name | |
86 */ | |
87 static int | |
88 sysevent_is_chan_name(const char *str) | |
89 { | |
90 for (; *str != '\0'; str++) { | |
91 if (!EVCH_ISCHANCHAR(*str)) | |
92 return (0); | |
93 } | |
94 | |
95 return (1); | |
96 } | |
97 | |
98 /* | |
99 * Check for printable characters | |
100 */ | |
101 static int | |
102 strisprint(const char *s) | |
103 { | |
104 for (; *s != '\0'; s++) { | |
105 if (*s < ' ' || *s > '~') | |
106 return (0); | |
107 } | |
108 | |
109 return (1); | |
110 } | |
111 | |
112 /* | |
113 * sysevent_evc_bind - Create/bind application to named channel | |
114 */ | |
115 int | |
116 sysevent_evc_bind(const char *channel, evchan_t **scpp, uint32_t flags) | |
117 { | |
118 int chanlen; | |
119 evchan_t *scp; | |
120 sev_bind_args_t uargs; | |
121 int ec; | |
122 | |
123 if (scpp == NULL || misaligned(scpp)) { | |
124 return (errno = EINVAL); | |
125 } | |
126 | |
127 /* Provide useful value in error case */ | |
128 *scpp = NULL; | |
129 | |
130 if (channel == NULL || | |
131 (chanlen = strlen(channel) + 1) > MAX_CHNAME_LEN) { | |
132 return (errno = EINVAL); | |
133 } | |
134 | |
135 /* Check channel syntax */ | |
136 if (!sysevent_is_chan_name(channel)) { | |
137 return (errno = EINVAL); | |
138 } | |
139 | |
140 if (flags & ~EVCH_B_FLAGS) { | |
141 return (errno = EINVAL); | |
142 } | |
143 | |
144 scp = calloc(1, sizeof (evchan_impl_hdl_t)); | |
145 if (scp == NULL) { | |
146 return (errno = ENOMEM); | |
147 } | |
148 | |
149 /* | |
150 * Enable sysevent driver. Fallback if the device link doesn't exist; | |
151 * this situation can arise if a channel is bound early in system | |
152 * startup, prior to devfsadm(1M) being invoked. | |
153 */ | |
154 EV_FD(scp) = open(DEVSYSEVENT, O_RDWR); | |
155 if (EV_FD(scp) == -1) { | |
156 if (errno != ENOENT) { | |
157 ec = errno == EACCES ? EPERM : errno; | |
158 free(scp); | |
159 return (errno = ec); | |
160 } | |
161 | |
162 EV_FD(scp) = open(DEVICESYSEVENT, O_RDWR); | |
163 if (EV_FD(scp) == -1) { | |
164 ec = errno == EACCES ? EPERM : errno; | |
165 free(scp); | |
166 return (errno = ec); | |
167 } | |
168 } | |
169 | |
170 /* | |
171 * Force to close the fd's when process is doing exec. | |
172 * The driver will then release stale binding handles. | |
173 * The driver will release also the associated subscriptions | |
174 * if EVCH_SUB_KEEP flag was not set. | |
175 */ | |
176 (void) fcntl(EV_FD(scp), F_SETFD, FD_CLOEXEC); | |
177 | |
178 uargs.chan_name.name = (uintptr_t)channel; | |
179 uargs.chan_name.len = chanlen; | |
180 uargs.flags = flags; | |
181 | |
182 if (ioctl(EV_FD(scp), SEV_CHAN_OPEN, &uargs) != 0) { | |
183 ec = errno; | |
184 (void) close(EV_FD(scp)); | |
185 free(scp); | |
186 return (errno = ec); | |
187 } | |
188 | |
189 /* Needed to detect a fork() */ | |
190 EV_PID(scp) = getpid(); | |
191 (void) mutex_init(EV_LOCK(scp), USYNC_THREAD, NULL); | |
192 | |
193 *scpp = scp; | |
194 | |
195 return (0); | |
196 } | |
197 | |
198 /* | |
199 * sysevent_evc_unbind - Unbind from previously bound/created channel | |
200 */ | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
201 int |
0 | 202 sysevent_evc_unbind(evchan_t *scp) |
203 { | |
204 sev_unsubscribe_args_t uargs; | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
205 evchan_subscr_t *subp; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
206 int errcp; |
0 | 207 |
208 if (scp == NULL || misaligned(scp)) | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
209 return (errno = EINVAL); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
210 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
211 if (will_deadlock(scp)) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
212 return (errno = EDEADLK); |
0 | 213 |
214 (void) mutex_lock(EV_LOCK(scp)); | |
215 | |
216 /* | |
217 * Unsubscribe, if we are in the process which did the bind. | |
218 */ | |
219 if (EV_PID(scp) == getpid()) { | |
220 uargs.sid.name = NULL; | |
221 uargs.sid.len = 0; | |
222 /* | |
223 * The unsubscribe ioctl will block until all door upcalls have | |
224 * drained. | |
225 */ | |
226 if (ioctl(EV_FD(scp), SEV_UNSUBSCRIBE, (intptr_t)&uargs) != 0) { | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
227 errcp = errno; |
0 | 228 (void) mutex_unlock(EV_LOCK(scp)); |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
229 return (errno = errcp); |
0 | 230 } |
231 } | |
232 | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
233 while ((subp = EV_SUB_NEXT(scp)) != NULL) { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
234 EV_SUB_NEXT(scp) = subp->evsub_next; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
235 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
236 /* If door_xcreate was applied we can clean up */ |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
237 if (subp->evsub_attr) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
238 kill_door_servers(subp); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
239 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
240 if (door_revoke(subp->evsub_door_desc) != 0 && errno == EPERM) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
241 (void) close(subp->evsub_door_desc); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
242 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
243 free(subp->evsub_sid); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
244 free(subp); |
0 | 245 } |
246 | |
247 (void) mutex_unlock(EV_LOCK(scp)); | |
248 | |
249 /* | |
250 * The close of the driver will do the unsubscribe if a) it is the last | |
251 * close and b) we are in a child which inherited subscriptions. | |
252 */ | |
253 (void) close(EV_FD(scp)); | |
254 (void) mutex_destroy(EV_LOCK(scp)); | |
255 free(scp); | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
256 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
257 return (0); |
0 | 258 } |
259 | |
260 /* | |
261 * sysevent_evc_publish - Generate a system event via an event channel | |
262 */ | |
263 int | |
264 sysevent_evc_publish(evchan_t *scp, const char *class, | |
265 const char *subclass, const char *vendor, | |
266 const char *pub_name, nvlist_t *attr_list, | |
267 uint32_t flags) | |
268 { | |
269 sysevent_t *ev; | |
270 sev_publish_args_t uargs; | |
271 int rc; | |
272 int ec; | |
273 | |
274 if (scp == NULL || misaligned(scp)) { | |
275 return (errno = EINVAL); | |
276 } | |
277 | |
278 /* No inheritance of binding handles via fork() */ | |
279 if (EV_PID(scp) != getpid()) { | |
280 return (errno = EINVAL); | |
281 } | |
282 | |
283 ev = sysevent_alloc_event((char *)class, (char *)subclass, | |
284 (char *)vendor, (char *)pub_name, attr_list); | |
285 if (ev == NULL) { | |
286 return (errno); | |
287 } | |
288 | |
289 uargs.ev.name = (uintptr_t)ev; | |
290 uargs.ev.len = SE_SIZE(ev); | |
291 uargs.flags = flags; | |
292 | |
293 (void) mutex_lock(EV_LOCK(scp)); | |
294 | |
295 rc = ioctl(EV_FD(scp), SEV_PUBLISH, (intptr_t)&uargs); | |
296 ec = errno; | |
297 | |
298 (void) mutex_unlock(EV_LOCK(scp)); | |
299 | |
300 sysevent_free(ev); | |
301 | |
302 if (rc != 0) { | |
303 return (ec); | |
304 } | |
305 return (0); | |
306 } | |
307 | |
308 /* | |
309 * Generic callback which catches events from the kernel and calls | |
310 * subscribers call back routine. | |
311 * | |
312 * Kernel guarantees that door_upcalls are disabled when unsubscription | |
313 * was issued that's why cookie points always to a valid evchan_subscr_t *. | |
314 * | |
315 * Furthermore it's not necessary to lock subp because the sysevent | |
316 * framework guarantees no unsubscription until door_return. | |
317 */ | |
318 /*ARGSUSED3*/ | |
319 static void | |
320 door_upcall(void *cookie, char *args, size_t alen, | |
321 door_desc_t *ddp, uint_t ndid) | |
322 { | |
323 evchan_subscr_t *subp = EVCHAN_SUBSCR(cookie); | |
324 int rval = 0; | |
325 | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
326 /* |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
327 * If we've been invoked simply to kill the thread then |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
328 * exit now. |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
329 */ |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
330 if (subp->evsub_state == EVCHAN_SUB_STATE_CLOSING) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
331 pthread_exit(NULL); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
332 |
0 | 333 if (args == NULL || alen <= (size_t)0) { |
334 /* Skip callback execution */ | |
335 rval = EINVAL; | |
336 } else { | |
337 rval = subp->evsub_func((sysevent_t *)(void *)args, | |
338 subp->evsub_cookie); | |
339 } | |
340 | |
341 /* | |
342 * Fill in return values for door_return | |
343 */ | |
344 alen = sizeof (rval); | |
345 bcopy(&rval, args, alen); | |
346 | |
347 (void) door_return(args, alen, NULL, 0); | |
348 } | |
349 | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
350 static pthread_once_t xsub_thrattr_once = PTHREAD_ONCE_INIT; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
351 static pthread_attr_t xsub_thrattr; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
352 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
353 static void |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
354 xsub_thrattr_init(void) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
355 { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
356 (void) pthread_attr_init(&xsub_thrattr); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
357 (void) pthread_attr_setdetachstate(&xsub_thrattr, |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
358 PTHREAD_CREATE_DETACHED); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
359 (void) pthread_attr_setscope(&xsub_thrattr, PTHREAD_SCOPE_SYSTEM); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
360 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
361 |
0 | 362 /* |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
363 * Our door server create function is only called during initial |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
364 * door_xcreate since we specify DOOR_NO_DEPLETION_CB. |
0 | 365 */ |
366 int | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
367 xsub_door_server_create(door_info_t *dip, void *(*startf)(void *), |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
368 void *startfarg, void *cookie) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
369 { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
370 evchan_subscr_t *subp = EVCHAN_SUBSCR(cookie); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
371 struct sysevent_subattr_impl *xsa = subp->evsub_attr; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
372 pthread_attr_t *thrattr; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
373 sigset_t oset; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
374 int err; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
375 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
376 if (subp->evsub_state == EVCHAN_SUB_STATE_CLOSING) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
377 return (0); /* shouldn't happen, but just in case */ |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
378 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
379 /* |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
380 * If sysevent_evc_xsubscribe was called electing to use a |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
381 * different door server create function then let it take it |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
382 * from here. |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
383 */ |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
384 if (xsa->xs_thrcreate) { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
385 return (xsa->xs_thrcreate(dip, startf, startfarg, |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
386 xsa->xs_thrcreate_cookie)); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
387 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
388 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
389 if (xsa->xs_thrattr == NULL) { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
390 (void) pthread_once(&xsub_thrattr_once, xsub_thrattr_init); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
391 thrattr = &xsub_thrattr; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
392 } else { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
393 thrattr = xsa->xs_thrattr; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
394 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
395 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
396 (void) pthread_sigmask(SIG_SETMASK, &xsa->xs_sigmask, &oset); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
397 err = pthread_create(NULL, thrattr, startf, startfarg); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
398 (void) pthread_sigmask(SIG_SETMASK, &oset, NULL); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
399 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
400 return (err == 0 ? 1 : -1); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
401 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
402 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
403 void |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
404 xsub_door_server_setup(void *cookie) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
405 { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
406 evchan_subscr_t *subp = EVCHAN_SUBSCR(cookie); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
407 struct sysevent_subattr_impl *xsa = subp->evsub_attr; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
408 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
409 if (xsa->xs_thrsetup == NULL) { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
410 (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
411 (void) pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
412 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
413 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
414 (void) pthread_setspecific(nrkey, (void *)subp); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
415 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
416 if (xsa->xs_thrsetup) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
417 xsa->xs_thrsetup(xsa->xs_thrsetup_cookie); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
418 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
419 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
420 /* |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
421 * Cause private door server threads to exit. We have already performed the |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
422 * unsubscribe ioctl which stops new invocations and waits until all |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
423 * existing invocations are complete. So all server threads should be |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
424 * blocked in door_return. The door has not yet been revoked. We will |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
425 * invoke repeatedly after setting the evsub_state to be noticed on |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
426 * wakeup; each invocation will result in the death of one server thread. |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
427 * |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
428 * You'd think it would be easier to kill these threads, such as through |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
429 * pthread_cancel. Unfortunately door_return is not a cancellation point, |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
430 * and if you do cancel a thread blocked in door_return the EINTR check in |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
431 * the door_return assembly logic causes us to loop with EINTR forever! |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
432 */ |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
433 static void |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
434 kill_door_servers(evchan_subscr_t *subp) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
435 { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
436 door_arg_t da; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
437 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
438 bzero(&da, sizeof (da)); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
439 subp->evsub_state = EVCHAN_SUB_STATE_CLOSING; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
440 membar_producer(); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
441 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
442 (void) door_call(subp->evsub_door_desc, &da); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
443 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
444 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
445 static int |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
446 sysevent_evc_subscribe_cmn(evchan_t *scp, const char *sid, const char *class, |
0 | 447 int (*event_handler)(sysevent_t *ev, void *cookie), |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
448 void *cookie, uint32_t flags, struct sysevent_subattr_impl *xsa) |
0 | 449 { |
450 evchan_subscr_t *subp; | |
451 int upcall_door; | |
452 sev_subscribe_args_t uargs; | |
453 uint32_t sid_len; | |
454 uint32_t class_len; | |
455 int ec; | |
456 | |
457 if (scp == NULL || misaligned(scp) || sid == NULL || class == NULL) { | |
458 return (errno = EINVAL); | |
459 } | |
460 | |
461 /* No inheritance of binding handles via fork() */ | |
462 if (EV_PID(scp) != getpid()) { | |
463 return (errno = EINVAL); | |
464 } | |
465 | |
466 if ((sid_len = strlen(sid) + 1) > MAX_SUBID_LEN || sid_len == 1 || | |
467 (class_len = strlen(class) + 1) > MAX_CLASS_LEN) { | |
468 return (errno = EINVAL); | |
469 } | |
470 | |
471 /* Check for printable characters */ | |
472 if (!strisprint(sid)) { | |
473 return (errno = EINVAL); | |
474 } | |
475 | |
476 if (event_handler == NULL) { | |
477 return (errno = EINVAL); | |
478 } | |
479 | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
480 if (pthread_key_create_once_np(&nrkey, NULL) != 0) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
481 return (errno); /* ENOMEM or EAGAIN */ |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
482 |
0 | 483 /* Create subscriber data */ |
484 if ((subp = calloc(1, sizeof (evchan_subscr_t))) == NULL) { | |
485 return (errno); | |
486 } | |
487 | |
488 if ((subp->evsub_sid = strdup(sid)) == NULL) { | |
489 ec = errno; | |
490 free(subp); | |
491 return (ec); | |
492 } | |
493 | |
494 /* | |
495 * EC_ALL string will not be copied to kernel - NULL is assumed | |
496 */ | |
497 if (strcmp(class, EC_ALL) == 0) { | |
498 class = NULL; | |
499 class_len = 0; | |
500 } | |
501 | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
502 /* |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
503 * Fill this in now for the xsub_door_server_setup dance |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
504 */ |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
505 subp->ev_subhead = EVCHAN_IMPL_HNDL(scp); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
506 subp->evsub_state = EVCHAN_SUB_STATE_ACTIVE; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
507 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
508 if (xsa == NULL) { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
509 upcall_door = door_create(door_upcall, (void *)subp, |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
510 DOOR_REFUSE_DESC | DOOR_NO_CANCEL); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
511 } else { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
512 subp->evsub_attr = xsa; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
513 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
514 /* |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
515 * Create a private door with exactly one thread to |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
516 * service the callbacks (the GPEC kernel implementation |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
517 * serializes deliveries for each subscriber id). |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
518 */ |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
519 upcall_door = door_xcreate(door_upcall, (void *)subp, |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
520 DOOR_REFUSE_DESC | DOOR_NO_CANCEL | DOOR_NO_DEPLETION_CB, |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
521 xsub_door_server_create, xsub_door_server_setup, |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
522 (void *)subp, 1); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
523 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
524 |
0 | 525 if (upcall_door == -1) { |
526 ec = errno; | |
527 free(subp->evsub_sid); | |
528 free(subp); | |
529 return (ec); | |
530 } | |
531 | |
532 /* Complete subscriber information */ | |
533 subp->evsub_door_desc = upcall_door; | |
534 subp->evsub_func = event_handler; | |
535 subp->evsub_cookie = cookie; | |
536 | |
537 (void) mutex_lock(EV_LOCK(scp)); | |
538 | |
539 uargs.sid.name = (uintptr_t)sid; | |
540 uargs.sid.len = sid_len; | |
541 uargs.class_info.name = (uintptr_t)class; | |
542 uargs.class_info.len = class_len; | |
543 uargs.door_desc = subp->evsub_door_desc; | |
544 uargs.flags = flags; | |
545 if (ioctl(EV_FD(scp), SEV_SUBSCRIBE, (intptr_t)&uargs) != 0) { | |
546 ec = errno; | |
547 (void) mutex_unlock(EV_LOCK(scp)); | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
548 if (xsa) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
549 kill_door_servers(subp); |
0 | 550 (void) door_revoke(upcall_door); |
551 free(subp->evsub_sid); | |
552 free(subp); | |
553 return (ec); | |
554 } | |
555 | |
556 /* Attach to subscriber list */ | |
557 subp->evsub_next = EV_SUB_NEXT(scp); | |
558 EV_SUB_NEXT(scp) = subp; | |
559 | |
560 (void) mutex_unlock(EV_LOCK(scp)); | |
561 | |
562 return (0); | |
563 } | |
564 | |
565 /* | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
566 * sysevent_evc_subscribe - subscribe to an existing event channel |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
567 * using a non-private door (which will create as many server threads |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
568 * as the apparent maximum concurrency requirements suggest). |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
569 */ |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
570 int |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
571 sysevent_evc_subscribe(evchan_t *scp, const char *sid, const char *class, |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
572 int (*event_handler)(sysevent_t *ev, void *cookie), |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
573 void *cookie, uint32_t flags) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
574 { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
575 return (sysevent_evc_subscribe_cmn(scp, sid, class, event_handler, |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
576 cookie, flags, NULL)); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
577 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
578 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
579 static void |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
580 subattr_dfltinit(struct sysevent_subattr_impl *xsa) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
581 { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
582 (void) sigfillset(&xsa->xs_sigmask); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
583 (void) sigdelset(&xsa->xs_sigmask, SIGABRT); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
584 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
585 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
586 static struct sysevent_subattr_impl dfltsa; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
587 pthread_once_t dfltsa_inited = PTHREAD_ONCE_INIT; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
588 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
589 static void |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
590 init_dfltsa(void) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
591 { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
592 subattr_dfltinit(&dfltsa); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
593 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
594 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
595 /* |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
596 * sysevent_evc_subscribe - subscribe to an existing event channel |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
597 * using a private door with control over thread creation. |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
598 */ |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
599 int |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
600 sysevent_evc_xsubscribe(evchan_t *scp, const char *sid, const char *class, |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
601 int (*event_handler)(sysevent_t *ev, void *cookie), |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
602 void *cookie, uint32_t flags, sysevent_subattr_t *attr) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
603 { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
604 struct sysevent_subattr_impl *xsa; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
605 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
606 if (attr != NULL) { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
607 xsa = (struct sysevent_subattr_impl *)attr; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
608 } else { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
609 xsa = &dfltsa; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
610 (void) pthread_once(&dfltsa_inited, init_dfltsa); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
611 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
612 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
613 return (sysevent_evc_subscribe_cmn(scp, sid, class, event_handler, |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
614 cookie, flags, xsa)); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
615 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
616 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
617 sysevent_subattr_t * |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
618 sysevent_subattr_alloc(void) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
619 { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
620 struct sysevent_subattr_impl *xsa = calloc(1, sizeof (*xsa)); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
621 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
622 if (xsa != NULL) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
623 subattr_dfltinit(xsa); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
624 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
625 return (xsa != NULL ? (sysevent_subattr_t *)xsa : NULL); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
626 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
627 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
628 void |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
629 sysevent_subattr_free(sysevent_subattr_t *attr) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
630 { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
631 struct sysevent_subattr_impl *xsa = |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
632 (struct sysevent_subattr_impl *)attr; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
633 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
634 free(xsa); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
635 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
636 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
637 void |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
638 sysevent_subattr_thrcreate(sysevent_subattr_t *attr, |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
639 door_xcreate_server_func_t *thrcreate, void *cookie) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
640 { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
641 struct sysevent_subattr_impl *xsa = |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
642 (struct sysevent_subattr_impl *)attr; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
643 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
644 xsa->xs_thrcreate = thrcreate; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
645 xsa->xs_thrcreate_cookie = cookie; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
646 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
647 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
648 void |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
649 sysevent_subattr_thrsetup(sysevent_subattr_t *attr, |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
650 door_xcreate_thrsetup_func_t *thrsetup, void *cookie) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
651 { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
652 struct sysevent_subattr_impl *xsa = |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
653 (struct sysevent_subattr_impl *)attr; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
654 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
655 xsa->xs_thrsetup = thrsetup; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
656 xsa->xs_thrsetup_cookie = cookie; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
657 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
658 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
659 void |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
660 sysevent_subattr_sigmask(sysevent_subattr_t *attr, sigset_t *set) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
661 { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
662 struct sysevent_subattr_impl *xsa = |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
663 (struct sysevent_subattr_impl *)attr; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
664 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
665 if (set) { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
666 xsa->xs_sigmask = *set; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
667 } else { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
668 (void) sigfillset(&xsa->xs_sigmask); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
669 (void) sigdelset(&xsa->xs_sigmask, SIGABRT); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
670 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
671 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
672 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
673 void |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
674 sysevent_subattr_thrattr(sysevent_subattr_t *attr, pthread_attr_t *thrattr) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
675 { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
676 struct sysevent_subattr_impl *xsa = |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
677 (struct sysevent_subattr_impl *)attr; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
678 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
679 xsa->xs_thrattr = thrattr; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
680 } |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
681 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
682 /* |
0 | 683 * sysevent_evc_unsubscribe - Unsubscribe from an existing event channel |
684 */ | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
685 int |
0 | 686 sysevent_evc_unsubscribe(evchan_t *scp, const char *sid) |
687 { | |
688 int all_subscribers = 0; | |
689 sev_unsubscribe_args_t uargs; | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
690 evchan_subscr_t *subp, *prevsubp, *tofree; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
691 int errcp; |
0 | 692 int rc; |
693 | |
694 if (scp == NULL || misaligned(scp)) | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
695 return (errno = EINVAL); |
0 | 696 |
697 if (sid == NULL || strlen(sid) == 0 || | |
698 (strlen(sid) >= MAX_SUBID_LEN)) | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
699 return (errno = EINVAL); |
0 | 700 |
701 /* No inheritance of binding handles via fork() */ | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
702 if (EV_PID(scp) != getpid()) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
703 return (errno = EINVAL); |
0 | 704 |
705 if (strcmp(sid, EVCH_ALLSUB) == 0) { | |
706 all_subscribers++; | |
707 /* Indicates all subscriber id's for this channel */ | |
708 uargs.sid.name = NULL; | |
709 uargs.sid.len = 0; | |
710 } else { | |
711 uargs.sid.name = (uintptr_t)sid; | |
712 uargs.sid.len = strlen(sid) + 1; | |
713 } | |
714 | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
715 if (will_deadlock(scp)) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
716 return (errno = EDEADLK); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
717 |
0 | 718 (void) mutex_lock(EV_LOCK(scp)); |
719 | |
720 /* | |
721 * The unsubscribe ioctl will block until all door upcalls have drained. | |
722 */ | |
723 rc = ioctl(EV_FD(scp), SEV_UNSUBSCRIBE, (intptr_t)&uargs); | |
724 | |
725 if (rc != 0) { | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
726 errcp = errno; |
0 | 727 (void) mutex_unlock(EV_LOCK(scp)); |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
728 return (errno = errcp); /* EFAULT, ENXIO, EINVAL possible */ |
0 | 729 } |
730 | |
731 | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
732 /* |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
733 * Search for the matching subscriber. If EVCH_ALLSUB was specified |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
734 * then the ioctl above will have returned 0 even if there are |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
735 * no subscriptions, so the initial EV_SUB_NEXT can be NULL. |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
736 */ |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
737 prevsubp = NULL; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
738 subp = EV_SUB_NEXT(scp); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
739 while (subp != NULL) { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
740 if (all_subscribers || strcmp(subp->evsub_sid, sid) == 0) { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
741 if (prevsubp == NULL) { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
742 EV_SUB_NEXT(scp) = subp->evsub_next; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
743 } else { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
744 prevsubp->evsub_next = subp->evsub_next; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
745 } |
0 | 746 |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
747 tofree = subp; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
748 subp = subp->evsub_next; |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
749 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
750 /* If door_xcreate was applied we can clean up */ |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
751 if (tofree->evsub_attr) |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
752 kill_door_servers(tofree); |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
753 |
0 | 754 (void) door_revoke(tofree->evsub_door_desc); |
755 free(tofree->evsub_sid); | |
756 free(tofree); | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
757 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
758 /* Freed single subscriber already? */ |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
759 if (all_subscribers == 0) |
0 | 760 break; |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
761 } else { |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
762 prevsubp = subp; |
0 | 763 subp = subp->evsub_next; |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
764 } |
0 | 765 } |
766 | |
767 (void) mutex_unlock(EV_LOCK(scp)); | |
11102
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
768 |
b91faef0c984
PSARC/2009/554 door_xcreate - extended door creation interface for private doors
Gavin Maltby <Gavin.Maltby@Sun.COM>
parents:
0
diff
changeset
|
769 return (0); |
0 | 770 } |
771 | |
772 /* | |
773 * sysevent_evc_control - Various channel based control operation | |
774 */ | |
775 int | |
776 sysevent_evc_control(evchan_t *scp, int cmd, /* arg */ ...) | |
777 { | |
778 va_list ap; | |
779 uint32_t *chlenp; | |
780 sev_control_args_t uargs; | |
781 int rc = 0; | |
782 | |
783 if (scp == NULL || misaligned(scp)) { | |
784 return (errno = EINVAL); | |
785 } | |
786 | |
787 /* No inheritance of binding handles via fork() */ | |
788 if (EV_PID(scp) != getpid()) { | |
789 return (errno = EINVAL); | |
790 } | |
791 | |
792 va_start(ap, cmd); | |
793 | |
794 uargs.cmd = cmd; | |
795 | |
796 (void) mutex_lock(EV_LOCK(scp)); | |
797 | |
798 switch (cmd) { | |
799 case EVCH_GET_CHAN_LEN: | |
800 case EVCH_GET_CHAN_LEN_MAX: | |
801 chlenp = va_arg(ap, uint32_t *); | |
802 if (chlenp == NULL || misaligned(chlenp)) { | |
803 rc = EINVAL; | |
804 break; | |
805 } | |
806 rc = ioctl(EV_FD(scp), SEV_CHAN_CONTROL, (intptr_t)&uargs); | |
807 *chlenp = uargs.value; | |
808 break; | |
12979
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
809 |
0 | 810 case EVCH_SET_CHAN_LEN: |
811 /* Range change will be handled in framework */ | |
812 uargs.value = va_arg(ap, uint32_t); | |
813 rc = ioctl(EV_FD(scp), SEV_CHAN_CONTROL, (intptr_t)&uargs); | |
814 break; | |
12979
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
815 |
0 | 816 default: |
817 rc = EINVAL; | |
818 } | |
819 | |
820 (void) mutex_unlock(EV_LOCK(scp)); | |
821 | |
822 if (rc == -1) { | |
823 rc = errno; | |
824 } | |
825 | |
826 va_end(ap); | |
827 | |
828 return (errno = rc); | |
829 } | |
12979
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
830 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
831 int |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
832 sysevent_evc_setpropnvl(evchan_t *scp, nvlist_t *nvl) |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
833 { |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
834 sev_propnvl_args_t uargs; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
835 char *buf = NULL; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
836 size_t nvlsz = 0; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
837 int rc; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
838 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
839 if (scp == NULL || misaligned(scp)) |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
840 return (errno = EINVAL); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
841 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
842 if (nvl != NULL && |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
843 nvlist_pack(nvl, &buf, &nvlsz, NV_ENCODE_NATIVE, 0) != 0) |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
844 return (errno); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
845 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
846 uargs.packednvl.name = (uint64_t)(uintptr_t)buf; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
847 uargs.packednvl.len = (uint32_t)nvlsz; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
848 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
849 rc = ioctl(EV_FD(scp), SEV_SETPROPNVL, (intptr_t)&uargs); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
850 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
851 if (buf) |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
852 free(buf); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
853 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
854 return (rc); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
855 } |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
856 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
857 int |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
858 sysevent_evc_getpropnvl(evchan_t *scp, nvlist_t **nvlp) |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
859 { |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
860 sev_propnvl_args_t uargs; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
861 char buf[1024], *bufp = buf; /* stack buffer */ |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
862 size_t sz = sizeof (buf); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
863 char *buf2 = NULL; /* allocated if stack buf too small */ |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
864 int64_t expgen = -1; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
865 int rc; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
866 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
867 if (scp == NULL || misaligned(scp) || nvlp == NULL) |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
868 return (errno = EINVAL); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
869 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
870 *nvlp = NULL; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
871 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
872 again: |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
873 uargs.packednvl.name = (uint64_t)(uintptr_t)bufp; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
874 uargs.packednvl.len = (uint32_t)sz; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
875 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
876 rc = ioctl(EV_FD(scp), SEV_GETPROPNVL, (intptr_t)&uargs); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
877 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
878 if (rc == E2BIG) |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
879 return (errno = E2BIG); /* driver refuses to copyout */ |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
880 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
881 /* |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
882 * If the packed nvlist is too big for the buffer size we offered |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
883 * then the ioctl returns EOVERFLOW and indicates in the 'len' |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
884 * the size required for the current property nvlist generation |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
885 * (itself returned in the generation member). |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
886 */ |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
887 if (rc == EOVERFLOW && |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
888 (buf2 == NULL || uargs.generation != expgen)) { |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
889 if (buf2 != NULL) |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
890 free(buf2); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
891 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
892 if ((sz = uargs.packednvl.len) > 1024 * 1024) |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
893 return (E2BIG); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
894 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
895 bufp = buf2 = malloc(sz); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
896 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
897 if (buf2 == NULL) |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
898 return (errno = ENOMEM); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
899 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
900 expgen = uargs.generation; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
901 goto again; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
902 } |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
903 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
904 /* |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
905 * The chan prop nvlist can be absent, in which case the ioctl |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
906 * returns success and uargs.packednvl.len of 0; we have already |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
907 * set *nvlp to NULL. Otherwise we must unpack the nvl. |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
908 */ |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
909 if (rc == 0 && uargs.packednvl.len != 0 && |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
910 nvlist_unpack(bufp, uargs.packednvl.len, nvlp, 0) != 0) |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
911 rc = EINVAL; |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
912 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
913 if (buf2 != NULL) |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
914 free(buf2); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
915 |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
916 return (rc ? errno = rc : 0); |
ab9ae749152f
PSARC/2009/617 Software Events Notification Parameters CLI
Gavin Maltby <gavin.maltby@oracle.com>
parents:
11102
diff
changeset
|
917 } |