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
5*12967Sgavin.maltby@oracle.com * Common Development and Distribution License (the "License").
6*12967Sgavin.maltby@oracle.com * 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 /*
23*12967Sgavin.maltby@oracle.com * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include <fmd_module.h>
270Sstevel@tonic-gate #include <fmd_subr.h>
280Sstevel@tonic-gate #include <fmd_error.h>
290Sstevel@tonic-gate #include <fmd_string.h>
300Sstevel@tonic-gate #include <fmd_event.h>
310Sstevel@tonic-gate #include <fmd_builtin.h>
32*12967Sgavin.maltby@oracle.com #include <zone.h>
330Sstevel@tonic-gate
340Sstevel@tonic-gate static const struct fmd_builtin _fmd_builtins[] = {
35*12967Sgavin.maltby@oracle.com { "fmd-self-diagnosis", self_init, self_fini, FMD_BUILTIN_ALLCTXT },
36*12967Sgavin.maltby@oracle.com { "sysevent-transport", sysev_init, sysev_fini,
37*12967Sgavin.maltby@oracle.com FMD_BUILTIN_CTXT_GLOBALZONE },
38*12967Sgavin.maltby@oracle.com { NULL, NULL, NULL, 0 }
390Sstevel@tonic-gate };
400Sstevel@tonic-gate
410Sstevel@tonic-gate static int
bltin_init(fmd_module_t * mp)420Sstevel@tonic-gate bltin_init(fmd_module_t *mp)
430Sstevel@tonic-gate {
440Sstevel@tonic-gate const fmd_builtin_t *bp;
450Sstevel@tonic-gate
460Sstevel@tonic-gate for (bp = _fmd_builtins; bp->bltin_name != NULL; bp++) {
470Sstevel@tonic-gate if (strcmp(mp->mod_name, bp->bltin_name) == 0)
480Sstevel@tonic-gate break;
490Sstevel@tonic-gate }
500Sstevel@tonic-gate
510Sstevel@tonic-gate if (bp == NULL)
520Sstevel@tonic-gate return (fmd_set_errno(EFMD_BLTIN_NAME));
530Sstevel@tonic-gate
540Sstevel@tonic-gate if (bp->bltin_init == NULL)
550Sstevel@tonic-gate return (fmd_set_errno(EFMD_BLTIN_INIT));
560Sstevel@tonic-gate
570Sstevel@tonic-gate mp->mod_data = (void *)bp;
580Sstevel@tonic-gate (void) pthread_mutex_unlock(&mp->mod_lock);
590Sstevel@tonic-gate
600Sstevel@tonic-gate /*
610Sstevel@tonic-gate * Call _fmd_init() in the module. If this causes a module abort and
620Sstevel@tonic-gate * mod_info has been registered, unregister it on behalf of the module.
630Sstevel@tonic-gate */
640Sstevel@tonic-gate if (fmd_module_enter(mp, bp->bltin_init) != 0 && mp->mod_info != NULL)
650Sstevel@tonic-gate fmd_hdl_unregister((fmd_hdl_t *)mp);
660Sstevel@tonic-gate
670Sstevel@tonic-gate fmd_module_exit(mp);
680Sstevel@tonic-gate (void) pthread_mutex_lock(&mp->mod_lock);
690Sstevel@tonic-gate
700Sstevel@tonic-gate if (mp->mod_info == NULL)
710Sstevel@tonic-gate return (fmd_set_errno(EFMD_HDL_INIT));
720Sstevel@tonic-gate
730Sstevel@tonic-gate return (0);
740Sstevel@tonic-gate }
750Sstevel@tonic-gate
760Sstevel@tonic-gate static int
bltin_fini(fmd_module_t * mp)770Sstevel@tonic-gate bltin_fini(fmd_module_t *mp)
780Sstevel@tonic-gate {
790Sstevel@tonic-gate fmd_builtin_t *bp = mp->mod_data;
800Sstevel@tonic-gate
810Sstevel@tonic-gate if (mp->mod_info != NULL) {
820Sstevel@tonic-gate (void) fmd_module_enter(mp, bp->bltin_fini);
830Sstevel@tonic-gate
840Sstevel@tonic-gate if (mp->mod_info != NULL) {
850Sstevel@tonic-gate fmd_module_lock(mp);
860Sstevel@tonic-gate fmd_module_unregister(mp);
870Sstevel@tonic-gate fmd_module_unlock(mp);
880Sstevel@tonic-gate }
890Sstevel@tonic-gate
900Sstevel@tonic-gate fmd_module_exit(mp);
910Sstevel@tonic-gate }
920Sstevel@tonic-gate
930Sstevel@tonic-gate return (0);
940Sstevel@tonic-gate }
950Sstevel@tonic-gate
960Sstevel@tonic-gate const fmd_modops_t fmd_bltin_ops = {
970Sstevel@tonic-gate bltin_init,
980Sstevel@tonic-gate bltin_fini,
990Sstevel@tonic-gate fmd_module_dispatch,
1001193Smws fmd_module_transport,
1010Sstevel@tonic-gate };
1020Sstevel@tonic-gate
1031193Smws int
fmd_builtin_loadall(fmd_modhash_t * mhp)1040Sstevel@tonic-gate fmd_builtin_loadall(fmd_modhash_t *mhp)
1050Sstevel@tonic-gate {
1060Sstevel@tonic-gate const fmd_builtin_t *bp;
107*12967Sgavin.maltby@oracle.com uint32_t ctxt = 0;
1081193Smws int err = 0;
1090Sstevel@tonic-gate
110*12967Sgavin.maltby@oracle.com ctxt |= (getzoneid() == GLOBAL_ZONEID) ? FMD_BUILTIN_CTXT_GLOBALZONE :
111*12967Sgavin.maltby@oracle.com FMD_BUILTIN_CTXT_NONGLOBALZONE;
112*12967Sgavin.maltby@oracle.com
1131193Smws for (bp = _fmd_builtins; bp->bltin_name != NULL; bp++) {
114*12967Sgavin.maltby@oracle.com if (!(ctxt & bp->bltin_ctxts))
115*12967Sgavin.maltby@oracle.com continue;
116*12967Sgavin.maltby@oracle.com
1171193Smws if (fmd_modhash_load(mhp, bp->bltin_name,
1181193Smws &fmd_bltin_ops) == NULL)
1191193Smws err = -1;
1201193Smws }
1211193Smws
1221193Smws return (err);
1230Sstevel@tonic-gate }
124