17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*f6e214c7SGavin Maltby * Common Development and Distribution License (the "License"). 6*f6e214c7SGavin Maltby * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21d9638e54Smws 227c478bd9Sstevel@tonic-gate /* 23*f6e214c7SGavin Maltby * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <fmd_module.h> 277c478bd9Sstevel@tonic-gate #include <fmd_subr.h> 287c478bd9Sstevel@tonic-gate #include <fmd_error.h> 297c478bd9Sstevel@tonic-gate #include <fmd_string.h> 307c478bd9Sstevel@tonic-gate #include <fmd_event.h> 317c478bd9Sstevel@tonic-gate #include <fmd_builtin.h> 32*f6e214c7SGavin Maltby #include <zone.h> 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate static const struct fmd_builtin _fmd_builtins[] = { 35*f6e214c7SGavin Maltby { "fmd-self-diagnosis", self_init, self_fini, FMD_BUILTIN_ALLCTXT }, 36*f6e214c7SGavin Maltby { "sysevent-transport", sysev_init, sysev_fini, 37*f6e214c7SGavin Maltby FMD_BUILTIN_CTXT_GLOBALZONE }, 38*f6e214c7SGavin Maltby { NULL, NULL, NULL, 0 } 397c478bd9Sstevel@tonic-gate }; 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate static int 427c478bd9Sstevel@tonic-gate bltin_init(fmd_module_t *mp) 437c478bd9Sstevel@tonic-gate { 447c478bd9Sstevel@tonic-gate const fmd_builtin_t *bp; 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate for (bp = _fmd_builtins; bp->bltin_name != NULL; bp++) { 477c478bd9Sstevel@tonic-gate if (strcmp(mp->mod_name, bp->bltin_name) == 0) 487c478bd9Sstevel@tonic-gate break; 497c478bd9Sstevel@tonic-gate } 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate if (bp == NULL) 527c478bd9Sstevel@tonic-gate return (fmd_set_errno(EFMD_BLTIN_NAME)); 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate if (bp->bltin_init == NULL) 557c478bd9Sstevel@tonic-gate return (fmd_set_errno(EFMD_BLTIN_INIT)); 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate mp->mod_data = (void *)bp; 587c478bd9Sstevel@tonic-gate (void) pthread_mutex_unlock(&mp->mod_lock); 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate /* 617c478bd9Sstevel@tonic-gate * Call _fmd_init() in the module. If this causes a module abort and 627c478bd9Sstevel@tonic-gate * mod_info has been registered, unregister it on behalf of the module. 637c478bd9Sstevel@tonic-gate */ 647c478bd9Sstevel@tonic-gate if (fmd_module_enter(mp, bp->bltin_init) != 0 && mp->mod_info != NULL) 657c478bd9Sstevel@tonic-gate fmd_hdl_unregister((fmd_hdl_t *)mp); 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate fmd_module_exit(mp); 687c478bd9Sstevel@tonic-gate (void) pthread_mutex_lock(&mp->mod_lock); 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate if (mp->mod_info == NULL) 717c478bd9Sstevel@tonic-gate return (fmd_set_errno(EFMD_HDL_INIT)); 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate return (0); 747c478bd9Sstevel@tonic-gate } 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate static int 777c478bd9Sstevel@tonic-gate bltin_fini(fmd_module_t *mp) 787c478bd9Sstevel@tonic-gate { 797c478bd9Sstevel@tonic-gate fmd_builtin_t *bp = mp->mod_data; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate if (mp->mod_info != NULL) { 827c478bd9Sstevel@tonic-gate (void) fmd_module_enter(mp, bp->bltin_fini); 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate if (mp->mod_info != NULL) { 857c478bd9Sstevel@tonic-gate fmd_module_lock(mp); 867c478bd9Sstevel@tonic-gate fmd_module_unregister(mp); 877c478bd9Sstevel@tonic-gate fmd_module_unlock(mp); 887c478bd9Sstevel@tonic-gate } 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate fmd_module_exit(mp); 917c478bd9Sstevel@tonic-gate } 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate return (0); 947c478bd9Sstevel@tonic-gate } 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate const fmd_modops_t fmd_bltin_ops = { 977c478bd9Sstevel@tonic-gate bltin_init, 987c478bd9Sstevel@tonic-gate bltin_fini, 997c478bd9Sstevel@tonic-gate fmd_module_dispatch, 100d9638e54Smws fmd_module_transport, 1017c478bd9Sstevel@tonic-gate }; 1027c478bd9Sstevel@tonic-gate 103d9638e54Smws int 1047c478bd9Sstevel@tonic-gate fmd_builtin_loadall(fmd_modhash_t *mhp) 1057c478bd9Sstevel@tonic-gate { 1067c478bd9Sstevel@tonic-gate const fmd_builtin_t *bp; 107*f6e214c7SGavin Maltby uint32_t ctxt = 0; 108d9638e54Smws int err = 0; 1097c478bd9Sstevel@tonic-gate 110*f6e214c7SGavin Maltby ctxt |= (getzoneid() == GLOBAL_ZONEID) ? FMD_BUILTIN_CTXT_GLOBALZONE : 111*f6e214c7SGavin Maltby FMD_BUILTIN_CTXT_NONGLOBALZONE; 112*f6e214c7SGavin Maltby 113d9638e54Smws for (bp = _fmd_builtins; bp->bltin_name != NULL; bp++) { 114*f6e214c7SGavin Maltby if (!(ctxt & bp->bltin_ctxts)) 115*f6e214c7SGavin Maltby continue; 116*f6e214c7SGavin Maltby 117d9638e54Smws if (fmd_modhash_load(mhp, bp->bltin_name, 118d9638e54Smws &fmd_bltin_ops) == NULL) 119d9638e54Smws err = -1; 120d9638e54Smws } 121d9638e54Smws 122d9638e54Smws return (err); 1237c478bd9Sstevel@tonic-gate } 124