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.
28 * PICL plug-in that listens to sysevent and posts picl events
41 #include <libdevinfo.h>
46 #include <sys/types.h>
47 #include <sys/sysinfo.h>
50 #include <sys/sunddi.h>
52 #include <libsysevent.h>
53 #include <libnvpair.h>
54 #include "piclevent.h"
57 * Plugin registration entry points
59 static void eventplugin_register(void);
60 static void eventplugin_init(void);
61 static void eventplugin_fini(void);
63 #pragma init(eventplugin_register)
65 static picld_plugin_reg_t my_reg_info
= {
66 PICLD_PLUGIN_VERSION_1
,
67 PICLD_PLUGIN_CRITICAL
,
68 "SUNW_piclevent plugin for sysevents",
76 #define EVT_THR_FAILED gettext("Event thread create failed!\n")
77 #define EVT_OPEN_FAILED gettext("PICL SLM door create failed\n")
79 static int door_id
= -1;
80 #define SUNW_PICLEVENT_PLUGIN_DEBUG "SUNW_PICLEVENT_PLUGIN_DEBUG"
81 static int piclevent_debug
= 0;
85 * completion handler for the posted picl event
89 piclevent_completion_handler(char *ename
, void *earg
, size_t size
)
96 * This function posts the incoming piclevent
97 * It packs the nvlist and posts it to PICL
100 parse_piclevent(nvlist_t
*nvlp
)
108 if (nvlist_lookup_string(nvlp
, PICLEVENTARG_EVENT_NAME
, &enval
))
112 if (nvlist_pack(nvlp
, &packed_nvl
, &nvl_size
, NV_ENCODE_NATIVE
, 0))
115 ename
= strdup(enval
);
121 if (piclevent_debug
) {
122 syslog(LOG_INFO
, "piclevent: posting ename:%s packed_nvl:%p "
123 "nvl_size:0x%x\n", ename
, packed_nvl
, nvl_size
);
125 err
= ptree_post_event(ename
, packed_nvl
, nvl_size
,
126 piclevent_completion_handler
);
128 if (err
!= PICL_SUCCESS
) {
131 "piclevent: posting ename:%s failed err:%d\n",
139 * This is the PICL SLM door handler. It parses the event tuple received
140 * and posts an event to refresh the PICL tree.
144 event_handler(void *cookie
, char *argp
, size_t asize
,
145 door_desc_t
*dp
, uint_t n_desc
)
153 "piclevent: got SLM event cookie:%p evarg:%p size:0x%x\n",
154 cookie
, argp
, asize
);
155 if ((door_id
< 0) || (argp
== NULL
) || (door_cred(&cred
) < 0) ||
157 (void) door_return(argp
, 0, NULL
, 0);
159 if (nvlist_unpack(argp
, asize
, &nvlp
, 0))
160 (void) door_return(argp
, 0, NULL
, 0);
162 if (nvlist_lookup_string(nvlp
, PICLEVENTARG_DATA_TYPE
, &dtype
)) {
164 (void) door_return(argp
, 0, NULL
, 0);
167 if (strcmp(dtype
, PICLEVENTARG_PICLEVENT_DATA
) == 0)
168 parse_piclevent(nvlp
);
170 * ignore other event data types
173 (void) door_return(argp
, 0, NULL
, 0);
177 * Create the slm to picl plugin door
187 door_id
= door_create(event_handler
, PICLEVENT_DOOR_COOKIE
,
188 DOOR_REFUSE_DESC
| DOOR_NO_CANCEL
);
193 if (stat(PICLEVENT_DOOR
, &stbuf
) < 0) {
195 if ((newfd
= creat(PICLEVENT_DOOR
, 0444)) < 0) {
196 (void) door_revoke(door_id
);
203 if (fattach(door_id
, PICLEVENT_DOOR
) < 0) {
204 if ((errno
!= EBUSY
) || (fdetach(PICLEVENT_DOOR
) < 0) ||
205 (fattach(door_id
, PICLEVENT_DOOR
) < 0)) {
206 (void) door_revoke(door_id
);
217 * This function is executed as part of .init when the plugin is
221 eventplugin_register(void)
223 if (getenv(SUNW_PICLEVENT_PLUGIN_DEBUG
))
225 (void) picld_plugin_register(&my_reg_info
);
229 * This function is the init entry point of the plugin.
230 * It creates the slm to picl plugin door.
233 eventplugin_init(void)
235 if (setup_door() < 0) {
236 syslog(LOG_ERR
, EVT_OPEN_FAILED
);
241 * This function is the fini entry point of the plugin
244 eventplugin_fini(void)
247 (void) door_revoke(door_id
);