17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate * with the License.
87c478bd9Sstevel@tonic-gate *
97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate * and limitations under the License.
137c478bd9Sstevel@tonic-gate *
147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate *
207c478bd9Sstevel@tonic-gate * CDDL HEADER END
217c478bd9Sstevel@tonic-gate */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate * Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate #include <sys/sysevent.h>
287c478bd9Sstevel@tonic-gate #include <sys/sysevent_impl.h>
297c478bd9Sstevel@tonic-gate #include <libsysevent.h>
307c478bd9Sstevel@tonic-gate #include <libsysevent_impl.h>
317c478bd9Sstevel@tonic-gate #include "../genunix/sysevent.h"
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate int
sysevent(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)347c478bd9Sstevel@tonic-gate sysevent(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
357c478bd9Sstevel@tonic-gate {
367c478bd9Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == 0)
377c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate if ((flags & DCMD_LOOP) == 0) {
407c478bd9Sstevel@tonic-gate if (mdb_pwalk_dcmd("sysevent", "sysevent", argc, argv,
417c478bd9Sstevel@tonic-gate addr) == -1) {
427c478bd9Sstevel@tonic-gate mdb_warn("can't walk sysevent queue");
437c478bd9Sstevel@tonic-gate return (DCMD_ERR);
447c478bd9Sstevel@tonic-gate }
457c478bd9Sstevel@tonic-gate return (DCMD_OK);
467c478bd9Sstevel@tonic-gate }
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate return (sysevent_buf(addr, flags, 0));
497c478bd9Sstevel@tonic-gate }
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate /*ARGSUSED*/
527c478bd9Sstevel@tonic-gate int
sysevent_handle(uintptr_t addr,uint_t flags,int argc,const mdb_arg_t * argv)537c478bd9Sstevel@tonic-gate sysevent_handle(uintptr_t addr, uint_t flags, int argc,
547c478bd9Sstevel@tonic-gate const mdb_arg_t *argv)
557c478bd9Sstevel@tonic-gate {
567c478bd9Sstevel@tonic-gate ssize_t channel_name_sz;
577c478bd9Sstevel@tonic-gate char channel_name[CLASS_LIST_FIELD_MAX];
587c478bd9Sstevel@tonic-gate subscriber_priv_t sub;
597c478bd9Sstevel@tonic-gate sysevent_impl_hdl_t sysevent_hdl;
607c478bd9Sstevel@tonic-gate
617c478bd9Sstevel@tonic-gate if ((flags & DCMD_ADDRSPEC) == 0)
627c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate if (argc != 0)
667c478bd9Sstevel@tonic-gate return (DCMD_USAGE);
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate if (mdb_vread(&sysevent_hdl, sizeof (sysevent_hdl),
707c478bd9Sstevel@tonic-gate (uintptr_t)addr) == -1) {
717c478bd9Sstevel@tonic-gate mdb_warn("failed to read sysevent handle at %p", addr);
727c478bd9Sstevel@tonic-gate return (DCMD_ERR);
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate if ((channel_name_sz = mdb_readstr(channel_name, CLASS_LIST_FIELD_MAX,
757c478bd9Sstevel@tonic-gate (uintptr_t)sysevent_hdl.sh_channel_name)) == -1) {
767c478bd9Sstevel@tonic-gate mdb_warn("failed to read channel name at %p",
777c478bd9Sstevel@tonic-gate sysevent_hdl.sh_channel_name);
787c478bd9Sstevel@tonic-gate return (DCMD_ERR);
797c478bd9Sstevel@tonic-gate }
807c478bd9Sstevel@tonic-gate if (channel_name_sz >= CLASS_LIST_FIELD_MAX - 1)
817c478bd9Sstevel@tonic-gate (void) strcpy(&channel_name[CLASS_LIST_FIELD_MAX - 4], "...");
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate if (sysevent_hdl.sh_type == SUBSCRIBER) {
847c478bd9Sstevel@tonic-gate if (mdb_vread(&sub, sizeof (sub),
857c478bd9Sstevel@tonic-gate (uintptr_t)sysevent_hdl.sh_priv_data) == -1) {
867c478bd9Sstevel@tonic-gate mdb_warn("failed to read sysevent handle at %p", addr);
877c478bd9Sstevel@tonic-gate return (DCMD_ERR);
887c478bd9Sstevel@tonic-gate }
897c478bd9Sstevel@tonic-gate
907c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags))
917c478bd9Sstevel@tonic-gate mdb_printf("%<u>%-?s %-24s %-13s %-5s %-?s"
927c478bd9Sstevel@tonic-gate "%</u>\n", "ADDR", "NAME", "TYPE", "ID",
937c478bd9Sstevel@tonic-gate "EVENT QUEUE ADDR");
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate mdb_printf("%-?p %-24s %-13s %-5lu %-?p\n",
967c478bd9Sstevel@tonic-gate addr, channel_name, "SUBSCRIBER", sysevent_hdl.sh_id,
977c478bd9Sstevel@tonic-gate (uintptr_t)sub.sp_evq_head);
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate } else {
1007c478bd9Sstevel@tonic-gate if (DCMD_HDRSPEC(flags))
1017c478bd9Sstevel@tonic-gate mdb_printf("%<u>%-?s %-24s %-13s %-5s %-?s"
1027c478bd9Sstevel@tonic-gate "%</u>\n", "ADDR", "NAME",
1037c478bd9Sstevel@tonic-gate "TYPE", "ID", "CLASS LIST ADDR");
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate mdb_printf("%-?p %-24s %-13s %-5lu %-?p\n",
1067c478bd9Sstevel@tonic-gate addr, channel_name, "PUBLISHER", sysevent_hdl.sh_id,
1077c478bd9Sstevel@tonic-gate (uintptr_t)sysevent_hdl.sh_priv_data +
1087c478bd9Sstevel@tonic-gate offsetof(publisher_priv_t, pp_class_hash));
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate return (DCMD_OK);
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate static const mdb_dcmd_t dcmds[] = {
1157c478bd9Sstevel@tonic-gate { "sysevent", "?[-v]", "print the contents of a sysevent queue",
1167c478bd9Sstevel@tonic-gate sysevent},
1177c478bd9Sstevel@tonic-gate { "sysevent_handle", ":", "print sysevent subscriber/publisher handle",
1187c478bd9Sstevel@tonic-gate sysevent_handle},
1197c478bd9Sstevel@tonic-gate { "sysevent_class_list", ":", "print sysevent class list",
1207c478bd9Sstevel@tonic-gate sysevent_class_list },
1217c478bd9Sstevel@tonic-gate { "sysevent_subclass_list", ":", "print sysevent subclass list",
1227c478bd9Sstevel@tonic-gate sysevent_subclass_list },
1237c478bd9Sstevel@tonic-gate { NULL }
1247c478bd9Sstevel@tonic-gate };
1257c478bd9Sstevel@tonic-gate
1267c478bd9Sstevel@tonic-gate int
sysevent_walk_init(mdb_walk_state_t * wsp)1277c478bd9Sstevel@tonic-gate sysevent_walk_init(mdb_walk_state_t *wsp)
1287c478bd9Sstevel@tonic-gate {
129*892ad162SToomas Soome if (wsp->walk_addr == 0) {
1307c478bd9Sstevel@tonic-gate mdb_warn("sysevent does not support global walks");
1317c478bd9Sstevel@tonic-gate return (WALK_ERR);
1327c478bd9Sstevel@tonic-gate }
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate return (WALK_NEXT);
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate
1377c478bd9Sstevel@tonic-gate int
sysevent_walk_step(mdb_walk_state_t * wsp)1387c478bd9Sstevel@tonic-gate sysevent_walk_step(mdb_walk_state_t *wsp)
1397c478bd9Sstevel@tonic-gate {
1407c478bd9Sstevel@tonic-gate int status;
1417c478bd9Sstevel@tonic-gate sysevent_queue_t se_q;
1427c478bd9Sstevel@tonic-gate
143*892ad162SToomas Soome if (wsp->walk_addr == 0)
1447c478bd9Sstevel@tonic-gate return (WALK_DONE);
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate if (mdb_vread(&se_q, sizeof (se_q), wsp->walk_addr) == -1) {
1477c478bd9Sstevel@tonic-gate mdb_warn("failed to read sysevent queue at %p", wsp->walk_addr);
1487c478bd9Sstevel@tonic-gate return (WALK_ERR);
1497c478bd9Sstevel@tonic-gate }
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate status = wsp->walk_callback((uintptr_t)se_q.sq_ev, NULL,
1527c478bd9Sstevel@tonic-gate wsp->walk_cbdata);
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate wsp->walk_addr = (uintptr_t)se_q.sq_next;
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate return (status);
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate
1597c478bd9Sstevel@tonic-gate static const mdb_walker_t walkers[] = {
1607c478bd9Sstevel@tonic-gate { "sysevent", "walk sysevent buffer queue",
1617c478bd9Sstevel@tonic-gate sysevent_walk_init, sysevent_walk_step,
1627c478bd9Sstevel@tonic-gate NULL },
1637c478bd9Sstevel@tonic-gate { "sysevent_class_list", "walk sysevent subsccription class list",
1647c478bd9Sstevel@tonic-gate sysevent_class_list_walk_init, sysevent_class_list_walk_step,
1657c478bd9Sstevel@tonic-gate sysevent_class_list_walk_fini },
1667c478bd9Sstevel@tonic-gate { "sysevent_subclass_list", "walk sysevent subsccription subclass list",
1677c478bd9Sstevel@tonic-gate sysevent_subclass_list_walk_init,
1687c478bd9Sstevel@tonic-gate sysevent_subclass_list_walk_step, NULL },
1697c478bd9Sstevel@tonic-gate { NULL }
1707c478bd9Sstevel@tonic-gate };
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate static const mdb_modinfo_t modinfo = {
1737c478bd9Sstevel@tonic-gate MDB_API_VERSION, dcmds, walkers
1747c478bd9Sstevel@tonic-gate };
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate const mdb_modinfo_t *
_mdb_init(void)1777c478bd9Sstevel@tonic-gate _mdb_init(void)
1787c478bd9Sstevel@tonic-gate {
1797c478bd9Sstevel@tonic-gate return (&modinfo);
1807c478bd9Sstevel@tonic-gate }
181