10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52112Sav145390 * Common Development and Distribution License (the "License"). 62112Sav145390 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211193Smws 220Sstevel@tonic-gate /* 239120SStephen.Hanson@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #include <sys/types.h> 280Sstevel@tonic-gate #include <sys/utsname.h> 290Sstevel@tonic-gate #include <sys/param.h> 300Sstevel@tonic-gate #include <sys/systeminfo.h> 310Sstevel@tonic-gate #include <sys/fm/util.h> 320Sstevel@tonic-gate 331414Scindi #include <smbios.h> 340Sstevel@tonic-gate #include <limits.h> 350Sstevel@tonic-gate #include <unistd.h> 360Sstevel@tonic-gate #include <signal.h> 370Sstevel@tonic-gate #include <stdlib.h> 380Sstevel@tonic-gate #include <stdio.h> 399874SStephen.Hanson@Sun.COM #include <ctype.h> 401193Smws #include <door.h> 410Sstevel@tonic-gate 420Sstevel@tonic-gate #include <fmd_conf.h> 430Sstevel@tonic-gate #include <fmd_dispq.h> 440Sstevel@tonic-gate #include <fmd_timerq.h> 450Sstevel@tonic-gate #include <fmd_subr.h> 460Sstevel@tonic-gate #include <fmd_error.h> 470Sstevel@tonic-gate #include <fmd_module.h> 480Sstevel@tonic-gate #include <fmd_thread.h> 490Sstevel@tonic-gate #include <fmd_alloc.h> 500Sstevel@tonic-gate #include <fmd_string.h> 510Sstevel@tonic-gate #include <fmd_builtin.h> 520Sstevel@tonic-gate #include <fmd_ustat.h> 530Sstevel@tonic-gate #include <fmd_protocol.h> 540Sstevel@tonic-gate #include <fmd_scheme.h> 550Sstevel@tonic-gate #include <fmd_asru.h> 560Sstevel@tonic-gate #include <fmd_case.h> 570Sstevel@tonic-gate #include <fmd_log.h> 581193Smws #include <fmd_idspace.h> 590Sstevel@tonic-gate #include <fmd_rpc.h> 600Sstevel@tonic-gate #include <fmd_dr.h> 613062Scindi #include <fmd_topo.h> 621193Smws #include <fmd_xprt.h> 631193Smws #include <fmd_ctl.h> 642112Sav145390 #include <sys/openpromio.h> 652112Sav145390 #include <libdevinfo.h> 660Sstevel@tonic-gate 670Sstevel@tonic-gate #include <fmd.h> 680Sstevel@tonic-gate 690Sstevel@tonic-gate extern const nv_alloc_ops_t fmd_nv_alloc_ops; /* see fmd_nv.c */ 700Sstevel@tonic-gate 714198Seschrock const char _fmd_version[] = "1.2"; /* daemon version string */ 720Sstevel@tonic-gate static char _fmd_plat[MAXNAMELEN]; /* native platform string */ 730Sstevel@tonic-gate static char _fmd_isa[MAXNAMELEN]; /* native instruction set */ 740Sstevel@tonic-gate static struct utsname _fmd_uts; /* native uname(2) info */ 75*10462SSean.Ye@Sun.COM static char _fmd_psn[MAXNAMELEN]; /* product serial number */ 761414Scindi static char _fmd_csn[MAXNAMELEN]; /* chassis serial number */ 771414Scindi static char _fmd_prod[MAXNAMELEN]; /* product name string */ 780Sstevel@tonic-gate 790Sstevel@tonic-gate /* 800Sstevel@tonic-gate * Note: the configuration file path is ordered from most common to most host- 810Sstevel@tonic-gate * specific because new conf files are merged/override previous ones. The 820Sstevel@tonic-gate * module paths are in the opposite order, from most specific to most common, 830Sstevel@tonic-gate * because once a module is loaded fmd will not try to load over the same name. 840Sstevel@tonic-gate */ 850Sstevel@tonic-gate 860Sstevel@tonic-gate static const char _fmd_conf_path[] = 870Sstevel@tonic-gate "%r/usr/lib/fm/fmd:" 880Sstevel@tonic-gate "%r/usr/platform/%m/lib/fm/fmd:" 890Sstevel@tonic-gate "%r/usr/platform/%i/lib/fm/fmd:" 900Sstevel@tonic-gate "%r/etc/fm/fmd"; 910Sstevel@tonic-gate 920Sstevel@tonic-gate static const char _fmd_agent_path[] = 930Sstevel@tonic-gate "%r/usr/platform/%i/lib/fm/fmd/agents:" 940Sstevel@tonic-gate "%r/usr/platform/%m/lib/fm/fmd/agents:" 950Sstevel@tonic-gate "%r/usr/lib/fm/fmd/agents"; 960Sstevel@tonic-gate 970Sstevel@tonic-gate static const char _fmd_plugin_path[] = 980Sstevel@tonic-gate "%r/usr/platform/%i/lib/fm/fmd/plugins:" 990Sstevel@tonic-gate "%r/usr/platform/%m/lib/fm/fmd/plugins:" 1000Sstevel@tonic-gate "%r/usr/lib/fm/fmd/plugins"; 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate static const char _fmd_scheme_path[] = 1030Sstevel@tonic-gate "usr/lib/fm/fmd/schemes"; 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate static const fmd_conf_mode_t _fmd_cerror_modes[] = { 1060Sstevel@tonic-gate { "unload", "unload offending client module", FMD_CERROR_UNLOAD }, 1070Sstevel@tonic-gate { "stop", "stop daemon for debugger attach", FMD_CERROR_STOP }, 1080Sstevel@tonic-gate { "abort", "abort daemon and force core dump", FMD_CERROR_ABORT }, 1090Sstevel@tonic-gate { NULL, NULL, 0 } 1100Sstevel@tonic-gate }; 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate static const fmd_conf_mode_t _fmd_dbout_modes[] = { 1130Sstevel@tonic-gate { "stderr", "send debug messages to stderr", FMD_DBOUT_STDERR }, 1140Sstevel@tonic-gate { "syslog", "send debug messages to syslog", FMD_DBOUT_SYSLOG }, 1150Sstevel@tonic-gate { NULL, NULL, 0 } 1160Sstevel@tonic-gate }; 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate static const fmd_conf_mode_t _fmd_debug_modes[] = { 1190Sstevel@tonic-gate { "help", "display debugging modes and exit", FMD_DBG_HELP }, 1200Sstevel@tonic-gate { "mod", "debug module load/unload/locking", FMD_DBG_MOD }, 1210Sstevel@tonic-gate { "disp", "debug dispatch queue processing", FMD_DBG_DISP }, 1220Sstevel@tonic-gate { "xprt", "debug transport-specific routines", FMD_DBG_XPRT }, 1230Sstevel@tonic-gate { "evt", "debug event subsystem routines", FMD_DBG_EVT }, 1240Sstevel@tonic-gate { "log", "debug log subsystem routines", FMD_DBG_LOG }, 1250Sstevel@tonic-gate { "tmr", "debug timer subsystem routines", FMD_DBG_TMR }, 1260Sstevel@tonic-gate { "fmri", "debug fmri subsystem routines", FMD_DBG_FMRI }, 1270Sstevel@tonic-gate { "asru", "debug asru subsystem routines", FMD_DBG_ASRU }, 1280Sstevel@tonic-gate { "case", "debug case subsystem routines", FMD_DBG_CASE }, 1290Sstevel@tonic-gate { "ckpt", "debug checkpoint routines", FMD_DBG_CKPT }, 1300Sstevel@tonic-gate { "rpc", "debug rpc service routines", FMD_DBG_RPC }, 1311193Smws { "trace", "display matching trace calls", FMD_DBG_TRACE }, 1320Sstevel@tonic-gate { "all", "enable all available debug modes", FMD_DBG_ALL }, 1330Sstevel@tonic-gate { NULL, NULL, 0 } 1340Sstevel@tonic-gate }; 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate static int 1370Sstevel@tonic-gate fmd_cerror_set(fmd_conf_param_t *pp, const char *value) 1380Sstevel@tonic-gate { 1390Sstevel@tonic-gate return (fmd_conf_mode_set(_fmd_cerror_modes, pp, value)); 1400Sstevel@tonic-gate } 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate static int 1430Sstevel@tonic-gate fmd_dbout_set(fmd_conf_param_t *pp, const char *value) 1440Sstevel@tonic-gate { 1450Sstevel@tonic-gate return (fmd_conf_mode_set(_fmd_dbout_modes, pp, value)); 1460Sstevel@tonic-gate } 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate static int 1490Sstevel@tonic-gate fmd_debug_set(fmd_conf_param_t *pp, const char *value) 1500Sstevel@tonic-gate { 1510Sstevel@tonic-gate int err = fmd_conf_mode_set(_fmd_debug_modes, pp, value); 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate if (err == 0) 1540Sstevel@tonic-gate fmd.d_fmd_debug = pp->cp_value.cpv_num; 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate return (err); 1570Sstevel@tonic-gate } 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate static int 1600Sstevel@tonic-gate fmd_trmode_set(fmd_conf_param_t *pp, const char *value) 1610Sstevel@tonic-gate { 1620Sstevel@tonic-gate fmd_tracebuf_f *func; 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate if (strcasecmp(value, "none") == 0) 1650Sstevel@tonic-gate func = fmd_trace_none; 1660Sstevel@tonic-gate else if (strcasecmp(value, "lite") == 0) 1670Sstevel@tonic-gate func = fmd_trace_lite; 1680Sstevel@tonic-gate else if (strcasecmp(value, "full") == 0) 1690Sstevel@tonic-gate func = fmd_trace_full; 1700Sstevel@tonic-gate else 1710Sstevel@tonic-gate return (fmd_set_errno(EFMD_CONF_INVAL)); 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate fmd.d_thr_trace = (void (*)())func; 1740Sstevel@tonic-gate pp->cp_value.cpv_ptr = (void *)func; 1750Sstevel@tonic-gate return (0); 1760Sstevel@tonic-gate } 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate static void 1790Sstevel@tonic-gate fmd_trmode_get(const fmd_conf_param_t *pp, void *ptr) 1800Sstevel@tonic-gate { 1810Sstevel@tonic-gate *((void **)ptr) = pp->cp_value.cpv_ptr; 1820Sstevel@tonic-gate } 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate static int 1850Sstevel@tonic-gate fmd_clkmode_set(fmd_conf_param_t *pp, const char *value) 1860Sstevel@tonic-gate { 1870Sstevel@tonic-gate const fmd_timeops_t *ops; 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate if (strcasecmp(value, "native") == 0) 1900Sstevel@tonic-gate ops = &fmd_timeops_native; 1910Sstevel@tonic-gate else if (strcasecmp(value, "simulated") == 0) 1920Sstevel@tonic-gate ops = &fmd_timeops_simulated; 1930Sstevel@tonic-gate else 1940Sstevel@tonic-gate return (fmd_set_errno(EFMD_CONF_INVAL)); 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate fmd.d_clockops = ops; 1970Sstevel@tonic-gate pp->cp_value.cpv_ptr = (void *)ops; 1980Sstevel@tonic-gate return (0); 1990Sstevel@tonic-gate } 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate static void 2020Sstevel@tonic-gate fmd_clkmode_get(const fmd_conf_param_t *pp, void *ptr) 2030Sstevel@tonic-gate { 2040Sstevel@tonic-gate *((void **)ptr) = pp->cp_value.cpv_ptr; 2050Sstevel@tonic-gate } 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate static const fmd_conf_ops_t fmd_cerror_ops = { 2080Sstevel@tonic-gate fmd_cerror_set, fmd_conf_mode_get, fmd_conf_notsup, fmd_conf_nop 2090Sstevel@tonic-gate }; 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate static const fmd_conf_ops_t fmd_dbout_ops = { 2120Sstevel@tonic-gate fmd_dbout_set, fmd_conf_mode_get, fmd_conf_notsup, fmd_conf_nop 2130Sstevel@tonic-gate }; 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate static const fmd_conf_ops_t fmd_debug_ops = { 2160Sstevel@tonic-gate fmd_debug_set, fmd_conf_mode_get, fmd_conf_notsup, fmd_conf_nop 2170Sstevel@tonic-gate }; 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate static const fmd_conf_ops_t fmd_trmode_ops = { 2200Sstevel@tonic-gate fmd_trmode_set, fmd_trmode_get, fmd_conf_notsup, fmd_conf_nop 2210Sstevel@tonic-gate }; 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate static const fmd_conf_ops_t fmd_clkmode_ops = { 2240Sstevel@tonic-gate fmd_clkmode_set, fmd_clkmode_get, fmd_conf_notsup, fmd_conf_nop 2250Sstevel@tonic-gate }; 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate static const fmd_conf_formal_t _fmd_conf[] = { 2280Sstevel@tonic-gate { "agent.path", &fmd_conf_path, _fmd_agent_path }, /* path for agents */ 2290Sstevel@tonic-gate { "alloc_msecs", &fmd_conf_uint32, "10" }, /* msecs before alloc retry */ 2300Sstevel@tonic-gate { "alloc_tries", &fmd_conf_uint32, "3" }, /* max # of alloc retries */ 231*10462SSean.Ye@Sun.COM { "product_sn", &fmd_conf_string, _fmd_psn }, /* product serial number */ 2321414Scindi { "chassis", &fmd_conf_string, _fmd_csn }, /* chassis serial number */ 2330Sstevel@tonic-gate { "ckpt.dir", &fmd_conf_string, "var/fm/fmd/ckpt" }, /* ckpt directory path */ 2340Sstevel@tonic-gate { "ckpt.dirmode", &fmd_conf_int32, "0700" }, /* ckpt directory perm mode */ 2350Sstevel@tonic-gate { "ckpt.mode", &fmd_conf_int32, "0400" }, /* ckpt file perm mode */ 2360Sstevel@tonic-gate { "ckpt.restore", &fmd_conf_bool, "true" }, /* restore checkpoints? */ 2370Sstevel@tonic-gate { "ckpt.save", &fmd_conf_bool, "true" }, /* save checkpoints? */ 2380Sstevel@tonic-gate { "ckpt.zero", &fmd_conf_bool, "false" }, /* zero checkpoints on start? */ 2390Sstevel@tonic-gate { "client.buflim", &fmd_conf_size, "10m" }, /* client buffer space limit */ 2400Sstevel@tonic-gate { "client.dbout", &fmd_dbout_ops, NULL }, /* client debug output sinks */ 2410Sstevel@tonic-gate { "client.debug", &fmd_conf_bool, NULL }, /* client debug enable */ 2420Sstevel@tonic-gate { "client.error", &fmd_cerror_ops, "unload" }, /* client error policy */ 2430Sstevel@tonic-gate { "client.memlim", &fmd_conf_size, "10m" }, /* client allocation limit */ 2440Sstevel@tonic-gate { "client.evqlim", &fmd_conf_uint32, "256" }, /* client event queue limit */ 2457850SVuong.Nguyen@Sun.COM { "client.thrlim", &fmd_conf_uint32, "20" }, /* client aux thread limit */ 2460Sstevel@tonic-gate { "client.thrsig", &fmd_conf_signal, "SIGUSR1" }, /* fmd_thr_signal() value */ 2470Sstevel@tonic-gate { "client.tmrlim", &fmd_conf_uint32, "1024" }, /* client pending timer limit */ 2481193Smws { "client.xprtlim", &fmd_conf_uint32, "256" }, /* client transport limit */ 2491193Smws { "client.xprtlog", &fmd_conf_bool, NULL }, /* client transport logging? */ 2502808Sav145390 { "client.xprtqlim", &fmd_conf_uint32, "1024" }, /* client transport queue li */ 2510Sstevel@tonic-gate { "clock", &fmd_clkmode_ops, "native" }, /* clock operation mode */ 2520Sstevel@tonic-gate { "conf_path", &fmd_conf_path, _fmd_conf_path }, /* root config file path */ 2530Sstevel@tonic-gate { "conf_file", &fmd_conf_string, "fmd.conf" }, /* root config file name */ 2540Sstevel@tonic-gate { "core", &fmd_conf_bool, "false" }, /* force core dump on quit */ 2550Sstevel@tonic-gate { "dbout", &fmd_dbout_ops, NULL }, /* daemon debug output sinks */ 2560Sstevel@tonic-gate { "debug", &fmd_debug_ops, NULL }, /* daemon debugging flags */ 2570Sstevel@tonic-gate { "dictdir", &fmd_conf_string, "usr/lib/fm/dict" }, /* default diagcode dir */ 2580Sstevel@tonic-gate { "domain", &fmd_conf_string, NULL }, /* domain id for de auth */ 2597275Sstephh { "fakenotpresent", &fmd_conf_uint32, "0" }, /* simulate rsrc not present */ 2600Sstevel@tonic-gate { "fg", &fmd_conf_bool, "false" }, /* run daemon in foreground */ 2610Sstevel@tonic-gate { "gc_interval", &fmd_conf_time, "1d" }, /* garbage collection intvl */ 2620Sstevel@tonic-gate { "ids.avg", &fmd_conf_uint32, "4" }, /* desired idspace chain len */ 2630Sstevel@tonic-gate { "ids.max", &fmd_conf_uint32, "1024" }, /* maximum idspace buckets */ 2640Sstevel@tonic-gate { "isaname", &fmd_conf_string, _fmd_isa }, /* instruction set (uname -p) */ 2650Sstevel@tonic-gate { "log.creator", &fmd_conf_string, "fmd" }, /* exacct log creator string */ 2660Sstevel@tonic-gate { "log.error", &fmd_conf_string, "var/fm/fmd/errlog" }, /* error log path */ 2670Sstevel@tonic-gate { "log.fault", &fmd_conf_string, "var/fm/fmd/fltlog" }, /* fault log path */ 2680Sstevel@tonic-gate { "log.minfree", &fmd_conf_size, "2m" }, /* min log fsys free space */ 2691193Smws { "log.rsrc", &fmd_conf_string, "var/fm/fmd/rsrc" }, /* asru log dir path */ 2700Sstevel@tonic-gate { "log.tryrotate", &fmd_conf_uint32, "10" }, /* max log rotation attempts */ 2710Sstevel@tonic-gate { "log.waitrotate", &fmd_conf_time, "200ms" }, /* log rotation retry delay */ 2721193Smws { "log.xprt", &fmd_conf_string, "var/fm/fmd/xprt" }, /* transport log dir */ 2730Sstevel@tonic-gate { "machine", &fmd_conf_string, _fmd_uts.machine }, /* machine name (uname -m) */ 2740Sstevel@tonic-gate { "nodiagcode", &fmd_conf_string, "-" }, /* diagcode to use if error */ 2756276Scy152378 { "repaircode", &fmd_conf_string, "-" }, /* diagcode for list.repaired */ 2767275Sstephh { "resolvecode", &fmd_conf_string, "-" }, /* diagcode for list.resolved */ 2777275Sstephh { "updatecode", &fmd_conf_string, "-" }, /* diagcode for list.updated */ 2780Sstevel@tonic-gate { "osrelease", &fmd_conf_string, _fmd_uts.release }, /* release (uname -r) */ 2790Sstevel@tonic-gate { "osversion", &fmd_conf_string, _fmd_uts.version }, /* version (uname -v) */ 2800Sstevel@tonic-gate { "platform", &fmd_conf_string, _fmd_plat }, /* platform string (uname -i) */ 2810Sstevel@tonic-gate { "plugin.close", &fmd_conf_bool, "true" }, /* dlclose plugins on fini */ 2820Sstevel@tonic-gate { "plugin.path", &fmd_conf_path, _fmd_plugin_path }, /* path for plugin mods */ 2831414Scindi { "product", &fmd_conf_string, _fmd_prod }, /* product name string */ 2840Sstevel@tonic-gate { "rootdir", &fmd_conf_string, "" }, /* root directory for paths */ 2850Sstevel@tonic-gate { "rpc.adm.path", &fmd_conf_string, NULL }, /* FMD_ADM rendezvous file */ 2860Sstevel@tonic-gate { "rpc.adm.prog", &fmd_conf_uint32, "100169" }, /* FMD_ADM rpc program num */ 2870Sstevel@tonic-gate { "rpc.api.path", &fmd_conf_string, NULL }, /* FMD_API rendezvous file */ 2880Sstevel@tonic-gate { "rpc.api.prog", &fmd_conf_uint32, "100170" }, /* FMD_API rpc program num */ 2890Sstevel@tonic-gate { "rpc.rcvsize", &fmd_conf_size, "128k" }, /* rpc receive buffer size */ 2900Sstevel@tonic-gate { "rpc.sndsize", &fmd_conf_size, "128k" }, /* rpc send buffer size */ 2910Sstevel@tonic-gate { "rsrc.age", &fmd_conf_time, "30d" }, /* max age of old rsrc log */ 2920Sstevel@tonic-gate { "rsrc.zero", &fmd_conf_bool, "false" }, /* zero rsrc cache on start? */ 2930Sstevel@tonic-gate { "schemedir", &fmd_conf_string, _fmd_scheme_path }, /* path for scheme mods */ 2940Sstevel@tonic-gate { "self.name", &fmd_conf_string, "fmd-self-diagnosis" }, /* self-diag module */ 2950Sstevel@tonic-gate { "self.dict", &fmd_conf_list, "FMD.dict" }, /* self-diag dictionary list */ 2960Sstevel@tonic-gate { "server", &fmd_conf_string, _fmd_uts.nodename }, /* server id for de auth */ 2970Sstevel@tonic-gate { "strbuckets", &fmd_conf_uint32, "211" }, /* size of string hashes */ 2980Sstevel@tonic-gate #ifdef DEBUG 2990Sstevel@tonic-gate { "trace.mode", &fmd_trmode_ops, "full" }, /* trace mode: none/lite/full */ 3000Sstevel@tonic-gate #else 3010Sstevel@tonic-gate { "trace.mode", &fmd_trmode_ops, "lite" }, /* trace mode: none/lite/full */ 3020Sstevel@tonic-gate #endif 3030Sstevel@tonic-gate { "trace.recs", &fmd_conf_uint32, "128" }, /* trace records per thread */ 3040Sstevel@tonic-gate { "trace.frames", &fmd_conf_uint32, "16" }, /* max trace rec stack frames */ 3050Sstevel@tonic-gate { "uuidlen", &fmd_conf_uint32, "36" }, /* UUID ASCII string length */ 3061193Smws { "xprt.ttl", &fmd_conf_uint8, "1" }, /* default event time-to-live */ 3070Sstevel@tonic-gate }; 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate /* 3100Sstevel@tonic-gate * Statistics maintained by fmd itself on behalf of various global subsystems. 3110Sstevel@tonic-gate * NOTE: FMD_TYPE_STRING statistics should not be used here. If they are 3120Sstevel@tonic-gate * required in the future, the FMD_ADM_MODGSTAT service routine must change. 3130Sstevel@tonic-gate */ 3140Sstevel@tonic-gate static fmd_statistics_t _fmd_stats = { 3150Sstevel@tonic-gate { "errlog.replayed", FMD_TYPE_UINT64, "total events replayed from errlog" }, 3160Sstevel@tonic-gate { "errlog.partials", FMD_TYPE_UINT64, "events partially committed in errlog" }, 3170Sstevel@tonic-gate { "errlog.enospc", FMD_TYPE_UINT64, "events not appended to errlog (ENOSPC)" }, 3180Sstevel@tonic-gate { "fltlog.enospc", FMD_TYPE_UINT64, "events not appended to fltlog (ENOSPC)" }, 3190Sstevel@tonic-gate { "log.enospc", FMD_TYPE_UINT64, "events not appended to other logs (ENOSPC)" }, 3200Sstevel@tonic-gate { "dr.gen", FMD_TYPE_UINT64, "dynamic reconfiguration generation" }, 3213062Scindi { "topo.gen", FMD_TYPE_UINT64, "topology snapshot generation" }, 3223062Scindi { "topo.drgen", FMD_TYPE_UINT64, "current topology DR generation number" }, 3230Sstevel@tonic-gate }; 3240Sstevel@tonic-gate 3259874SStephen.Hanson@Sun.COM /* 3269874SStephen.Hanson@Sun.COM * SMBIOS serial numbers can contain characters (particularly ':' and ' ') 3279874SStephen.Hanson@Sun.COM * that are invalid for the authority and can break FMRI parsing. We translate 3289874SStephen.Hanson@Sun.COM * any invalid characters to a safe '-', as well as trimming any leading or 3299874SStephen.Hanson@Sun.COM * trailing whitespace. Similarly, '/' can be found in some product names 3309874SStephen.Hanson@Sun.COM * so we translate that to '-'. 3319874SStephen.Hanson@Sun.COM */ 3329874SStephen.Hanson@Sun.COM void 3339874SStephen.Hanson@Sun.COM fmd_cleanup_auth_str(char *buf, const char *begin) 3349874SStephen.Hanson@Sun.COM { 3359874SStephen.Hanson@Sun.COM const char *end, *cp; 3369874SStephen.Hanson@Sun.COM char c; 3379874SStephen.Hanson@Sun.COM int i; 3389874SStephen.Hanson@Sun.COM 3399874SStephen.Hanson@Sun.COM end = begin + strlen(begin); 3409874SStephen.Hanson@Sun.COM 3419874SStephen.Hanson@Sun.COM while (begin < end && isspace(*begin)) 3429874SStephen.Hanson@Sun.COM begin++; 3439874SStephen.Hanson@Sun.COM while (begin < end && isspace(*(end - 1))) 3449874SStephen.Hanson@Sun.COM end--; 3459874SStephen.Hanson@Sun.COM 3469874SStephen.Hanson@Sun.COM if (begin >= end) 3479874SStephen.Hanson@Sun.COM return; 3489874SStephen.Hanson@Sun.COM 3499874SStephen.Hanson@Sun.COM cp = begin; 3509874SStephen.Hanson@Sun.COM for (i = 0; i < MAXNAMELEN - 1; i++) { 3519874SStephen.Hanson@Sun.COM if (cp >= end) 3529874SStephen.Hanson@Sun.COM break; 3539874SStephen.Hanson@Sun.COM c = *cp; 3549874SStephen.Hanson@Sun.COM if (c == ':' || c == '=' || c == '/' || isspace(c) || 3559874SStephen.Hanson@Sun.COM !isprint(c)) 3569874SStephen.Hanson@Sun.COM buf[i] = '-'; 3579874SStephen.Hanson@Sun.COM else 3589874SStephen.Hanson@Sun.COM buf[i] = c; 3599874SStephen.Hanson@Sun.COM cp++; 3609874SStephen.Hanson@Sun.COM } 3619874SStephen.Hanson@Sun.COM buf[i] = 0; 3629874SStephen.Hanson@Sun.COM } 3639874SStephen.Hanson@Sun.COM 3640Sstevel@tonic-gate void 3650Sstevel@tonic-gate fmd_create(fmd_t *dp, const char *arg0, const char *root, const char *conf) 3660Sstevel@tonic-gate { 3670Sstevel@tonic-gate fmd_conf_path_t *pap; 3680Sstevel@tonic-gate char file[PATH_MAX]; 369*10462SSean.Ye@Sun.COM const char *name, *psn, *csn; 3700Sstevel@tonic-gate fmd_stat_t *sp; 3710Sstevel@tonic-gate int i; 3720Sstevel@tonic-gate 3731414Scindi smbios_hdl_t *shp; 3741414Scindi smbios_system_t s1; 3751414Scindi smbios_info_t s2; 3761414Scindi id_t id; 3771414Scindi 3782112Sav145390 di_prom_handle_t promh = DI_PROM_HANDLE_NIL; 3792112Sav145390 di_node_t rooth = DI_NODE_NIL; 3802112Sav145390 char *bufp; 3812112Sav145390 3820Sstevel@tonic-gate (void) sysinfo(SI_PLATFORM, _fmd_plat, sizeof (_fmd_plat)); 3830Sstevel@tonic-gate (void) sysinfo(SI_ARCHITECTURE, _fmd_isa, sizeof (_fmd_isa)); 3840Sstevel@tonic-gate (void) uname(&_fmd_uts); 3850Sstevel@tonic-gate 3861414Scindi if ((shp = smbios_open(NULL, SMB_VERSION, 0, NULL)) != NULL) { 3871414Scindi if ((id = smbios_info_system(shp, &s1)) != SMB_ERR && 388*10462SSean.Ye@Sun.COM smbios_info_common(shp, id, &s2) != SMB_ERR) 3899874SStephen.Hanson@Sun.COM fmd_cleanup_auth_str(_fmd_prod, s2.smbi_product); 390*10462SSean.Ye@Sun.COM 391*10462SSean.Ye@Sun.COM if ((psn = smbios_psn(shp)) != NULL) 392*10462SSean.Ye@Sun.COM fmd_cleanup_auth_str(_fmd_psn, psn); 393*10462SSean.Ye@Sun.COM 394*10462SSean.Ye@Sun.COM if ((csn = smbios_csn(shp)) != NULL) 395*10462SSean.Ye@Sun.COM fmd_cleanup_auth_str(_fmd_csn, csn); 396*10462SSean.Ye@Sun.COM 3971414Scindi smbios_close(shp); 3982338Shueston } else if ((rooth = di_init("/", DINFOPROP)) != DI_NODE_NIL && 3992112Sav145390 (promh = di_prom_init()) != DI_PROM_HANDLE_NIL) { 4002112Sav145390 if (di_prom_prop_lookup_bytes(promh, rooth, "chassis-sn", 4012112Sav145390 (unsigned char **)&bufp) != -1) { 4029874SStephen.Hanson@Sun.COM fmd_cleanup_auth_str(_fmd_csn, bufp); 4032112Sav145390 } 4041414Scindi } 4051414Scindi 4062112Sav145390 if (promh != DI_PROM_HANDLE_NIL) 4072112Sav145390 di_prom_fini(promh); 4082112Sav145390 if (rooth != DI_NODE_NIL) 4092112Sav145390 di_fini(rooth); 4102112Sav145390 4110Sstevel@tonic-gate bzero(dp, sizeof (fmd_t)); 4120Sstevel@tonic-gate 4130Sstevel@tonic-gate dp->d_version = _fmd_version; 4140Sstevel@tonic-gate dp->d_pname = fmd_strbasename(arg0); 4150Sstevel@tonic-gate dp->d_pid = getpid(); 4160Sstevel@tonic-gate 4170Sstevel@tonic-gate if (pthread_key_create(&dp->d_key, NULL) != 0) 4180Sstevel@tonic-gate fmd_error(EFMD_EXIT, "failed to create pthread key"); 4190Sstevel@tonic-gate 4200Sstevel@tonic-gate (void) pthread_mutex_init(&dp->d_xprt_lock, NULL); 4210Sstevel@tonic-gate (void) pthread_mutex_init(&dp->d_err_lock, NULL); 4220Sstevel@tonic-gate (void) pthread_mutex_init(&dp->d_thr_lock, NULL); 4230Sstevel@tonic-gate (void) pthread_mutex_init(&dp->d_mod_lock, NULL); 4240Sstevel@tonic-gate (void) pthread_mutex_init(&dp->d_stats_lock, NULL); 4253062Scindi (void) pthread_mutex_init(&dp->d_topo_lock, NULL); 4260Sstevel@tonic-gate (void) pthread_rwlock_init(&dp->d_log_lock, NULL); 4276559Sstephh (void) pthread_mutex_init(&dp->d_fmd_lock, NULL); 4286559Sstephh (void) pthread_cond_init(&dp->d_fmd_cv, NULL); 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate /* 4310Sstevel@tonic-gate * A small number of properties must be set manually before we open 4320Sstevel@tonic-gate * the root configuration file. These include any settings for our 4330Sstevel@tonic-gate * memory allocator and path expansion token values, because these 4340Sstevel@tonic-gate * values are needed by the routines in fmd_conf.c itself. After 4350Sstevel@tonic-gate * the root configuration file is processed, we reset these properties 4360Sstevel@tonic-gate * based upon the latest values from the configuration file. 4370Sstevel@tonic-gate */ 4380Sstevel@tonic-gate dp->d_alloc_msecs = 10; 4390Sstevel@tonic-gate dp->d_alloc_tries = 3; 4400Sstevel@tonic-gate dp->d_str_buckets = 211; 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate dp->d_rootdir = root ? root : ""; 4430Sstevel@tonic-gate dp->d_platform = _fmd_plat; 4440Sstevel@tonic-gate dp->d_machine = _fmd_uts.machine; 4450Sstevel@tonic-gate dp->d_isaname = _fmd_isa; 4460Sstevel@tonic-gate 4471193Smws dp->d_conf = fmd_conf_open(conf, sizeof (_fmd_conf) / 4481193Smws sizeof (_fmd_conf[0]), _fmd_conf, FMD_CONF_DEFER); 4490Sstevel@tonic-gate 4500Sstevel@tonic-gate if (dp->d_conf == NULL) { 4510Sstevel@tonic-gate fmd_error(EFMD_EXIT, 4520Sstevel@tonic-gate "failed to load required configuration properties\n"); 4530Sstevel@tonic-gate } 4540Sstevel@tonic-gate 4550Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "alloc.msecs", &dp->d_alloc_msecs); 4560Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "alloc.tries", &dp->d_alloc_tries); 4570Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "strbuckets", &dp->d_str_buckets); 4580Sstevel@tonic-gate 4590Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "platform", &dp->d_platform); 4600Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "machine", &dp->d_machine); 4610Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "isaname", &dp->d_isaname); 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate /* 4640Sstevel@tonic-gate * Manually specified rootdirs override config files, so only update 4650Sstevel@tonic-gate * d_rootdir based on the config files we parsed if no 'root' was set. 4660Sstevel@tonic-gate */ 4670Sstevel@tonic-gate if (root == NULL) 4680Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "rootdir", &dp->d_rootdir); 4690Sstevel@tonic-gate else 4700Sstevel@tonic-gate (void) fmd_conf_setprop(dp->d_conf, "rootdir", dp->d_rootdir); 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate /* 4730Sstevel@tonic-gate * Once the base conf file properties are loaded, lookup the values 4740Sstevel@tonic-gate * of $conf_path and $conf_file and merge in any other conf files. 4750Sstevel@tonic-gate */ 4760Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "conf_path", &pap); 4770Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "conf_file", &name); 4780Sstevel@tonic-gate 4790Sstevel@tonic-gate for (i = 0; i < pap->cpa_argc; i++) { 4800Sstevel@tonic-gate (void) snprintf(file, sizeof (file), 4810Sstevel@tonic-gate "%s/%s", pap->cpa_argv[i], name); 4820Sstevel@tonic-gate if (access(file, F_OK) == 0) 4830Sstevel@tonic-gate fmd_conf_merge(dp->d_conf, file); 4840Sstevel@tonic-gate } 4850Sstevel@tonic-gate 4860Sstevel@tonic-gate /* 4870Sstevel@tonic-gate * Update the value of fmd.d_fg based on "fg". We cache this property 4880Sstevel@tonic-gate * because it must be accessed deep within fmd at fmd_verror() time. 4891193Smws * Update any other properties that must be cached for performance. 4900Sstevel@tonic-gate */ 4910Sstevel@tonic-gate (void) fmd_conf_getprop(fmd.d_conf, "fg", &fmd.d_fg); 4921193Smws (void) fmd_conf_getprop(fmd.d_conf, "xprt.ttl", &fmd.d_xprt_ttl); 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate /* 4950Sstevel@tonic-gate * Initialize our custom libnvpair allocator and create an nvlist for 4960Sstevel@tonic-gate * authority elements corresponding to this instance of the daemon. 4970Sstevel@tonic-gate */ 4980Sstevel@tonic-gate (void) nv_alloc_init(&dp->d_nva, &fmd_nv_alloc_ops); 4990Sstevel@tonic-gate dp->d_auth = fmd_protocol_authority(); 5000Sstevel@tonic-gate 5010Sstevel@tonic-gate /* 5020Sstevel@tonic-gate * The fmd_module_t for the root module must be created manually. Most 5030Sstevel@tonic-gate * of it remains unused and zero, except for the few things we fill in. 5040Sstevel@tonic-gate */ 5050Sstevel@tonic-gate dp->d_rmod = fmd_zalloc(sizeof (fmd_module_t), FMD_SLEEP); 5060Sstevel@tonic-gate dp->d_rmod->mod_name = fmd_strdup(dp->d_pname, FMD_SLEEP); 5071193Smws dp->d_rmod->mod_fmri = fmd_protocol_fmri_module(dp->d_rmod); 5081193Smws 5090Sstevel@tonic-gate fmd_list_append(&dp->d_mod_list, dp->d_rmod); 5101193Smws fmd_module_hold(dp->d_rmod); 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate (void) pthread_mutex_init(&dp->d_rmod->mod_lock, NULL); 5130Sstevel@tonic-gate (void) pthread_cond_init(&dp->d_rmod->mod_cv, NULL); 5141193Smws (void) pthread_mutex_init(&dp->d_rmod->mod_stats_lock, NULL); 5150Sstevel@tonic-gate 5160Sstevel@tonic-gate dp->d_rmod->mod_thread = fmd_thread_xcreate(dp->d_rmod, pthread_self()); 5171193Smws dp->d_rmod->mod_stats = fmd_zalloc(sizeof (fmd_modstat_t), FMD_SLEEP); 5180Sstevel@tonic-gate dp->d_rmod->mod_ustat = fmd_ustat_create(); 5190Sstevel@tonic-gate 5200Sstevel@tonic-gate if (pthread_setspecific(dp->d_key, dp->d_rmod->mod_thread) != 0) 5210Sstevel@tonic-gate fmd_error(EFMD_EXIT, "failed to attach main thread key"); 5220Sstevel@tonic-gate 5230Sstevel@tonic-gate if ((dp->d_stats = (fmd_statistics_t *)fmd_ustat_insert( 5240Sstevel@tonic-gate dp->d_rmod->mod_ustat, FMD_USTAT_NOALLOC, sizeof (_fmd_stats) / 5250Sstevel@tonic-gate sizeof (fmd_stat_t), (fmd_stat_t *)&_fmd_stats, NULL)) == NULL) 5260Sstevel@tonic-gate fmd_error(EFMD_EXIT, "failed to initialize statistics"); 5270Sstevel@tonic-gate 5281193Smws (void) pthread_mutex_lock(&dp->d_rmod->mod_lock); 5291193Smws dp->d_rmod->mod_flags |= FMD_MOD_INIT; 5301193Smws (void) pthread_mutex_unlock(&dp->d_rmod->mod_lock); 5311193Smws 5320Sstevel@tonic-gate /* 5330Sstevel@tonic-gate * In addition to inserting the _fmd_stats collection of program-wide 5340Sstevel@tonic-gate * statistics, we also insert a statistic named after each of our 5350Sstevel@tonic-gate * errors and update these counts in fmd_verror() (see fmd_subr.c). 5360Sstevel@tonic-gate */ 5370Sstevel@tonic-gate dp->d_errstats = sp = fmd_zalloc(sizeof (fmd_stat_t) * 5380Sstevel@tonic-gate (EFMD_END - EFMD_UNKNOWN), FMD_SLEEP); 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate for (i = 0; i < EFMD_END - EFMD_UNKNOWN; i++, sp++) { 5410Sstevel@tonic-gate (void) snprintf(sp->fmds_name, sizeof (sp->fmds_name), "err.%s", 5420Sstevel@tonic-gate strrchr(fmd_errclass(EFMD_UNKNOWN + i), '.') + 1); 5430Sstevel@tonic-gate sp->fmds_type = FMD_TYPE_UINT64; 5440Sstevel@tonic-gate } 5450Sstevel@tonic-gate 5460Sstevel@tonic-gate (void) fmd_ustat_insert(dp->d_rmod->mod_ustat, FMD_USTAT_NOALLOC, 5470Sstevel@tonic-gate EFMD_END - EFMD_UNKNOWN, dp->d_errstats, NULL); 5480Sstevel@tonic-gate } 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate void 5510Sstevel@tonic-gate fmd_destroy(fmd_t *dp) 5520Sstevel@tonic-gate { 5530Sstevel@tonic-gate fmd_module_t *mp; 5541193Smws fmd_case_t *cp; 5550Sstevel@tonic-gate int core; 5560Sstevel@tonic-gate 5570Sstevel@tonic-gate (void) fmd_conf_getprop(fmd.d_conf, "core", &core); 5580Sstevel@tonic-gate 5590Sstevel@tonic-gate fmd_rpc_fini(); 5601222Smws 5611222Smws if (dp->d_xprt_ids != NULL) 5621222Smws fmd_xprt_suspend_all(); 5630Sstevel@tonic-gate 5640Sstevel@tonic-gate /* 5650Sstevel@tonic-gate * Unload the self-diagnosis module first. This ensures that it does 5660Sstevel@tonic-gate * not get confused as we start unloading other modules, etc. We must 5670Sstevel@tonic-gate * hold the dispq lock as a writer while doing so since it uses d_self. 5680Sstevel@tonic-gate */ 5690Sstevel@tonic-gate if (dp->d_self != NULL) { 5702438Scindi fmd_module_t *self; 5712438Scindi 5720Sstevel@tonic-gate (void) pthread_rwlock_wrlock(&dp->d_disp->dq_lock); 5732438Scindi self = dp->d_self; 5740Sstevel@tonic-gate dp->d_self = NULL; 5750Sstevel@tonic-gate (void) pthread_rwlock_unlock(&dp->d_disp->dq_lock); 5762438Scindi 5772438Scindi fmd_module_unload(self); 5782438Scindi fmd_module_rele(self); 5790Sstevel@tonic-gate } 5800Sstevel@tonic-gate 5810Sstevel@tonic-gate /* 5820Sstevel@tonic-gate * Unload modules in reverse order *except* for the root module, which 5830Sstevel@tonic-gate * is first in the list. This allows it to keep its thread and trace. 5840Sstevel@tonic-gate */ 5850Sstevel@tonic-gate for (mp = fmd_list_prev(&dp->d_mod_list); mp != dp->d_rmod; ) { 5860Sstevel@tonic-gate fmd_module_unload(mp); 5870Sstevel@tonic-gate mp = fmd_list_prev(mp); 5880Sstevel@tonic-gate } 5890Sstevel@tonic-gate 5900Sstevel@tonic-gate if (dp->d_mod_hash != NULL) { 5910Sstevel@tonic-gate fmd_modhash_destroy(dp->d_mod_hash); 5920Sstevel@tonic-gate dp->d_mod_hash = NULL; 5930Sstevel@tonic-gate } 5940Sstevel@tonic-gate 5950Sstevel@tonic-gate /* 5960Sstevel@tonic-gate * Close both log files now that modules are no longer active. We must 5970Sstevel@tonic-gate * set these pointers to NULL in case any subsequent errors occur. 5980Sstevel@tonic-gate */ 5990Sstevel@tonic-gate if (dp->d_errlog != NULL) { 6000Sstevel@tonic-gate fmd_log_rele(dp->d_errlog); 6010Sstevel@tonic-gate dp->d_errlog = NULL; 6020Sstevel@tonic-gate } 6030Sstevel@tonic-gate 6040Sstevel@tonic-gate if (dp->d_fltlog != NULL) { 6050Sstevel@tonic-gate fmd_log_rele(dp->d_fltlog); 6060Sstevel@tonic-gate dp->d_fltlog = NULL; 6070Sstevel@tonic-gate } 6080Sstevel@tonic-gate 6090Sstevel@tonic-gate /* 6101193Smws * Now destroy the resource cache: each ASRU contains a case reference, 6111193Smws * which may in turn contain a pointer to a referenced owning module. 6121193Smws */ 6131193Smws if (dp->d_asrus != NULL) { 6141193Smws fmd_asru_hash_destroy(dp->d_asrus); 6151193Smws dp->d_asrus = NULL; 6161193Smws } 6171193Smws 6181193Smws /* 6190Sstevel@tonic-gate * Now that all data structures that refer to modules are torn down, 6200Sstevel@tonic-gate * no modules should be remaining on the module list except for d_rmod. 6210Sstevel@tonic-gate * If we trip one of these assertions, we're missing a rele somewhere. 6220Sstevel@tonic-gate */ 6230Sstevel@tonic-gate ASSERT(fmd_list_prev(&dp->d_mod_list) == dp->d_rmod); 6240Sstevel@tonic-gate ASSERT(fmd_list_next(&dp->d_mod_list) == dp->d_rmod); 6250Sstevel@tonic-gate 6260Sstevel@tonic-gate /* 6270Sstevel@tonic-gate * Now destroy the root module. We clear its thread key first so any 6280Sstevel@tonic-gate * calls to fmd_trace() inside of the module code will be ignored. 6290Sstevel@tonic-gate */ 6300Sstevel@tonic-gate (void) pthread_setspecific(dp->d_key, NULL); 6311193Smws fmd_module_lock(dp->d_rmod); 6321193Smws 6331193Smws while ((cp = fmd_list_next(&dp->d_rmod->mod_cases)) != NULL) 6349120SStephen.Hanson@Sun.COM fmd_case_discard(cp, B_FALSE); 6351193Smws 6361193Smws fmd_module_unlock(dp->d_rmod); 6371193Smws fmd_free(dp->d_rmod->mod_stats, sizeof (fmd_modstat_t)); 6381193Smws dp->d_rmod->mod_stats = NULL; 6390Sstevel@tonic-gate 6401193Smws (void) pthread_mutex_lock(&dp->d_rmod->mod_lock); 6411193Smws dp->d_rmod->mod_flags |= FMD_MOD_FINI; 6421193Smws (void) pthread_mutex_unlock(&dp->d_rmod->mod_lock); 6431193Smws 6441193Smws fmd_module_rele(dp->d_rmod); 6451193Smws ASSERT(fmd_list_next(&dp->d_mod_list) == NULL); 6461193Smws 6471193Smws /* 6481193Smws * Now destroy the remaining global data structures. If 'core' was 6491193Smws * set to true, force a core dump so we can check for memory leaks. 6501193Smws */ 6511193Smws if (dp->d_cases != NULL) 6521193Smws fmd_case_hash_destroy(dp->d_cases); 6530Sstevel@tonic-gate if (dp->d_disp != NULL) 6540Sstevel@tonic-gate fmd_dispq_destroy(dp->d_disp); 6551193Smws if (dp->d_timers != NULL) 6561193Smws fmd_timerq_destroy(dp->d_timers); 6570Sstevel@tonic-gate if (dp->d_schemes != NULL) 6580Sstevel@tonic-gate fmd_scheme_hash_destroy(dp->d_schemes); 6591193Smws if (dp->d_xprt_ids != NULL) 6601193Smws fmd_idspace_destroy(dp->d_xprt_ids); 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate if (dp->d_errstats != NULL) { 6630Sstevel@tonic-gate fmd_free(dp->d_errstats, 6640Sstevel@tonic-gate sizeof (fmd_stat_t) * (EFMD_END - EFMD_UNKNOWN)); 6650Sstevel@tonic-gate } 6660Sstevel@tonic-gate 6670Sstevel@tonic-gate if (dp->d_conf != NULL) 6680Sstevel@tonic-gate fmd_conf_close(dp->d_conf); 6690Sstevel@tonic-gate 6703062Scindi fmd_topo_fini(); 6711414Scindi 6720Sstevel@tonic-gate nvlist_free(dp->d_auth); 6730Sstevel@tonic-gate (void) nv_alloc_fini(&dp->d_nva); 6740Sstevel@tonic-gate dp->d_clockops->fto_fini(dp->d_clockptr); 6750Sstevel@tonic-gate 6760Sstevel@tonic-gate (void) pthread_key_delete(dp->d_key); 6770Sstevel@tonic-gate bzero(dp, sizeof (fmd_t)); 6780Sstevel@tonic-gate 6790Sstevel@tonic-gate if (core) 6800Sstevel@tonic-gate fmd_panic("forcing core dump at user request\n"); 6810Sstevel@tonic-gate } 6820Sstevel@tonic-gate 6830Sstevel@tonic-gate /*ARGSUSED*/ 6840Sstevel@tonic-gate static void 6850Sstevel@tonic-gate fmd_gc(fmd_t *dp, id_t id, hrtime_t hrt) 6860Sstevel@tonic-gate { 6870Sstevel@tonic-gate hrtime_t delta; 6880Sstevel@tonic-gate 6890Sstevel@tonic-gate if (id != 0) { 6900Sstevel@tonic-gate TRACE((FMD_DBG_MOD, "garbage collect start")); 6910Sstevel@tonic-gate fmd_modhash_apply(dp->d_mod_hash, fmd_module_gc); 6920Sstevel@tonic-gate TRACE((FMD_DBG_MOD, "garbage collect end")); 6930Sstevel@tonic-gate 6940Sstevel@tonic-gate (void) pthread_rwlock_rdlock(&dp->d_log_lock); 6950Sstevel@tonic-gate fmd_log_update(dp->d_errlog); 6960Sstevel@tonic-gate (void) pthread_rwlock_unlock(&dp->d_log_lock); 6970Sstevel@tonic-gate } 6980Sstevel@tonic-gate 6990Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "gc_interval", &delta); 7000Sstevel@tonic-gate (void) fmd_timerq_install(dp->d_timers, dp->d_rmod->mod_timerids, 7010Sstevel@tonic-gate (fmd_timer_f *)fmd_gc, dp, NULL, delta); 7020Sstevel@tonic-gate } 7030Sstevel@tonic-gate 7046228Sstephh /*ARGSUSED*/ 7056228Sstephh static void 7066228Sstephh fmd_clear_aged_rsrcs(fmd_t *dp, id_t id, hrtime_t hrt) 7076228Sstephh { 7086228Sstephh hrtime_t delta; 7096228Sstephh 7106228Sstephh fmd_asru_clear_aged_rsrcs(); 7116228Sstephh (void) fmd_conf_getprop(dp->d_conf, "rsrc.age", &delta); 7126228Sstephh (void) fmd_timerq_install(dp->d_timers, dp->d_rmod->mod_timerids, 7136228Sstephh (fmd_timer_f *)fmd_clear_aged_rsrcs, dp, NULL, delta/10); 7146228Sstephh } 7156228Sstephh 7160Sstevel@tonic-gate /* 7170Sstevel@tonic-gate * Events are committed to the errlog after cases are checkpointed. If fmd 7180Sstevel@tonic-gate * crashes before an event is ever associated with a module, this function will 7190Sstevel@tonic-gate * be called to replay it to all subscribers. If fmd crashes in between the 7200Sstevel@tonic-gate * subscriber checkpointing and committing the event in the error log, the 7210Sstevel@tonic-gate * module will have seen the event and we don't want to replay it. So we look 7220Sstevel@tonic-gate * for the event in all modules and transition it to the proper state. If 7230Sstevel@tonic-gate * it is found, we commit it to the error log and do not replay it. The in- 7240Sstevel@tonic-gate * memory case search used by fmd_module_contains() et al isn't particularly 7250Sstevel@tonic-gate * efficient, but it is faster than doing read i/o's on every case event to 7260Sstevel@tonic-gate * check their status or write i/o's on every event to replay to update states. 7270Sstevel@tonic-gate * We can improve the efficiency of this lookup algorithm later if necessary. 7280Sstevel@tonic-gate */ 7290Sstevel@tonic-gate /*ARGSUSED*/ 7300Sstevel@tonic-gate static void 7310Sstevel@tonic-gate fmd_err_replay(fmd_log_t *lp, fmd_event_t *ep, fmd_t *dp) 7320Sstevel@tonic-gate { 7330Sstevel@tonic-gate fmd_module_t *mp; 7340Sstevel@tonic-gate fmd_stat_t *sp; 7350Sstevel@tonic-gate 7360Sstevel@tonic-gate (void) pthread_mutex_lock(&dp->d_mod_lock); 7370Sstevel@tonic-gate 7380Sstevel@tonic-gate for (mp = fmd_list_next(&dp->d_mod_list); 7390Sstevel@tonic-gate mp != NULL; mp = fmd_list_next(mp)) { 7400Sstevel@tonic-gate if (fmd_module_contains(mp, ep)) { 7410Sstevel@tonic-gate fmd_module_hold(mp); 7420Sstevel@tonic-gate break; 7430Sstevel@tonic-gate } 7440Sstevel@tonic-gate } 7450Sstevel@tonic-gate 7460Sstevel@tonic-gate (void) pthread_mutex_unlock(&dp->d_mod_lock); 7470Sstevel@tonic-gate 7480Sstevel@tonic-gate if (mp != NULL) { 7490Sstevel@tonic-gate fmd_event_commit(ep); 7500Sstevel@tonic-gate fmd_module_rele(mp); 7510Sstevel@tonic-gate sp = &dp->d_stats->ds_log_partials; 7520Sstevel@tonic-gate } else { 7531193Smws fmd_dispq_dispatch(dp->d_disp, ep, FMD_EVENT_DATA(ep)); 7540Sstevel@tonic-gate sp = &dp->d_stats->ds_log_replayed; 7550Sstevel@tonic-gate } 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate (void) pthread_mutex_lock(&dp->d_stats_lock); 7580Sstevel@tonic-gate sp->fmds_value.ui64++; 7590Sstevel@tonic-gate (void) pthread_mutex_unlock(&dp->d_stats_lock); 7600Sstevel@tonic-gate } 7610Sstevel@tonic-gate 7621193Smws void 7631193Smws fmd_door_server(void *dip) 7641193Smws { 7651193Smws fmd_dprintf(FMD_DBG_XPRT, "door server starting for %p\n", dip); 7661193Smws (void) pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); 7671193Smws (void) door_return(NULL, 0, NULL, 0); 7681193Smws } 7691193Smws 7701193Smws /* 7711193Smws * Custom door server create callback. Any fmd services that use doors will 7721193Smws * require those threads to have their fmd-specific TSD initialized, etc. 7731193Smws */ 7741193Smws static void 7751193Smws fmd_door(door_info_t *dip) 7761193Smws { 7771193Smws if (fmd_thread_create(fmd.d_rmod, fmd_door_server, dip) == NULL) 7781193Smws fmd_panic("failed to create server for door %p", (void *)dip); 7791193Smws } 7801193Smws 7810Sstevel@tonic-gate /* 7820Sstevel@tonic-gate * This signal handler is installed for the client.thrsig signal to be used to 7830Sstevel@tonic-gate * force an auxiliary thread to wake up from a system call and return EINTR in 7840Sstevel@tonic-gate * response to a module's use of fmd_thr_signal(). We also trace the event. 7850Sstevel@tonic-gate */ 7860Sstevel@tonic-gate static void 7870Sstevel@tonic-gate fmd_signal(int sig) 7880Sstevel@tonic-gate { 7890Sstevel@tonic-gate TRACE((FMD_DBG_MOD, "module thread received sig #%d", sig)); 7900Sstevel@tonic-gate } 7910Sstevel@tonic-gate 7920Sstevel@tonic-gate void 7930Sstevel@tonic-gate fmd_run(fmd_t *dp, int pfd) 7940Sstevel@tonic-gate { 7950Sstevel@tonic-gate char *nodc_key[] = { FMD_FLT_NODC, NULL }; 7966276Scy152378 char *repair_key[] = { FM_LIST_REPAIRED_CLASS, NULL }; 7977275Sstephh char *resolve_key[] = { FM_LIST_RESOLVED_CLASS, NULL }; 7987275Sstephh char *update_key[] = { FM_LIST_UPDATED_CLASS, NULL }; 7996276Scy152378 char code_str[128]; 8000Sstevel@tonic-gate struct sigaction act; 8010Sstevel@tonic-gate 8020Sstevel@tonic-gate int status = FMD_EXIT_SUCCESS; 8030Sstevel@tonic-gate const char *name; 8040Sstevel@tonic-gate fmd_conf_path_t *pap; 8051193Smws fmd_event_t *e; 8063062Scindi int dbout; 8070Sstevel@tonic-gate 8080Sstevel@tonic-gate /* 8090Sstevel@tonic-gate * Cache all the current debug property settings in d_fmd_debug, 8100Sstevel@tonic-gate * d_fmd_dbout, d_hdl_debug, and d_hdl_dbout. If a given debug mask 8110Sstevel@tonic-gate * is non-zero and the corresponding dbout mask is zero, set dbout 8120Sstevel@tonic-gate * to a sensible default value based on whether we have daemonized. 8130Sstevel@tonic-gate */ 8140Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "dbout", &dbout); 8150Sstevel@tonic-gate 8160Sstevel@tonic-gate if (dp->d_fmd_debug != 0 && dbout == 0) 8170Sstevel@tonic-gate dp->d_fmd_dbout = dp->d_fg? FMD_DBOUT_STDERR : FMD_DBOUT_SYSLOG; 8180Sstevel@tonic-gate else 8190Sstevel@tonic-gate dp->d_fmd_dbout = dbout; 8200Sstevel@tonic-gate 8210Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "client.debug", &dp->d_hdl_debug); 8220Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "client.dbout", &dbout); 8230Sstevel@tonic-gate 8240Sstevel@tonic-gate if (dp->d_hdl_debug != 0 && dbout == 0) 8250Sstevel@tonic-gate dp->d_hdl_dbout = dp->d_fg? FMD_DBOUT_STDERR : FMD_DBOUT_SYSLOG; 8260Sstevel@tonic-gate else 8270Sstevel@tonic-gate dp->d_hdl_dbout = dbout; 8280Sstevel@tonic-gate 8290Sstevel@tonic-gate /* 8301193Smws * Initialize remaining major program data structures such as the 8311193Smws * clock, dispatch queues, log files, module hash collections, etc. 8320Sstevel@tonic-gate * This work is done here rather than in fmd_create() to permit the -o 8330Sstevel@tonic-gate * command-line option to modify properties after fmd_create() is done. 8340Sstevel@tonic-gate */ 8351414Scindi name = dp->d_rootdir != NULL && 8361414Scindi *dp->d_rootdir != '\0' ? dp->d_rootdir : NULL; 8371414Scindi 8384282Seschrock /* 8394282Seschrock * The clock must be initialized before fmd_topo_init() because 8404282Seschrock * fmd_topo_update() calls fmd_time_gethrtime(). 8414282Seschrock */ 8424282Seschrock dp->d_clockptr = dp->d_clockops->fto_init(); 8434282Seschrock 8443062Scindi fmd_topo_init(); 8451414Scindi 8461193Smws dp->d_xprt_ids = fmd_idspace_create("xprt_ids", 1, INT_MAX); 8471193Smws fmd_xprt_suspend_all(); 8481193Smws 8491193Smws (void) door_server_create(fmd_door); 8500Sstevel@tonic-gate 8510Sstevel@tonic-gate dp->d_rmod->mod_timerids = fmd_idspace_create(dp->d_pname, 1, 16); 8520Sstevel@tonic-gate dp->d_timers = fmd_timerq_create(); 8530Sstevel@tonic-gate dp->d_disp = fmd_dispq_create(); 8540Sstevel@tonic-gate dp->d_cases = fmd_case_hash_create(); 8550Sstevel@tonic-gate 8560Sstevel@tonic-gate /* 8571193Smws * The root module's mod_queue is created with limit zero, making it 8581193Smws * act like /dev/null; anything inserted here is simply ignored. 8591193Smws */ 8601193Smws dp->d_rmod->mod_queue = fmd_eventq_create(dp->d_rmod, 8611193Smws &dp->d_rmod->mod_stats->ms_evqstat, &dp->d_rmod->mod_stats_lock, 0); 8621193Smws 8631193Smws /* 8640Sstevel@tonic-gate * Once our subsystems that use signals have been set up, install the 8650Sstevel@tonic-gate * signal handler for the fmd_thr_signal() API. Verify that the signal 8660Sstevel@tonic-gate * being used for this purpose doesn't conflict with something else. 8670Sstevel@tonic-gate */ 8680Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "client.thrsig", &dp->d_thr_sig); 8690Sstevel@tonic-gate 8700Sstevel@tonic-gate if (sigaction(dp->d_thr_sig, NULL, &act) != 0) { 8710Sstevel@tonic-gate fmd_error(EFMD_EXIT, "invalid signal selected for " 8720Sstevel@tonic-gate "client.thrsig property: %d\n", dp->d_thr_sig); 8730Sstevel@tonic-gate } 8740Sstevel@tonic-gate 8750Sstevel@tonic-gate if (act.sa_handler != SIG_IGN && act.sa_handler != SIG_DFL) { 8760Sstevel@tonic-gate fmd_error(EFMD_EXIT, "signal selected for client.thrsig " 8770Sstevel@tonic-gate "property is already in use: %d\n", dp->d_thr_sig); 8780Sstevel@tonic-gate } 8790Sstevel@tonic-gate 8800Sstevel@tonic-gate act.sa_handler = fmd_signal; 8810Sstevel@tonic-gate act.sa_flags = 0; 8820Sstevel@tonic-gate 8830Sstevel@tonic-gate (void) sigemptyset(&act.sa_mask); 8840Sstevel@tonic-gate (void) sigaction(dp->d_thr_sig, &act, NULL); 8850Sstevel@tonic-gate 8860Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "schemedir", &name); 8870Sstevel@tonic-gate dp->d_schemes = fmd_scheme_hash_create(dp->d_rootdir, name); 8880Sstevel@tonic-gate 8890Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "log.rsrc", &name); 8900Sstevel@tonic-gate dp->d_asrus = fmd_asru_hash_create(dp->d_rootdir, name); 8910Sstevel@tonic-gate 8920Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "log.error", &name); 8930Sstevel@tonic-gate dp->d_errlog = fmd_log_open(dp->d_rootdir, name, FMD_LOG_ERROR); 8940Sstevel@tonic-gate 8950Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "log.fault", &name); 8960Sstevel@tonic-gate dp->d_fltlog = fmd_log_open(dp->d_rootdir, name, FMD_LOG_FAULT); 8970Sstevel@tonic-gate 8980Sstevel@tonic-gate if (dp->d_asrus == NULL || dp->d_errlog == NULL || dp->d_fltlog == NULL) 8990Sstevel@tonic-gate fmd_error(EFMD_EXIT, "failed to initialize log files\n"); 9000Sstevel@tonic-gate 9011193Smws /* 9021193Smws * Before loading modules, create an empty control event which will act 9031193Smws * as a global barrier for module event processing. Each module we 9041193Smws * load successfully will insert it at their head of their event queue, 9051193Smws * and then pause inside of fmd_ctl_rele() after dequeuing the event. 9061193Smws * This module barrier is required for two reasons: 9071193Smws * 9081193Smws * (a) During module loading, the restoration of case checkpoints may 9091193Smws * result in a list.* event being recreated for which the intended 9101193Smws * subscriber has not yet loaded depending on the load order. Such 9111193Smws * events could then result in spurious "no subscriber" errors. 9121193Smws * 9131193Smws * (b) During errlog replay, a sequence of errors from a long time ago 9141193Smws * may be replayed, and the module may attempt to install relative 9151193Smws * timers associated with one or more of these events. If errlog 9161193Smws * replay were "racing" with active module threads, an event E1 9171193Smws * that resulted in a relative timer T at time E1 + N nsec could 9181193Smws * fire prior to an event E2 being enqueued, even if the relative 9191193Smws * time ordering was E1 < E2 < E1 + N, causing mis-diagnosis. 9201193Smws */ 9211193Smws dp->d_mod_event = e = fmd_event_create(FMD_EVT_CTL, 9221193Smws FMD_HRT_NOW, NULL, fmd_ctl_init(NULL)); 9231193Smws 9241193Smws fmd_event_hold(e); 9251193Smws 9261193Smws /* 9271193Smws * Once all data structures are initialized, we load all of our modules 9281193Smws * in order according to class in order to load up any subscriptions. 9291193Smws * Once built-in modules are loaded, we detach from our waiting parent. 9301193Smws */ 9310Sstevel@tonic-gate dp->d_mod_hash = fmd_modhash_create(); 9321193Smws 9331193Smws if (fmd_builtin_loadall(dp->d_mod_hash) != 0 && !dp->d_fg) 9341193Smws fmd_error(EFMD_EXIT, "failed to initialize fault manager\n"); 9351193Smws 9361193Smws (void) fmd_conf_getprop(dp->d_conf, "self.name", &name); 9371193Smws dp->d_self = fmd_modhash_lookup(dp->d_mod_hash, name); 9381193Smws 9396276Scy152378 if (dp->d_self != NULL) { 9406276Scy152378 if (fmd_module_dc_key2code(dp->d_self, nodc_key, code_str, 9416276Scy152378 sizeof (code_str)) == 0) 9426276Scy152378 (void) fmd_conf_setprop(dp->d_conf, "nodiagcode", 9436276Scy152378 code_str); 9446276Scy152378 if (fmd_module_dc_key2code(dp->d_self, repair_key, code_str, 9456276Scy152378 sizeof (code_str)) == 0) 9466276Scy152378 (void) fmd_conf_setprop(dp->d_conf, "repaircode", 9476276Scy152378 code_str); 9487275Sstephh if (fmd_module_dc_key2code(dp->d_self, resolve_key, code_str, 9497275Sstephh sizeof (code_str)) == 0) 9507275Sstephh (void) fmd_conf_setprop(dp->d_conf, "resolvecode", 9517275Sstephh code_str); 9527275Sstephh if (fmd_module_dc_key2code(dp->d_self, update_key, code_str, 9537275Sstephh sizeof (code_str)) == 0) 9547275Sstephh (void) fmd_conf_setprop(dp->d_conf, "updatecode", 9557275Sstephh code_str); 9566276Scy152378 } 9571193Smws 9581193Smws fmd_rpc_init(); 9590Sstevel@tonic-gate dp->d_running = 1; /* we are now officially an active fmd */ 9600Sstevel@tonic-gate 9610Sstevel@tonic-gate /* 9620Sstevel@tonic-gate * Now that we're running, if a pipe fd was specified, write an exit 9630Sstevel@tonic-gate * status to it to indicate that our parent process can safely detach. 9641193Smws * Then proceed to loading the remaining non-built-in modules. 9650Sstevel@tonic-gate */ 9660Sstevel@tonic-gate if (pfd >= 0) 9670Sstevel@tonic-gate (void) write(pfd, &status, sizeof (status)); 9680Sstevel@tonic-gate 9691552Smws /* 9701552Smws * Before loading all modules, repopulate the ASRU cache from its 9711552Smws * persistent repository on disk. Then during module loading, the 9721552Smws * restoration of checkpoint files will reparent any active cases. 9731552Smws */ 9741552Smws fmd_asru_hash_refresh(dp->d_asrus); 9751552Smws 9760Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "plugin.path", &pap); 9771429Smws fmd_modhash_loadall(dp->d_mod_hash, pap, &fmd_rtld_ops, ".so"); 9780Sstevel@tonic-gate 9790Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "agent.path", &pap); 9801429Smws fmd_modhash_loadall(dp->d_mod_hash, pap, &fmd_proc_ops, NULL); 9810Sstevel@tonic-gate 9820Sstevel@tonic-gate /* 9831193Smws * With all modules loaded, replay fault events from the ASRU cache for 9841193Smws * any ASRUs that must be retired, replay error events from the errlog 9851193Smws * that did not finish processing the last time ran, and then release 9861193Smws * the global module barrier by executing a final rele on d_mod_event. 9870Sstevel@tonic-gate */ 9881552Smws fmd_asru_hash_replay(dp->d_asrus); 9890Sstevel@tonic-gate 9900Sstevel@tonic-gate (void) pthread_rwlock_rdlock(&dp->d_log_lock); 9910Sstevel@tonic-gate fmd_log_replay(dp->d_errlog, (fmd_log_f *)fmd_err_replay, dp); 9920Sstevel@tonic-gate fmd_log_update(dp->d_errlog); 9930Sstevel@tonic-gate (void) pthread_rwlock_unlock(&dp->d_log_lock); 9940Sstevel@tonic-gate 9951193Smws dp->d_mod_event = NULL; 9961193Smws fmd_event_rele(e); 9970Sstevel@tonic-gate 9980Sstevel@tonic-gate /* 9997275Sstephh * Now replay list.updated and list.repaired events 10007275Sstephh */ 10017275Sstephh fmd_case_repair_replay(); 10027275Sstephh 10037275Sstephh /* 10040Sstevel@tonic-gate * Finally, awaken any threads associated with receiving events from 10051193Smws * open transports and tell them to proceed with fmd_xprt_recv(). 10060Sstevel@tonic-gate */ 10071193Smws fmd_xprt_resume_all(); 10081193Smws fmd_gc(dp, 0, 0); 10096228Sstephh fmd_clear_aged_rsrcs(dp, 0, 0); 10100Sstevel@tonic-gate 10116559Sstephh (void) pthread_mutex_lock(&dp->d_fmd_lock); 10121193Smws dp->d_booted = 1; 10136559Sstephh (void) pthread_cond_broadcast(&dp->d_fmd_cv); 10146559Sstephh (void) pthread_mutex_unlock(&dp->d_fmd_lock); 10150Sstevel@tonic-gate } 10160Sstevel@tonic-gate 10170Sstevel@tonic-gate void 10180Sstevel@tonic-gate fmd_help(fmd_t *dp) 10190Sstevel@tonic-gate { 10200Sstevel@tonic-gate const fmd_conf_mode_t *cmp; 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate (void) printf("Usage: %s -o debug=mode[,mode]\n", dp->d_pname); 10230Sstevel@tonic-gate 10240Sstevel@tonic-gate for (cmp = _fmd_debug_modes; cmp->cm_name != NULL; cmp++) 10250Sstevel@tonic-gate (void) printf("\t%s\t%s\n", cmp->cm_name, cmp->cm_desc); 10260Sstevel@tonic-gate } 1027