4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * PICL plug-in that listens to sysevent and posts picl events
43 #include <libdevinfo.h>
48 #include <sys/types.h>
49 #include <sys/sysinfo.h>
52 #include <sys/sunddi.h>
54 #include <libsysevent.h>
55 #include <libnvpair.h>
56 #include "piclevent.h"
59 * Plugin registration entry points
61 static void eventplugin_register(void);
62 static void eventplugin_init(void);
63 static void eventplugin_fini(void);
65 #pragma init(eventplugin_register)
67 static picld_plugin_reg_t my_reg_info
= {
68 PICLD_PLUGIN_VERSION_1
,
69 PICLD_PLUGIN_CRITICAL
,
70 "SUNW_piclevent plugin for sysevents",
78 #define EVT_THR_FAILED gettext("Event thread create failed!\n")
79 #define EVT_OPEN_FAILED gettext("PICL SLM door create failed\n")
81 static int door_id
= -1;
82 #define SUNW_PICLEVENT_PLUGIN_DEBUG "SUNW_PICLEVENT_PLUGIN_DEBUG"
83 static int piclevent_debug
= 0;
87 * completion handler for the posted picl event
91 piclevent_completion_handler(char *ename
, void *earg
, size_t size
)
98 * This function posts the incoming piclevent
99 * It packs the nvlist and posts it to PICL
102 parse_piclevent(nvlist_t
*nvlp
)
110 if (nvlist_lookup_string(nvlp
, PICLEVENTARG_EVENT_NAME
, &enval
))
114 if (nvlist_pack(nvlp
, &packed_nvl
, &nvl_size
, NV_ENCODE_NATIVE
, NULL
))
117 ename
= strdup(enval
);
123 if (piclevent_debug
) {
124 syslog(LOG_INFO
, "piclevent: posting ename:%s packed_nvl:%p "
125 "nvl_size:0x%x\n", ename
, packed_nvl
, nvl_size
);
127 err
= ptree_post_event(ename
, packed_nvl
, nvl_size
,
128 piclevent_completion_handler
);
130 if (err
!= PICL_SUCCESS
) {
133 "piclevent: posting ename:%s failed err:%d\n",
141 * This is the PICL SLM door handler. It parses the event tuple received
142 * and posts an event to refresh the PICL tree.
146 event_handler(void *cookie
, char *argp
, size_t asize
,
147 door_desc_t
*dp
, uint_t n_desc
)
155 "piclevent: got SLM event cookie:%p evarg:%p size:0x%x\n",
156 cookie
, argp
, asize
);
157 if ((door_id
< 0) || (argp
== NULL
) || (door_cred(&cred
) < 0) ||
159 (void) door_return(argp
, 0, NULL
, 0);
161 if (nvlist_unpack(argp
, asize
, &nvlp
, NULL
))
162 (void) door_return(argp
, 0, NULL
, 0);
164 if (nvlist_lookup_string(nvlp
, PICLEVENTARG_DATA_TYPE
, &dtype
)) {
166 (void) door_return(argp
, 0, NULL
, 0);
169 if (strcmp(dtype
, PICLEVENTARG_PICLEVENT_DATA
) == 0)
170 parse_piclevent(nvlp
);
172 * ignore other event data types
175 (void) door_return(argp
, 0, NULL
, 0);
179 * Create the slm to picl plugin door
189 door_id
= door_create(event_handler
, PICLEVENT_DOOR_COOKIE
,
190 DOOR_REFUSE_DESC
| DOOR_NO_CANCEL
);
195 if (stat(PICLEVENT_DOOR
, &stbuf
) < 0) {
197 if ((newfd
= creat(PICLEVENT_DOOR
, 0444)) < 0) {
198 (void) door_revoke(door_id
);
205 if (fattach(door_id
, PICLEVENT_DOOR
) < 0) {
206 if ((errno
!= EBUSY
) || (fdetach(PICLEVENT_DOOR
) < 0) ||
207 (fattach(door_id
, PICLEVENT_DOOR
) < 0)) {
208 (void) door_revoke(door_id
);
219 * This function is executed as part of .init when the plugin is
223 eventplugin_register(void)
225 if (getenv(SUNW_PICLEVENT_PLUGIN_DEBUG
))
227 (void) picld_plugin_register(&my_reg_info
);
231 * This function is the init entry point of the plugin.
232 * It creates the slm to picl plugin door.
235 eventplugin_init(void)
237 if (setup_door() < 0) {
238 syslog(LOG_ERR
, EVT_OPEN_FAILED
);
243 * This function is the fini entry point of the plugin
246 eventplugin_fini(void)
249 (void) door_revoke(door_id
);