1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 30*7c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 31*7c478bd9Sstevel@tonic-gate #include <sys/param.h> 32*7c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h> 33*7c478bd9Sstevel@tonic-gate #include <sys/fm/util.h> 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #include <limits.h> 36*7c478bd9Sstevel@tonic-gate #include <unistd.h> 37*7c478bd9Sstevel@tonic-gate #include <signal.h> 38*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 39*7c478bd9Sstevel@tonic-gate #include <stdio.h> 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate #include <fmd_conf.h> 42*7c478bd9Sstevel@tonic-gate #include <fmd_dispq.h> 43*7c478bd9Sstevel@tonic-gate #include <fmd_timerq.h> 44*7c478bd9Sstevel@tonic-gate #include <fmd_subr.h> 45*7c478bd9Sstevel@tonic-gate #include <fmd_error.h> 46*7c478bd9Sstevel@tonic-gate #include <fmd_module.h> 47*7c478bd9Sstevel@tonic-gate #include <fmd_thread.h> 48*7c478bd9Sstevel@tonic-gate #include <fmd_alloc.h> 49*7c478bd9Sstevel@tonic-gate #include <fmd_string.h> 50*7c478bd9Sstevel@tonic-gate #include <fmd_transport.h> 51*7c478bd9Sstevel@tonic-gate #include <fmd_builtin.h> 52*7c478bd9Sstevel@tonic-gate #include <fmd_ustat.h> 53*7c478bd9Sstevel@tonic-gate #include <fmd_protocol.h> 54*7c478bd9Sstevel@tonic-gate #include <fmd_scheme.h> 55*7c478bd9Sstevel@tonic-gate #include <fmd_asru.h> 56*7c478bd9Sstevel@tonic-gate #include <fmd_case.h> 57*7c478bd9Sstevel@tonic-gate #include <fmd_log.h> 58*7c478bd9Sstevel@tonic-gate #include <fmd_rpc.h> 59*7c478bd9Sstevel@tonic-gate #include <fmd_dr.h> 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate #include <fmd.h> 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate extern const nv_alloc_ops_t fmd_nv_alloc_ops; /* see fmd_nv.c */ 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate const char _fmd_version[] = "1.0"; /* daemon version string */ 66*7c478bd9Sstevel@tonic-gate static char _fmd_plat[MAXNAMELEN]; /* native platform string */ 67*7c478bd9Sstevel@tonic-gate static char _fmd_isa[MAXNAMELEN]; /* native instruction set */ 68*7c478bd9Sstevel@tonic-gate static struct utsname _fmd_uts; /* native uname(2) info */ 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate /* 71*7c478bd9Sstevel@tonic-gate * Note: the configuration file path is ordered from most common to most host- 72*7c478bd9Sstevel@tonic-gate * specific because new conf files are merged/override previous ones. The 73*7c478bd9Sstevel@tonic-gate * module paths are in the opposite order, from most specific to most common, 74*7c478bd9Sstevel@tonic-gate * because once a module is loaded fmd will not try to load over the same name. 75*7c478bd9Sstevel@tonic-gate */ 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate static const char _fmd_conf_path[] = 78*7c478bd9Sstevel@tonic-gate "%r/usr/lib/fm/fmd:" 79*7c478bd9Sstevel@tonic-gate "%r/usr/platform/%m/lib/fm/fmd:" 80*7c478bd9Sstevel@tonic-gate "%r/usr/platform/%i/lib/fm/fmd:" 81*7c478bd9Sstevel@tonic-gate "%r/etc/fm/fmd"; 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate static const char _fmd_agent_path[] = 84*7c478bd9Sstevel@tonic-gate "%r/usr/platform/%i/lib/fm/fmd/agents:" 85*7c478bd9Sstevel@tonic-gate "%r/usr/platform/%m/lib/fm/fmd/agents:" 86*7c478bd9Sstevel@tonic-gate "%r/usr/lib/fm/fmd/agents"; 87*7c478bd9Sstevel@tonic-gate 88*7c478bd9Sstevel@tonic-gate static const char _fmd_plugin_path[] = 89*7c478bd9Sstevel@tonic-gate "%r/usr/platform/%i/lib/fm/fmd/plugins:" 90*7c478bd9Sstevel@tonic-gate "%r/usr/platform/%m/lib/fm/fmd/plugins:" 91*7c478bd9Sstevel@tonic-gate "%r/usr/lib/fm/fmd/plugins"; 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate static const char _fmd_scheme_path[] = 94*7c478bd9Sstevel@tonic-gate "usr/lib/fm/fmd/schemes"; 95*7c478bd9Sstevel@tonic-gate 96*7c478bd9Sstevel@tonic-gate static const fmd_conf_mode_t _fmd_cerror_modes[] = { 97*7c478bd9Sstevel@tonic-gate { "unload", "unload offending client module", FMD_CERROR_UNLOAD }, 98*7c478bd9Sstevel@tonic-gate { "stop", "stop daemon for debugger attach", FMD_CERROR_STOP }, 99*7c478bd9Sstevel@tonic-gate { "abort", "abort daemon and force core dump", FMD_CERROR_ABORT }, 100*7c478bd9Sstevel@tonic-gate { NULL, NULL, 0 } 101*7c478bd9Sstevel@tonic-gate }; 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate static const fmd_conf_mode_t _fmd_dbout_modes[] = { 104*7c478bd9Sstevel@tonic-gate { "stderr", "send debug messages to stderr", FMD_DBOUT_STDERR }, 105*7c478bd9Sstevel@tonic-gate { "syslog", "send debug messages to syslog", FMD_DBOUT_SYSLOG }, 106*7c478bd9Sstevel@tonic-gate { NULL, NULL, 0 } 107*7c478bd9Sstevel@tonic-gate }; 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate static const fmd_conf_mode_t _fmd_debug_modes[] = { 110*7c478bd9Sstevel@tonic-gate { "help", "display debugging modes and exit", FMD_DBG_HELP }, 111*7c478bd9Sstevel@tonic-gate { "mod", "debug module load/unload/locking", FMD_DBG_MOD }, 112*7c478bd9Sstevel@tonic-gate { "disp", "debug dispatch queue processing", FMD_DBG_DISP }, 113*7c478bd9Sstevel@tonic-gate { "xprt", "debug transport-specific routines", FMD_DBG_XPRT }, 114*7c478bd9Sstevel@tonic-gate { "evt", "debug event subsystem routines", FMD_DBG_EVT }, 115*7c478bd9Sstevel@tonic-gate { "log", "debug log subsystem routines", FMD_DBG_LOG }, 116*7c478bd9Sstevel@tonic-gate { "tmr", "debug timer subsystem routines", FMD_DBG_TMR }, 117*7c478bd9Sstevel@tonic-gate { "fmri", "debug fmri subsystem routines", FMD_DBG_FMRI }, 118*7c478bd9Sstevel@tonic-gate { "asru", "debug asru subsystem routines", FMD_DBG_ASRU }, 119*7c478bd9Sstevel@tonic-gate { "case", "debug case subsystem routines", FMD_DBG_CASE }, 120*7c478bd9Sstevel@tonic-gate { "ckpt", "debug checkpoint routines", FMD_DBG_CKPT }, 121*7c478bd9Sstevel@tonic-gate { "rpc", "debug rpc service routines", FMD_DBG_RPC }, 122*7c478bd9Sstevel@tonic-gate { "all", "enable all available debug modes", FMD_DBG_ALL }, 123*7c478bd9Sstevel@tonic-gate { NULL, NULL, 0 } 124*7c478bd9Sstevel@tonic-gate }; 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate static int 127*7c478bd9Sstevel@tonic-gate fmd_cerror_set(fmd_conf_param_t *pp, const char *value) 128*7c478bd9Sstevel@tonic-gate { 129*7c478bd9Sstevel@tonic-gate return (fmd_conf_mode_set(_fmd_cerror_modes, pp, value)); 130*7c478bd9Sstevel@tonic-gate } 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate static int 133*7c478bd9Sstevel@tonic-gate fmd_dbout_set(fmd_conf_param_t *pp, const char *value) 134*7c478bd9Sstevel@tonic-gate { 135*7c478bd9Sstevel@tonic-gate return (fmd_conf_mode_set(_fmd_dbout_modes, pp, value)); 136*7c478bd9Sstevel@tonic-gate } 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate static int 139*7c478bd9Sstevel@tonic-gate fmd_debug_set(fmd_conf_param_t *pp, const char *value) 140*7c478bd9Sstevel@tonic-gate { 141*7c478bd9Sstevel@tonic-gate int err = fmd_conf_mode_set(_fmd_debug_modes, pp, value); 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate if (err == 0) 144*7c478bd9Sstevel@tonic-gate fmd.d_fmd_debug = pp->cp_value.cpv_num; 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate return (err); 147*7c478bd9Sstevel@tonic-gate } 148*7c478bd9Sstevel@tonic-gate 149*7c478bd9Sstevel@tonic-gate static int 150*7c478bd9Sstevel@tonic-gate fmd_trmode_set(fmd_conf_param_t *pp, const char *value) 151*7c478bd9Sstevel@tonic-gate { 152*7c478bd9Sstevel@tonic-gate fmd_tracebuf_f *func; 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate if (strcasecmp(value, "none") == 0) 155*7c478bd9Sstevel@tonic-gate func = fmd_trace_none; 156*7c478bd9Sstevel@tonic-gate else if (strcasecmp(value, "lite") == 0) 157*7c478bd9Sstevel@tonic-gate func = fmd_trace_lite; 158*7c478bd9Sstevel@tonic-gate else if (strcasecmp(value, "full") == 0) 159*7c478bd9Sstevel@tonic-gate func = fmd_trace_full; 160*7c478bd9Sstevel@tonic-gate else 161*7c478bd9Sstevel@tonic-gate return (fmd_set_errno(EFMD_CONF_INVAL)); 162*7c478bd9Sstevel@tonic-gate 163*7c478bd9Sstevel@tonic-gate fmd.d_thr_trace = (void (*)())func; 164*7c478bd9Sstevel@tonic-gate pp->cp_value.cpv_ptr = (void *)func; 165*7c478bd9Sstevel@tonic-gate return (0); 166*7c478bd9Sstevel@tonic-gate } 167*7c478bd9Sstevel@tonic-gate 168*7c478bd9Sstevel@tonic-gate static void 169*7c478bd9Sstevel@tonic-gate fmd_trmode_get(const fmd_conf_param_t *pp, void *ptr) 170*7c478bd9Sstevel@tonic-gate { 171*7c478bd9Sstevel@tonic-gate *((void **)ptr) = pp->cp_value.cpv_ptr; 172*7c478bd9Sstevel@tonic-gate } 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate static int 175*7c478bd9Sstevel@tonic-gate fmd_clkmode_set(fmd_conf_param_t *pp, const char *value) 176*7c478bd9Sstevel@tonic-gate { 177*7c478bd9Sstevel@tonic-gate const fmd_timeops_t *ops; 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate if (strcasecmp(value, "native") == 0) 180*7c478bd9Sstevel@tonic-gate ops = &fmd_timeops_native; 181*7c478bd9Sstevel@tonic-gate else if (strcasecmp(value, "simulated") == 0) 182*7c478bd9Sstevel@tonic-gate ops = &fmd_timeops_simulated; 183*7c478bd9Sstevel@tonic-gate else 184*7c478bd9Sstevel@tonic-gate return (fmd_set_errno(EFMD_CONF_INVAL)); 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate fmd.d_clockops = ops; 187*7c478bd9Sstevel@tonic-gate pp->cp_value.cpv_ptr = (void *)ops; 188*7c478bd9Sstevel@tonic-gate return (0); 189*7c478bd9Sstevel@tonic-gate } 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate static void 192*7c478bd9Sstevel@tonic-gate fmd_clkmode_get(const fmd_conf_param_t *pp, void *ptr) 193*7c478bd9Sstevel@tonic-gate { 194*7c478bd9Sstevel@tonic-gate *((void **)ptr) = pp->cp_value.cpv_ptr; 195*7c478bd9Sstevel@tonic-gate } 196*7c478bd9Sstevel@tonic-gate 197*7c478bd9Sstevel@tonic-gate static const fmd_conf_ops_t fmd_cerror_ops = { 198*7c478bd9Sstevel@tonic-gate fmd_cerror_set, fmd_conf_mode_get, fmd_conf_notsup, fmd_conf_nop 199*7c478bd9Sstevel@tonic-gate }; 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate static const fmd_conf_ops_t fmd_dbout_ops = { 202*7c478bd9Sstevel@tonic-gate fmd_dbout_set, fmd_conf_mode_get, fmd_conf_notsup, fmd_conf_nop 203*7c478bd9Sstevel@tonic-gate }; 204*7c478bd9Sstevel@tonic-gate 205*7c478bd9Sstevel@tonic-gate static const fmd_conf_ops_t fmd_debug_ops = { 206*7c478bd9Sstevel@tonic-gate fmd_debug_set, fmd_conf_mode_get, fmd_conf_notsup, fmd_conf_nop 207*7c478bd9Sstevel@tonic-gate }; 208*7c478bd9Sstevel@tonic-gate 209*7c478bd9Sstevel@tonic-gate static const fmd_conf_ops_t fmd_trmode_ops = { 210*7c478bd9Sstevel@tonic-gate fmd_trmode_set, fmd_trmode_get, fmd_conf_notsup, fmd_conf_nop 211*7c478bd9Sstevel@tonic-gate }; 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gate static const fmd_conf_ops_t fmd_clkmode_ops = { 214*7c478bd9Sstevel@tonic-gate fmd_clkmode_set, fmd_clkmode_get, fmd_conf_notsup, fmd_conf_nop 215*7c478bd9Sstevel@tonic-gate }; 216*7c478bd9Sstevel@tonic-gate 217*7c478bd9Sstevel@tonic-gate static const fmd_conf_formal_t _fmd_conf[] = { 218*7c478bd9Sstevel@tonic-gate { "agent.path", &fmd_conf_path, _fmd_agent_path }, /* path for agents */ 219*7c478bd9Sstevel@tonic-gate { "alloc_msecs", &fmd_conf_uint32, "10" }, /* msecs before alloc retry */ 220*7c478bd9Sstevel@tonic-gate { "alloc_tries", &fmd_conf_uint32, "3" }, /* max # of alloc retries */ 221*7c478bd9Sstevel@tonic-gate { "chassis", &fmd_conf_string, NULL }, /* chassis serial number */ 222*7c478bd9Sstevel@tonic-gate { "ckpt.dir", &fmd_conf_string, "var/fm/fmd/ckpt" }, /* ckpt directory path */ 223*7c478bd9Sstevel@tonic-gate { "ckpt.dirmode", &fmd_conf_int32, "0700" }, /* ckpt directory perm mode */ 224*7c478bd9Sstevel@tonic-gate { "ckpt.mode", &fmd_conf_int32, "0400" }, /* ckpt file perm mode */ 225*7c478bd9Sstevel@tonic-gate { "ckpt.restore", &fmd_conf_bool, "true" }, /* restore checkpoints? */ 226*7c478bd9Sstevel@tonic-gate { "ckpt.save", &fmd_conf_bool, "true" }, /* save checkpoints? */ 227*7c478bd9Sstevel@tonic-gate { "ckpt.zero", &fmd_conf_bool, "false" }, /* zero checkpoints on start? */ 228*7c478bd9Sstevel@tonic-gate { "client.buflim", &fmd_conf_size, "10m" }, /* client buffer space limit */ 229*7c478bd9Sstevel@tonic-gate { "client.dbout", &fmd_dbout_ops, NULL }, /* client debug output sinks */ 230*7c478bd9Sstevel@tonic-gate { "client.debug", &fmd_conf_bool, NULL }, /* client debug enable */ 231*7c478bd9Sstevel@tonic-gate { "client.error", &fmd_cerror_ops, "unload" }, /* client error policy */ 232*7c478bd9Sstevel@tonic-gate { "client.memlim", &fmd_conf_size, "10m" }, /* client allocation limit */ 233*7c478bd9Sstevel@tonic-gate { "client.evqlim", &fmd_conf_uint32, "256" }, /* client event queue limit */ 234*7c478bd9Sstevel@tonic-gate { "client.thrlim", &fmd_conf_uint32, "8" }, /* client aux thread limit */ 235*7c478bd9Sstevel@tonic-gate { "client.thrsig", &fmd_conf_signal, "SIGUSR1" }, /* fmd_thr_signal() value */ 236*7c478bd9Sstevel@tonic-gate { "client.tmrlim", &fmd_conf_uint32, "1024" }, /* client pending timer limit */ 237*7c478bd9Sstevel@tonic-gate { "clock", &fmd_clkmode_ops, "native" }, /* clock operation mode */ 238*7c478bd9Sstevel@tonic-gate { "conf_path", &fmd_conf_path, _fmd_conf_path }, /* root config file path */ 239*7c478bd9Sstevel@tonic-gate { "conf_file", &fmd_conf_string, "fmd.conf" }, /* root config file name */ 240*7c478bd9Sstevel@tonic-gate { "core", &fmd_conf_bool, "false" }, /* force core dump on quit */ 241*7c478bd9Sstevel@tonic-gate { "dbout", &fmd_dbout_ops, NULL }, /* daemon debug output sinks */ 242*7c478bd9Sstevel@tonic-gate { "debug", &fmd_debug_ops, NULL }, /* daemon debugging flags */ 243*7c478bd9Sstevel@tonic-gate { "dictdir", &fmd_conf_string, "usr/lib/fm/dict" }, /* default diagcode dir */ 244*7c478bd9Sstevel@tonic-gate { "domain", &fmd_conf_string, NULL }, /* domain id for de auth */ 245*7c478bd9Sstevel@tonic-gate { "errchan", &fmd_conf_string, FM_ERROR_CHAN }, /* error event channel name */ 246*7c478bd9Sstevel@tonic-gate { "fg", &fmd_conf_bool, "false" }, /* run daemon in foreground */ 247*7c478bd9Sstevel@tonic-gate { "gc_interval", &fmd_conf_time, "1d" }, /* garbage collection intvl */ 248*7c478bd9Sstevel@tonic-gate { "ids.avg", &fmd_conf_uint32, "4" }, /* desired idspace chain len */ 249*7c478bd9Sstevel@tonic-gate { "ids.max", &fmd_conf_uint32, "1024" }, /* maximum idspace buckets */ 250*7c478bd9Sstevel@tonic-gate { "isaname", &fmd_conf_string, _fmd_isa }, /* instruction set (uname -p) */ 251*7c478bd9Sstevel@tonic-gate { "log.rsrc", &fmd_conf_string, "var/fm/fmd/rsrc" }, /* asru log dir path */ 252*7c478bd9Sstevel@tonic-gate { "log.creator", &fmd_conf_string, "fmd" }, /* exacct log creator string */ 253*7c478bd9Sstevel@tonic-gate { "log.error", &fmd_conf_string, "var/fm/fmd/errlog" }, /* error log path */ 254*7c478bd9Sstevel@tonic-gate { "log.fault", &fmd_conf_string, "var/fm/fmd/fltlog" }, /* fault log path */ 255*7c478bd9Sstevel@tonic-gate { "log.minfree", &fmd_conf_size, "2m" }, /* min log fsys free space */ 256*7c478bd9Sstevel@tonic-gate { "log.tryrotate", &fmd_conf_uint32, "10" }, /* max log rotation attempts */ 257*7c478bd9Sstevel@tonic-gate { "log.waitrotate", &fmd_conf_time, "200ms" }, /* log rotation retry delay */ 258*7c478bd9Sstevel@tonic-gate { "machine", &fmd_conf_string, _fmd_uts.machine }, /* machine name (uname -m) */ 259*7c478bd9Sstevel@tonic-gate { "nodiagcode", &fmd_conf_string, "-" }, /* diagcode to use if error */ 260*7c478bd9Sstevel@tonic-gate { "osrelease", &fmd_conf_string, _fmd_uts.release }, /* release (uname -r) */ 261*7c478bd9Sstevel@tonic-gate { "osversion", &fmd_conf_string, _fmd_uts.version }, /* version (uname -v) */ 262*7c478bd9Sstevel@tonic-gate { "platform", &fmd_conf_string, _fmd_plat }, /* platform string (uname -i) */ 263*7c478bd9Sstevel@tonic-gate { "plugin.close", &fmd_conf_bool, "true" }, /* dlclose plugins on fini */ 264*7c478bd9Sstevel@tonic-gate { "plugin.path", &fmd_conf_path, _fmd_plugin_path }, /* path for plugin mods */ 265*7c478bd9Sstevel@tonic-gate { "rootdir", &fmd_conf_string, "" }, /* root directory for paths */ 266*7c478bd9Sstevel@tonic-gate { "rpc.adm.path", &fmd_conf_string, NULL }, /* FMD_ADM rendezvous file */ 267*7c478bd9Sstevel@tonic-gate { "rpc.adm.prog", &fmd_conf_uint32, "100169" }, /* FMD_ADM rpc program num */ 268*7c478bd9Sstevel@tonic-gate { "rpc.api.path", &fmd_conf_string, NULL }, /* FMD_API rendezvous file */ 269*7c478bd9Sstevel@tonic-gate { "rpc.api.prog", &fmd_conf_uint32, "100170" }, /* FMD_API rpc program num */ 270*7c478bd9Sstevel@tonic-gate { "rpc.rcvsize", &fmd_conf_size, "128k" }, /* rpc receive buffer size */ 271*7c478bd9Sstevel@tonic-gate { "rpc.sndsize", &fmd_conf_size, "128k" }, /* rpc send buffer size */ 272*7c478bd9Sstevel@tonic-gate { "rsrc.age", &fmd_conf_time, "30d" }, /* max age of old rsrc log */ 273*7c478bd9Sstevel@tonic-gate { "rsrc.zero", &fmd_conf_bool, "false" }, /* zero rsrc cache on start? */ 274*7c478bd9Sstevel@tonic-gate { "schemedir", &fmd_conf_string, _fmd_scheme_path }, /* path for scheme mods */ 275*7c478bd9Sstevel@tonic-gate { "self.name", &fmd_conf_string, "fmd-self-diagnosis" }, /* self-diag module */ 276*7c478bd9Sstevel@tonic-gate { "self.dict", &fmd_conf_list, "FMD.dict" }, /* self-diag dictionary list */ 277*7c478bd9Sstevel@tonic-gate { "server", &fmd_conf_string, _fmd_uts.nodename }, /* server id for de auth */ 278*7c478bd9Sstevel@tonic-gate { "strbuckets", &fmd_conf_uint32, "211" }, /* size of string hashes */ 279*7c478bd9Sstevel@tonic-gate #ifdef DEBUG 280*7c478bd9Sstevel@tonic-gate { "trace.mode", &fmd_trmode_ops, "full" }, /* trace mode: none/lite/full */ 281*7c478bd9Sstevel@tonic-gate #else 282*7c478bd9Sstevel@tonic-gate { "trace.mode", &fmd_trmode_ops, "lite" }, /* trace mode: none/lite/full */ 283*7c478bd9Sstevel@tonic-gate #endif 284*7c478bd9Sstevel@tonic-gate { "trace.recs", &fmd_conf_uint32, "128" }, /* trace records per thread */ 285*7c478bd9Sstevel@tonic-gate { "trace.frames", &fmd_conf_uint32, "16" }, /* max trace rec stack frames */ 286*7c478bd9Sstevel@tonic-gate { "uuidlen", &fmd_conf_uint32, "36" }, /* UUID ASCII string length */ 287*7c478bd9Sstevel@tonic-gate { "xprt.class", &fmd_conf_string, NULL }, /* transport event class */ 288*7c478bd9Sstevel@tonic-gate { "xprt.device", &fmd_conf_string, NULL }, /* transport replay device */ 289*7c478bd9Sstevel@tonic-gate { "xprt.sid", &fmd_conf_string, "fmd" }, /* transport subscriber id */ 290*7c478bd9Sstevel@tonic-gate }; 291*7c478bd9Sstevel@tonic-gate 292*7c478bd9Sstevel@tonic-gate /* 293*7c478bd9Sstevel@tonic-gate * Statistics maintained by fmd itself on behalf of various global subsystems. 294*7c478bd9Sstevel@tonic-gate * NOTE: FMD_TYPE_STRING statistics should not be used here. If they are 295*7c478bd9Sstevel@tonic-gate * required in the future, the FMD_ADM_MODGSTAT service routine must change. 296*7c478bd9Sstevel@tonic-gate */ 297*7c478bd9Sstevel@tonic-gate static fmd_statistics_t _fmd_stats = { 298*7c478bd9Sstevel@tonic-gate { "transport.received", FMD_TYPE_UINT64, "events received by transport" }, 299*7c478bd9Sstevel@tonic-gate { "transport.discarded", FMD_TYPE_UINT64, "bad events discarded by transport" }, 300*7c478bd9Sstevel@tonic-gate { "transport.retried", FMD_TYPE_UINT64, "retries requested of transport" }, 301*7c478bd9Sstevel@tonic-gate { "transport.replayed", FMD_TYPE_UINT64, "events replayed by transport" }, 302*7c478bd9Sstevel@tonic-gate { "transport.lost", FMD_TYPE_UINT64, "events lost by transport" }, 303*7c478bd9Sstevel@tonic-gate { "errlog.replayed", FMD_TYPE_UINT64, "total events replayed from errlog" }, 304*7c478bd9Sstevel@tonic-gate { "errlog.partials", FMD_TYPE_UINT64, "events partially committed in errlog" }, 305*7c478bd9Sstevel@tonic-gate { "errlog.enospc", FMD_TYPE_UINT64, "events not appended to errlog (ENOSPC)" }, 306*7c478bd9Sstevel@tonic-gate { "fltlog.enospc", FMD_TYPE_UINT64, "events not appended to fltlog (ENOSPC)" }, 307*7c478bd9Sstevel@tonic-gate { "log.enospc", FMD_TYPE_UINT64, "events not appended to other logs (ENOSPC)" }, 308*7c478bd9Sstevel@tonic-gate { "dr.gen", FMD_TYPE_UINT64, "dynamic reconfiguration generation" }, 309*7c478bd9Sstevel@tonic-gate }; 310*7c478bd9Sstevel@tonic-gate 311*7c478bd9Sstevel@tonic-gate void 312*7c478bd9Sstevel@tonic-gate fmd_create(fmd_t *dp, const char *arg0, const char *root, const char *conf) 313*7c478bd9Sstevel@tonic-gate { 314*7c478bd9Sstevel@tonic-gate fmd_conf_path_t *pap; 315*7c478bd9Sstevel@tonic-gate char file[PATH_MAX]; 316*7c478bd9Sstevel@tonic-gate const char *name; 317*7c478bd9Sstevel@tonic-gate fmd_stat_t *sp; 318*7c478bd9Sstevel@tonic-gate int i; 319*7c478bd9Sstevel@tonic-gate 320*7c478bd9Sstevel@tonic-gate (void) sysinfo(SI_PLATFORM, _fmd_plat, sizeof (_fmd_plat)); 321*7c478bd9Sstevel@tonic-gate (void) sysinfo(SI_ARCHITECTURE, _fmd_isa, sizeof (_fmd_isa)); 322*7c478bd9Sstevel@tonic-gate (void) uname(&_fmd_uts); 323*7c478bd9Sstevel@tonic-gate 324*7c478bd9Sstevel@tonic-gate bzero(dp, sizeof (fmd_t)); 325*7c478bd9Sstevel@tonic-gate 326*7c478bd9Sstevel@tonic-gate dp->d_version = _fmd_version; 327*7c478bd9Sstevel@tonic-gate dp->d_pname = fmd_strbasename(arg0); 328*7c478bd9Sstevel@tonic-gate dp->d_pid = getpid(); 329*7c478bd9Sstevel@tonic-gate 330*7c478bd9Sstevel@tonic-gate if (pthread_key_create(&dp->d_key, NULL) != 0) 331*7c478bd9Sstevel@tonic-gate fmd_error(EFMD_EXIT, "failed to create pthread key"); 332*7c478bd9Sstevel@tonic-gate 333*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_init(&dp->d_xprt_lock, NULL); 334*7c478bd9Sstevel@tonic-gate (void) pthread_cond_init(&dp->d_xprt_cv, NULL); 335*7c478bd9Sstevel@tonic-gate dp->d_xprt_wait++; /* pause transport threads */ 336*7c478bd9Sstevel@tonic-gate 337*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_init(&dp->d_err_lock, NULL); 338*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_init(&dp->d_thr_lock, NULL); 339*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_init(&dp->d_mod_lock, NULL); 340*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_init(&dp->d_stats_lock, NULL); 341*7c478bd9Sstevel@tonic-gate (void) pthread_rwlock_init(&dp->d_log_lock, NULL); 342*7c478bd9Sstevel@tonic-gate 343*7c478bd9Sstevel@tonic-gate /* 344*7c478bd9Sstevel@tonic-gate * A small number of properties must be set manually before we open 345*7c478bd9Sstevel@tonic-gate * the root configuration file. These include any settings for our 346*7c478bd9Sstevel@tonic-gate * memory allocator and path expansion token values, because these 347*7c478bd9Sstevel@tonic-gate * values are needed by the routines in fmd_conf.c itself. After 348*7c478bd9Sstevel@tonic-gate * the root configuration file is processed, we reset these properties 349*7c478bd9Sstevel@tonic-gate * based upon the latest values from the configuration file. 350*7c478bd9Sstevel@tonic-gate */ 351*7c478bd9Sstevel@tonic-gate dp->d_alloc_msecs = 10; 352*7c478bd9Sstevel@tonic-gate dp->d_alloc_tries = 3; 353*7c478bd9Sstevel@tonic-gate dp->d_str_buckets = 211; 354*7c478bd9Sstevel@tonic-gate 355*7c478bd9Sstevel@tonic-gate dp->d_rootdir = root ? root : ""; 356*7c478bd9Sstevel@tonic-gate dp->d_platform = _fmd_plat; 357*7c478bd9Sstevel@tonic-gate dp->d_machine = _fmd_uts.machine; 358*7c478bd9Sstevel@tonic-gate dp->d_isaname = _fmd_isa; 359*7c478bd9Sstevel@tonic-gate 360*7c478bd9Sstevel@tonic-gate dp->d_conf = fmd_conf_open(conf, 361*7c478bd9Sstevel@tonic-gate sizeof (_fmd_conf) / sizeof (_fmd_conf[0]), _fmd_conf); 362*7c478bd9Sstevel@tonic-gate 363*7c478bd9Sstevel@tonic-gate if (dp->d_conf == NULL) { 364*7c478bd9Sstevel@tonic-gate fmd_error(EFMD_EXIT, 365*7c478bd9Sstevel@tonic-gate "failed to load required configuration properties\n"); 366*7c478bd9Sstevel@tonic-gate } 367*7c478bd9Sstevel@tonic-gate 368*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "alloc.msecs", &dp->d_alloc_msecs); 369*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "alloc.tries", &dp->d_alloc_tries); 370*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "strbuckets", &dp->d_str_buckets); 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "platform", &dp->d_platform); 373*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "machine", &dp->d_machine); 374*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "isaname", &dp->d_isaname); 375*7c478bd9Sstevel@tonic-gate 376*7c478bd9Sstevel@tonic-gate /* 377*7c478bd9Sstevel@tonic-gate * Manually specified rootdirs override config files, so only update 378*7c478bd9Sstevel@tonic-gate * d_rootdir based on the config files we parsed if no 'root' was set. 379*7c478bd9Sstevel@tonic-gate */ 380*7c478bd9Sstevel@tonic-gate if (root == NULL) 381*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "rootdir", &dp->d_rootdir); 382*7c478bd9Sstevel@tonic-gate else 383*7c478bd9Sstevel@tonic-gate (void) fmd_conf_setprop(dp->d_conf, "rootdir", dp->d_rootdir); 384*7c478bd9Sstevel@tonic-gate 385*7c478bd9Sstevel@tonic-gate /* 386*7c478bd9Sstevel@tonic-gate * Once the base conf file properties are loaded, lookup the values 387*7c478bd9Sstevel@tonic-gate * of $conf_path and $conf_file and merge in any other conf files. 388*7c478bd9Sstevel@tonic-gate */ 389*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "conf_path", &pap); 390*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "conf_file", &name); 391*7c478bd9Sstevel@tonic-gate 392*7c478bd9Sstevel@tonic-gate for (i = 0; i < pap->cpa_argc; i++) { 393*7c478bd9Sstevel@tonic-gate (void) snprintf(file, sizeof (file), 394*7c478bd9Sstevel@tonic-gate "%s/%s", pap->cpa_argv[i], name); 395*7c478bd9Sstevel@tonic-gate if (access(file, F_OK) == 0) 396*7c478bd9Sstevel@tonic-gate fmd_conf_merge(dp->d_conf, file); 397*7c478bd9Sstevel@tonic-gate } 398*7c478bd9Sstevel@tonic-gate 399*7c478bd9Sstevel@tonic-gate /* 400*7c478bd9Sstevel@tonic-gate * Update the value of fmd.d_fg based on "fg". We cache this property 401*7c478bd9Sstevel@tonic-gate * because it must be accessed deep within fmd at fmd_verror() time. 402*7c478bd9Sstevel@tonic-gate */ 403*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(fmd.d_conf, "fg", &fmd.d_fg); 404*7c478bd9Sstevel@tonic-gate 405*7c478bd9Sstevel@tonic-gate /* 406*7c478bd9Sstevel@tonic-gate * Initialize our custom libnvpair allocator and create an nvlist for 407*7c478bd9Sstevel@tonic-gate * authority elements corresponding to this instance of the daemon. 408*7c478bd9Sstevel@tonic-gate */ 409*7c478bd9Sstevel@tonic-gate (void) nv_alloc_init(&dp->d_nva, &fmd_nv_alloc_ops); 410*7c478bd9Sstevel@tonic-gate dp->d_auth = fmd_protocol_authority(); 411*7c478bd9Sstevel@tonic-gate 412*7c478bd9Sstevel@tonic-gate /* 413*7c478bd9Sstevel@tonic-gate * The fmd_module_t for the root module must be created manually. Most 414*7c478bd9Sstevel@tonic-gate * of it remains unused and zero, except for the few things we fill in. 415*7c478bd9Sstevel@tonic-gate */ 416*7c478bd9Sstevel@tonic-gate dp->d_rmod = fmd_zalloc(sizeof (fmd_module_t), FMD_SLEEP); 417*7c478bd9Sstevel@tonic-gate dp->d_rmod->mod_name = fmd_strdup(dp->d_pname, FMD_SLEEP); 418*7c478bd9Sstevel@tonic-gate fmd_list_append(&dp->d_mod_list, dp->d_rmod); 419*7c478bd9Sstevel@tonic-gate 420*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_init(&dp->d_rmod->mod_lock, NULL); 421*7c478bd9Sstevel@tonic-gate (void) pthread_cond_init(&dp->d_rmod->mod_cv, NULL); 422*7c478bd9Sstevel@tonic-gate 423*7c478bd9Sstevel@tonic-gate dp->d_rmod->mod_thread = fmd_thread_xcreate(dp->d_rmod, pthread_self()); 424*7c478bd9Sstevel@tonic-gate dp->d_rmod->mod_ustat = fmd_ustat_create(); 425*7c478bd9Sstevel@tonic-gate 426*7c478bd9Sstevel@tonic-gate if (pthread_setspecific(dp->d_key, dp->d_rmod->mod_thread) != 0) 427*7c478bd9Sstevel@tonic-gate fmd_error(EFMD_EXIT, "failed to attach main thread key"); 428*7c478bd9Sstevel@tonic-gate 429*7c478bd9Sstevel@tonic-gate if ((dp->d_stats = (fmd_statistics_t *)fmd_ustat_insert( 430*7c478bd9Sstevel@tonic-gate dp->d_rmod->mod_ustat, FMD_USTAT_NOALLOC, sizeof (_fmd_stats) / 431*7c478bd9Sstevel@tonic-gate sizeof (fmd_stat_t), (fmd_stat_t *)&_fmd_stats, NULL)) == NULL) 432*7c478bd9Sstevel@tonic-gate fmd_error(EFMD_EXIT, "failed to initialize statistics"); 433*7c478bd9Sstevel@tonic-gate 434*7c478bd9Sstevel@tonic-gate /* 435*7c478bd9Sstevel@tonic-gate * In addition to inserting the _fmd_stats collection of program-wide 436*7c478bd9Sstevel@tonic-gate * statistics, we also insert a statistic named after each of our 437*7c478bd9Sstevel@tonic-gate * errors and update these counts in fmd_verror() (see fmd_subr.c). 438*7c478bd9Sstevel@tonic-gate */ 439*7c478bd9Sstevel@tonic-gate dp->d_errstats = sp = fmd_zalloc(sizeof (fmd_stat_t) * 440*7c478bd9Sstevel@tonic-gate (EFMD_END - EFMD_UNKNOWN), FMD_SLEEP); 441*7c478bd9Sstevel@tonic-gate 442*7c478bd9Sstevel@tonic-gate for (i = 0; i < EFMD_END - EFMD_UNKNOWN; i++, sp++) { 443*7c478bd9Sstevel@tonic-gate (void) snprintf(sp->fmds_name, sizeof (sp->fmds_name), "err.%s", 444*7c478bd9Sstevel@tonic-gate strrchr(fmd_errclass(EFMD_UNKNOWN + i), '.') + 1); 445*7c478bd9Sstevel@tonic-gate sp->fmds_type = FMD_TYPE_UINT64; 446*7c478bd9Sstevel@tonic-gate } 447*7c478bd9Sstevel@tonic-gate 448*7c478bd9Sstevel@tonic-gate (void) fmd_ustat_insert(dp->d_rmod->mod_ustat, FMD_USTAT_NOALLOC, 449*7c478bd9Sstevel@tonic-gate EFMD_END - EFMD_UNKNOWN, dp->d_errstats, NULL); 450*7c478bd9Sstevel@tonic-gate } 451*7c478bd9Sstevel@tonic-gate 452*7c478bd9Sstevel@tonic-gate void 453*7c478bd9Sstevel@tonic-gate fmd_destroy(fmd_t *dp) 454*7c478bd9Sstevel@tonic-gate { 455*7c478bd9Sstevel@tonic-gate fmd_module_t *mp; 456*7c478bd9Sstevel@tonic-gate int core; 457*7c478bd9Sstevel@tonic-gate 458*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(fmd.d_conf, "core", &core); 459*7c478bd9Sstevel@tonic-gate 460*7c478bd9Sstevel@tonic-gate fmd_rpc_fini(); 461*7c478bd9Sstevel@tonic-gate fmd_transport_fini(); 462*7c478bd9Sstevel@tonic-gate fmd_dr_fini(); 463*7c478bd9Sstevel@tonic-gate 464*7c478bd9Sstevel@tonic-gate /* 465*7c478bd9Sstevel@tonic-gate * Unload the self-diagnosis module first. This ensures that it does 466*7c478bd9Sstevel@tonic-gate * not get confused as we start unloading other modules, etc. We must 467*7c478bd9Sstevel@tonic-gate * hold the dispq lock as a writer while doing so since it uses d_self. 468*7c478bd9Sstevel@tonic-gate */ 469*7c478bd9Sstevel@tonic-gate if (dp->d_self != NULL) { 470*7c478bd9Sstevel@tonic-gate (void) pthread_rwlock_wrlock(&dp->d_disp->dq_lock); 471*7c478bd9Sstevel@tonic-gate fmd_module_unload(dp->d_self); 472*7c478bd9Sstevel@tonic-gate fmd_module_rele(dp->d_self); 473*7c478bd9Sstevel@tonic-gate dp->d_self = NULL; 474*7c478bd9Sstevel@tonic-gate (void) pthread_rwlock_unlock(&dp->d_disp->dq_lock); 475*7c478bd9Sstevel@tonic-gate } 476*7c478bd9Sstevel@tonic-gate 477*7c478bd9Sstevel@tonic-gate /* 478*7c478bd9Sstevel@tonic-gate * Unload modules in reverse order *except* for the root module, which 479*7c478bd9Sstevel@tonic-gate * is first in the list. This allows it to keep its thread and trace. 480*7c478bd9Sstevel@tonic-gate */ 481*7c478bd9Sstevel@tonic-gate for (mp = fmd_list_prev(&dp->d_mod_list); mp != dp->d_rmod; ) { 482*7c478bd9Sstevel@tonic-gate fmd_module_unload(mp); 483*7c478bd9Sstevel@tonic-gate mp = fmd_list_prev(mp); 484*7c478bd9Sstevel@tonic-gate } 485*7c478bd9Sstevel@tonic-gate 486*7c478bd9Sstevel@tonic-gate if (dp->d_mod_hash != NULL) { 487*7c478bd9Sstevel@tonic-gate fmd_modhash_destroy(dp->d_mod_hash); 488*7c478bd9Sstevel@tonic-gate dp->d_mod_hash = NULL; 489*7c478bd9Sstevel@tonic-gate } 490*7c478bd9Sstevel@tonic-gate 491*7c478bd9Sstevel@tonic-gate /* 492*7c478bd9Sstevel@tonic-gate * Close both log files now that modules are no longer active. We must 493*7c478bd9Sstevel@tonic-gate * set these pointers to NULL in case any subsequent errors occur. 494*7c478bd9Sstevel@tonic-gate */ 495*7c478bd9Sstevel@tonic-gate if (dp->d_errlog != NULL) { 496*7c478bd9Sstevel@tonic-gate fmd_log_rele(dp->d_errlog); 497*7c478bd9Sstevel@tonic-gate dp->d_errlog = NULL; 498*7c478bd9Sstevel@tonic-gate } 499*7c478bd9Sstevel@tonic-gate 500*7c478bd9Sstevel@tonic-gate if (dp->d_fltlog != NULL) { 501*7c478bd9Sstevel@tonic-gate fmd_log_rele(dp->d_fltlog); 502*7c478bd9Sstevel@tonic-gate dp->d_fltlog = NULL; 503*7c478bd9Sstevel@tonic-gate } 504*7c478bd9Sstevel@tonic-gate 505*7c478bd9Sstevel@tonic-gate /* 506*7c478bd9Sstevel@tonic-gate * Now that all data structures that refer to modules are torn down, 507*7c478bd9Sstevel@tonic-gate * no modules should be remaining on the module list except for d_rmod. 508*7c478bd9Sstevel@tonic-gate * If we trip one of these assertions, we're missing a rele somewhere. 509*7c478bd9Sstevel@tonic-gate */ 510*7c478bd9Sstevel@tonic-gate ASSERT(fmd_list_prev(&dp->d_mod_list) == dp->d_rmod); 511*7c478bd9Sstevel@tonic-gate ASSERT(fmd_list_next(&dp->d_mod_list) == dp->d_rmod); 512*7c478bd9Sstevel@tonic-gate 513*7c478bd9Sstevel@tonic-gate /* 514*7c478bd9Sstevel@tonic-gate * Now destroy the root module. We clear its thread key first so any 515*7c478bd9Sstevel@tonic-gate * calls to fmd_trace() inside of the module code will be ignored. 516*7c478bd9Sstevel@tonic-gate */ 517*7c478bd9Sstevel@tonic-gate (void) pthread_setspecific(dp->d_key, NULL); 518*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_lock(&dp->d_rmod->mod_lock); 519*7c478bd9Sstevel@tonic-gate fmd_module_destroy(dp->d_rmod); 520*7c478bd9Sstevel@tonic-gate 521*7c478bd9Sstevel@tonic-gate if (dp->d_timers != NULL) 522*7c478bd9Sstevel@tonic-gate fmd_timerq_destroy(dp->d_timers); 523*7c478bd9Sstevel@tonic-gate if (dp->d_disp != NULL) 524*7c478bd9Sstevel@tonic-gate fmd_dispq_destroy(dp->d_disp); 525*7c478bd9Sstevel@tonic-gate if (dp->d_asrus != NULL) 526*7c478bd9Sstevel@tonic-gate fmd_asru_hash_destroy(dp->d_asrus); 527*7c478bd9Sstevel@tonic-gate if (dp->d_schemes != NULL) 528*7c478bd9Sstevel@tonic-gate fmd_scheme_hash_destroy(dp->d_schemes); 529*7c478bd9Sstevel@tonic-gate if (dp->d_cases != NULL) 530*7c478bd9Sstevel@tonic-gate fmd_case_hash_destroy(dp->d_cases); 531*7c478bd9Sstevel@tonic-gate 532*7c478bd9Sstevel@tonic-gate if (dp->d_errstats != NULL) { 533*7c478bd9Sstevel@tonic-gate fmd_free(dp->d_errstats, 534*7c478bd9Sstevel@tonic-gate sizeof (fmd_stat_t) * (EFMD_END - EFMD_UNKNOWN)); 535*7c478bd9Sstevel@tonic-gate } 536*7c478bd9Sstevel@tonic-gate 537*7c478bd9Sstevel@tonic-gate if (dp->d_conf != NULL) 538*7c478bd9Sstevel@tonic-gate fmd_conf_close(dp->d_conf); 539*7c478bd9Sstevel@tonic-gate 540*7c478bd9Sstevel@tonic-gate nvlist_free(dp->d_auth); 541*7c478bd9Sstevel@tonic-gate (void) nv_alloc_fini(&dp->d_nva); 542*7c478bd9Sstevel@tonic-gate dp->d_clockops->fto_fini(dp->d_clockptr); 543*7c478bd9Sstevel@tonic-gate 544*7c478bd9Sstevel@tonic-gate (void) pthread_key_delete(dp->d_key); 545*7c478bd9Sstevel@tonic-gate bzero(dp, sizeof (fmd_t)); 546*7c478bd9Sstevel@tonic-gate 547*7c478bd9Sstevel@tonic-gate if (core) 548*7c478bd9Sstevel@tonic-gate fmd_panic("forcing core dump at user request\n"); 549*7c478bd9Sstevel@tonic-gate } 550*7c478bd9Sstevel@tonic-gate 551*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 552*7c478bd9Sstevel@tonic-gate static void 553*7c478bd9Sstevel@tonic-gate fmd_gc(fmd_t *dp, id_t id, hrtime_t hrt) 554*7c478bd9Sstevel@tonic-gate { 555*7c478bd9Sstevel@tonic-gate hrtime_t delta; 556*7c478bd9Sstevel@tonic-gate 557*7c478bd9Sstevel@tonic-gate if (id != 0) { 558*7c478bd9Sstevel@tonic-gate TRACE((FMD_DBG_MOD, "garbage collect start")); 559*7c478bd9Sstevel@tonic-gate fmd_modhash_apply(dp->d_mod_hash, fmd_module_gc); 560*7c478bd9Sstevel@tonic-gate TRACE((FMD_DBG_MOD, "garbage collect end")); 561*7c478bd9Sstevel@tonic-gate 562*7c478bd9Sstevel@tonic-gate (void) pthread_rwlock_rdlock(&dp->d_log_lock); 563*7c478bd9Sstevel@tonic-gate fmd_log_update(dp->d_errlog); 564*7c478bd9Sstevel@tonic-gate (void) pthread_rwlock_unlock(&dp->d_log_lock); 565*7c478bd9Sstevel@tonic-gate } 566*7c478bd9Sstevel@tonic-gate 567*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "gc_interval", &delta); 568*7c478bd9Sstevel@tonic-gate (void) fmd_timerq_install(dp->d_timers, dp->d_rmod->mod_timerids, 569*7c478bd9Sstevel@tonic-gate (fmd_timer_f *)fmd_gc, dp, NULL, delta); 570*7c478bd9Sstevel@tonic-gate } 571*7c478bd9Sstevel@tonic-gate 572*7c478bd9Sstevel@tonic-gate /* 573*7c478bd9Sstevel@tonic-gate * Events are committed to the errlog after cases are checkpointed. If fmd 574*7c478bd9Sstevel@tonic-gate * crashes before an event is ever associated with a module, this function will 575*7c478bd9Sstevel@tonic-gate * be called to replay it to all subscribers. If fmd crashes in between the 576*7c478bd9Sstevel@tonic-gate * subscriber checkpointing and committing the event in the error log, the 577*7c478bd9Sstevel@tonic-gate * module will have seen the event and we don't want to replay it. So we look 578*7c478bd9Sstevel@tonic-gate * for the event in all modules and transition it to the proper state. If 579*7c478bd9Sstevel@tonic-gate * it is found, we commit it to the error log and do not replay it. The in- 580*7c478bd9Sstevel@tonic-gate * memory case search used by fmd_module_contains() et al isn't particularly 581*7c478bd9Sstevel@tonic-gate * efficient, but it is faster than doing read i/o's on every case event to 582*7c478bd9Sstevel@tonic-gate * check their status or write i/o's on every event to replay to update states. 583*7c478bd9Sstevel@tonic-gate * We can improve the efficiency of this lookup algorithm later if necessary. 584*7c478bd9Sstevel@tonic-gate */ 585*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 586*7c478bd9Sstevel@tonic-gate static void 587*7c478bd9Sstevel@tonic-gate fmd_err_replay(fmd_log_t *lp, fmd_event_t *ep, fmd_t *dp) 588*7c478bd9Sstevel@tonic-gate { 589*7c478bd9Sstevel@tonic-gate fmd_module_t *mp; 590*7c478bd9Sstevel@tonic-gate fmd_stat_t *sp; 591*7c478bd9Sstevel@tonic-gate 592*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_lock(&dp->d_mod_lock); 593*7c478bd9Sstevel@tonic-gate 594*7c478bd9Sstevel@tonic-gate for (mp = fmd_list_next(&dp->d_mod_list); 595*7c478bd9Sstevel@tonic-gate mp != NULL; mp = fmd_list_next(mp)) { 596*7c478bd9Sstevel@tonic-gate if (fmd_module_contains(mp, ep)) { 597*7c478bd9Sstevel@tonic-gate fmd_module_hold(mp); 598*7c478bd9Sstevel@tonic-gate break; 599*7c478bd9Sstevel@tonic-gate } 600*7c478bd9Sstevel@tonic-gate } 601*7c478bd9Sstevel@tonic-gate 602*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_unlock(&dp->d_mod_lock); 603*7c478bd9Sstevel@tonic-gate 604*7c478bd9Sstevel@tonic-gate if (mp != NULL) { 605*7c478bd9Sstevel@tonic-gate fmd_event_commit(ep); 606*7c478bd9Sstevel@tonic-gate fmd_module_rele(mp); 607*7c478bd9Sstevel@tonic-gate sp = &dp->d_stats->ds_log_partials; 608*7c478bd9Sstevel@tonic-gate } else { 609*7c478bd9Sstevel@tonic-gate fmd_dispq_dispatch(dp->d_disp, ep, 610*7c478bd9Sstevel@tonic-gate ((fmd_event_impl_t *)ep)->ev_data); 611*7c478bd9Sstevel@tonic-gate sp = &dp->d_stats->ds_log_replayed; 612*7c478bd9Sstevel@tonic-gate } 613*7c478bd9Sstevel@tonic-gate 614*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_lock(&dp->d_stats_lock); 615*7c478bd9Sstevel@tonic-gate sp->fmds_value.ui64++; 616*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_unlock(&dp->d_stats_lock); 617*7c478bd9Sstevel@tonic-gate } 618*7c478bd9Sstevel@tonic-gate 619*7c478bd9Sstevel@tonic-gate /* 620*7c478bd9Sstevel@tonic-gate * This signal handler is installed for the client.thrsig signal to be used to 621*7c478bd9Sstevel@tonic-gate * force an auxiliary thread to wake up from a system call and return EINTR in 622*7c478bd9Sstevel@tonic-gate * response to a module's use of fmd_thr_signal(). We also trace the event. 623*7c478bd9Sstevel@tonic-gate */ 624*7c478bd9Sstevel@tonic-gate static void 625*7c478bd9Sstevel@tonic-gate fmd_signal(int sig) 626*7c478bd9Sstevel@tonic-gate { 627*7c478bd9Sstevel@tonic-gate TRACE((FMD_DBG_MOD, "module thread received sig #%d", sig)); 628*7c478bd9Sstevel@tonic-gate } 629*7c478bd9Sstevel@tonic-gate 630*7c478bd9Sstevel@tonic-gate void 631*7c478bd9Sstevel@tonic-gate fmd_run(fmd_t *dp, int pfd) 632*7c478bd9Sstevel@tonic-gate { 633*7c478bd9Sstevel@tonic-gate char *nodc_key[] = { FMD_FLT_NODC, NULL }; 634*7c478bd9Sstevel@tonic-gate char nodc_str[128]; 635*7c478bd9Sstevel@tonic-gate struct sigaction act; 636*7c478bd9Sstevel@tonic-gate 637*7c478bd9Sstevel@tonic-gate int status = FMD_EXIT_SUCCESS; 638*7c478bd9Sstevel@tonic-gate const char *name; 639*7c478bd9Sstevel@tonic-gate fmd_conf_path_t *pap; 640*7c478bd9Sstevel@tonic-gate int dbout; 641*7c478bd9Sstevel@tonic-gate 642*7c478bd9Sstevel@tonic-gate /* 643*7c478bd9Sstevel@tonic-gate * Cache all the current debug property settings in d_fmd_debug, 644*7c478bd9Sstevel@tonic-gate * d_fmd_dbout, d_hdl_debug, and d_hdl_dbout. If a given debug mask 645*7c478bd9Sstevel@tonic-gate * is non-zero and the corresponding dbout mask is zero, set dbout 646*7c478bd9Sstevel@tonic-gate * to a sensible default value based on whether we have daemonized. 647*7c478bd9Sstevel@tonic-gate */ 648*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "dbout", &dbout); 649*7c478bd9Sstevel@tonic-gate 650*7c478bd9Sstevel@tonic-gate if (dp->d_fmd_debug != 0 && dbout == 0) 651*7c478bd9Sstevel@tonic-gate dp->d_fmd_dbout = dp->d_fg? FMD_DBOUT_STDERR : FMD_DBOUT_SYSLOG; 652*7c478bd9Sstevel@tonic-gate else 653*7c478bd9Sstevel@tonic-gate dp->d_fmd_dbout = dbout; 654*7c478bd9Sstevel@tonic-gate 655*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "client.debug", &dp->d_hdl_debug); 656*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "client.dbout", &dbout); 657*7c478bd9Sstevel@tonic-gate 658*7c478bd9Sstevel@tonic-gate if (dp->d_hdl_debug != 0 && dbout == 0) 659*7c478bd9Sstevel@tonic-gate dp->d_hdl_dbout = dp->d_fg? FMD_DBOUT_STDERR : FMD_DBOUT_SYSLOG; 660*7c478bd9Sstevel@tonic-gate else 661*7c478bd9Sstevel@tonic-gate dp->d_hdl_dbout = dbout; 662*7c478bd9Sstevel@tonic-gate 663*7c478bd9Sstevel@tonic-gate /* 664*7c478bd9Sstevel@tonic-gate * Initialize remaining major program data structures such as the event 665*7c478bd9Sstevel@tonic-gate * transport, dispatch queues, log files, module hash collections, etc. 666*7c478bd9Sstevel@tonic-gate * This work is done here rather than in fmd_create() to permit the -o 667*7c478bd9Sstevel@tonic-gate * command-line option to modify properties after fmd_create() is done. 668*7c478bd9Sstevel@tonic-gate * Note that our event transport will remain blocked until we broadcast 669*7c478bd9Sstevel@tonic-gate * to threads blocked on d_xprt_cv at the end of this function. 670*7c478bd9Sstevel@tonic-gate */ 671*7c478bd9Sstevel@tonic-gate dp->d_clockptr = dp->d_clockops->fto_init(); 672*7c478bd9Sstevel@tonic-gate fmd_transport_init(); 673*7c478bd9Sstevel@tonic-gate fmd_rpc_init(); 674*7c478bd9Sstevel@tonic-gate fmd_dr_init(); 675*7c478bd9Sstevel@tonic-gate 676*7c478bd9Sstevel@tonic-gate dp->d_rmod->mod_timerids = fmd_idspace_create(dp->d_pname, 1, 16); 677*7c478bd9Sstevel@tonic-gate dp->d_timers = fmd_timerq_create(); 678*7c478bd9Sstevel@tonic-gate dp->d_disp = fmd_dispq_create(); 679*7c478bd9Sstevel@tonic-gate dp->d_cases = fmd_case_hash_create(); 680*7c478bd9Sstevel@tonic-gate 681*7c478bd9Sstevel@tonic-gate /* 682*7c478bd9Sstevel@tonic-gate * Once our subsystems that use signals have been set up, install the 683*7c478bd9Sstevel@tonic-gate * signal handler for the fmd_thr_signal() API. Verify that the signal 684*7c478bd9Sstevel@tonic-gate * being used for this purpose doesn't conflict with something else. 685*7c478bd9Sstevel@tonic-gate */ 686*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "client.thrsig", &dp->d_thr_sig); 687*7c478bd9Sstevel@tonic-gate 688*7c478bd9Sstevel@tonic-gate if (sigaction(dp->d_thr_sig, NULL, &act) != 0) { 689*7c478bd9Sstevel@tonic-gate fmd_error(EFMD_EXIT, "invalid signal selected for " 690*7c478bd9Sstevel@tonic-gate "client.thrsig property: %d\n", dp->d_thr_sig); 691*7c478bd9Sstevel@tonic-gate } 692*7c478bd9Sstevel@tonic-gate 693*7c478bd9Sstevel@tonic-gate if (act.sa_handler != SIG_IGN && act.sa_handler != SIG_DFL) { 694*7c478bd9Sstevel@tonic-gate fmd_error(EFMD_EXIT, "signal selected for client.thrsig " 695*7c478bd9Sstevel@tonic-gate "property is already in use: %d\n", dp->d_thr_sig); 696*7c478bd9Sstevel@tonic-gate } 697*7c478bd9Sstevel@tonic-gate 698*7c478bd9Sstevel@tonic-gate act.sa_handler = fmd_signal; 699*7c478bd9Sstevel@tonic-gate act.sa_flags = 0; 700*7c478bd9Sstevel@tonic-gate 701*7c478bd9Sstevel@tonic-gate (void) sigemptyset(&act.sa_mask); 702*7c478bd9Sstevel@tonic-gate (void) sigaction(dp->d_thr_sig, &act, NULL); 703*7c478bd9Sstevel@tonic-gate 704*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "schemedir", &name); 705*7c478bd9Sstevel@tonic-gate dp->d_schemes = fmd_scheme_hash_create(dp->d_rootdir, name); 706*7c478bd9Sstevel@tonic-gate 707*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "log.rsrc", &name); 708*7c478bd9Sstevel@tonic-gate dp->d_asrus = fmd_asru_hash_create(dp->d_rootdir, name); 709*7c478bd9Sstevel@tonic-gate 710*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "log.error", &name); 711*7c478bd9Sstevel@tonic-gate dp->d_errlog = fmd_log_open(dp->d_rootdir, name, FMD_LOG_ERROR); 712*7c478bd9Sstevel@tonic-gate 713*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "log.fault", &name); 714*7c478bd9Sstevel@tonic-gate dp->d_fltlog = fmd_log_open(dp->d_rootdir, name, FMD_LOG_FAULT); 715*7c478bd9Sstevel@tonic-gate 716*7c478bd9Sstevel@tonic-gate if (dp->d_asrus == NULL || dp->d_errlog == NULL || dp->d_fltlog == NULL) 717*7c478bd9Sstevel@tonic-gate fmd_error(EFMD_EXIT, "failed to initialize log files\n"); 718*7c478bd9Sstevel@tonic-gate 719*7c478bd9Sstevel@tonic-gate dp->d_mod_hash = fmd_modhash_create(); 720*7c478bd9Sstevel@tonic-gate dp->d_running = 1; /* we are now officially an active fmd */ 721*7c478bd9Sstevel@tonic-gate 722*7c478bd9Sstevel@tonic-gate /* 723*7c478bd9Sstevel@tonic-gate * Now that we're running, if a pipe fd was specified, write an exit 724*7c478bd9Sstevel@tonic-gate * status to it to indicate that our parent process can safely detach. 725*7c478bd9Sstevel@tonic-gate */ 726*7c478bd9Sstevel@tonic-gate if (pfd >= 0) 727*7c478bd9Sstevel@tonic-gate (void) write(pfd, &status, sizeof (status)); 728*7c478bd9Sstevel@tonic-gate 729*7c478bd9Sstevel@tonic-gate /* 730*7c478bd9Sstevel@tonic-gate * Once all data structures are initialized, we load all of our modules 731*7c478bd9Sstevel@tonic-gate * in order according to class in order to load up any subscriptions. 732*7c478bd9Sstevel@tonic-gate */ 733*7c478bd9Sstevel@tonic-gate fmd_builtin_loadall(dp->d_mod_hash); 734*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "self.name", &name); 735*7c478bd9Sstevel@tonic-gate dp->d_self = fmd_modhash_lookup(dp->d_mod_hash, name); 736*7c478bd9Sstevel@tonic-gate 737*7c478bd9Sstevel@tonic-gate if (fmd_module_dc_key2code(dp->d_self, 738*7c478bd9Sstevel@tonic-gate nodc_key, nodc_str, sizeof (nodc_str)) == 0) 739*7c478bd9Sstevel@tonic-gate (void) fmd_conf_setprop(dp->d_conf, "nodiagcode", nodc_str); 740*7c478bd9Sstevel@tonic-gate 741*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "plugin.path", &pap); 742*7c478bd9Sstevel@tonic-gate fmd_modhash_loadall(dp->d_mod_hash, pap, &fmd_rtld_ops); 743*7c478bd9Sstevel@tonic-gate 744*7c478bd9Sstevel@tonic-gate (void) fmd_conf_getprop(dp->d_conf, "agent.path", &pap); 745*7c478bd9Sstevel@tonic-gate fmd_modhash_loadall(dp->d_mod_hash, pap, &fmd_proc_ops); 746*7c478bd9Sstevel@tonic-gate 747*7c478bd9Sstevel@tonic-gate /* 748*7c478bd9Sstevel@tonic-gate * Before activating the inbound event transport, we first replay any 749*7c478bd9Sstevel@tonic-gate * fault events from the ASRU cache, any case events from the case hash 750*7c478bd9Sstevel@tonic-gate * associated with restored case checkpoints, and any error events from 751*7c478bd9Sstevel@tonic-gate * the errlog that did not finish processing the last time we ran. Then 752*7c478bd9Sstevel@tonic-gate * we replay any pending events from the event transport itself. 753*7c478bd9Sstevel@tonic-gate */ 754*7c478bd9Sstevel@tonic-gate fmd_asru_hash_refresh(dp->d_asrus); 755*7c478bd9Sstevel@tonic-gate fmd_case_hash_refresh(dp->d_cases); 756*7c478bd9Sstevel@tonic-gate 757*7c478bd9Sstevel@tonic-gate (void) pthread_rwlock_rdlock(&dp->d_log_lock); 758*7c478bd9Sstevel@tonic-gate fmd_log_replay(dp->d_errlog, (fmd_log_f *)fmd_err_replay, dp); 759*7c478bd9Sstevel@tonic-gate fmd_log_update(dp->d_errlog); 760*7c478bd9Sstevel@tonic-gate (void) pthread_rwlock_unlock(&dp->d_log_lock); 761*7c478bd9Sstevel@tonic-gate 762*7c478bd9Sstevel@tonic-gate fmd_transport_replay(); 763*7c478bd9Sstevel@tonic-gate 764*7c478bd9Sstevel@tonic-gate /* 765*7c478bd9Sstevel@tonic-gate * Finally, awaken any threads associated with receiving events from 766*7c478bd9Sstevel@tonic-gate * our main ereport event transport that are sleeping on d_xprt_wait. 767*7c478bd9Sstevel@tonic-gate */ 768*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_lock(&dp->d_xprt_lock); 769*7c478bd9Sstevel@tonic-gate ASSERT(dp->d_xprt_wait != 0); 770*7c478bd9Sstevel@tonic-gate dp->d_xprt_wait--; 771*7c478bd9Sstevel@tonic-gate (void) pthread_mutex_unlock(&dp->d_xprt_lock); 772*7c478bd9Sstevel@tonic-gate (void) pthread_cond_broadcast(&dp->d_xprt_cv); 773*7c478bd9Sstevel@tonic-gate 774*7c478bd9Sstevel@tonic-gate fmd_gc(dp, 0, 0); 775*7c478bd9Sstevel@tonic-gate } 776*7c478bd9Sstevel@tonic-gate 777*7c478bd9Sstevel@tonic-gate void 778*7c478bd9Sstevel@tonic-gate fmd_help(fmd_t *dp) 779*7c478bd9Sstevel@tonic-gate { 780*7c478bd9Sstevel@tonic-gate const fmd_conf_mode_t *cmp; 781*7c478bd9Sstevel@tonic-gate 782*7c478bd9Sstevel@tonic-gate (void) printf("Usage: %s -o debug=mode[,mode]\n", dp->d_pname); 783*7c478bd9Sstevel@tonic-gate 784*7c478bd9Sstevel@tonic-gate for (cmp = _fmd_debug_modes; cmp->cm_name != NULL; cmp++) 785*7c478bd9Sstevel@tonic-gate (void) printf("\t%s\t%s\n", cmp->cm_name, cmp->cm_desc); 786*7c478bd9Sstevel@tonic-gate } 787