dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / fm / fmd / common / fmd_builtin.c
blob84435216c99251b50962277d08c64fcd4add16eb
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
26 #include <fmd_module.h>
27 #include <fmd_subr.h>
28 #include <fmd_error.h>
29 #include <fmd_string.h>
30 #include <fmd_event.h>
31 #include <fmd_builtin.h>
32 #include <zone.h>
34 static const struct fmd_builtin _fmd_builtins[] = {
35 { "fmd-self-diagnosis", self_init, self_fini, FMD_BUILTIN_ALLCTXT },
36 { "sysevent-transport", sysev_init, sysev_fini,
37 FMD_BUILTIN_CTXT_GLOBALZONE },
38 { NULL, NULL, NULL, 0 }
41 static int
42 bltin_init(fmd_module_t *mp)
44 const fmd_builtin_t *bp;
46 for (bp = _fmd_builtins; bp->bltin_name != NULL; bp++) {
47 if (strcmp(mp->mod_name, bp->bltin_name) == 0)
48 break;
51 if (bp == NULL)
52 return (fmd_set_errno(EFMD_BLTIN_NAME));
54 if (bp->bltin_init == NULL)
55 return (fmd_set_errno(EFMD_BLTIN_INIT));
57 mp->mod_data = (void *)bp;
58 (void) pthread_mutex_unlock(&mp->mod_lock);
61 * Call _fmd_init() in the module. If this causes a module abort and
62 * mod_info has been registered, unregister it on behalf of the module.
64 if (fmd_module_enter(mp, bp->bltin_init) != 0 && mp->mod_info != NULL)
65 fmd_hdl_unregister((fmd_hdl_t *)mp);
67 fmd_module_exit(mp);
68 (void) pthread_mutex_lock(&mp->mod_lock);
70 if (mp->mod_info == NULL)
71 return (fmd_set_errno(EFMD_HDL_INIT));
73 return (0);
76 static int
77 bltin_fini(fmd_module_t *mp)
79 fmd_builtin_t *bp = mp->mod_data;
81 if (mp->mod_info != NULL) {
82 (void) fmd_module_enter(mp, bp->bltin_fini);
84 if (mp->mod_info != NULL) {
85 fmd_module_lock(mp);
86 fmd_module_unregister(mp);
87 fmd_module_unlock(mp);
90 fmd_module_exit(mp);
93 return (0);
96 const fmd_modops_t fmd_bltin_ops = {
97 bltin_init,
98 bltin_fini,
99 fmd_module_dispatch,
100 fmd_module_transport,
104 fmd_builtin_loadall(fmd_modhash_t *mhp)
106 const fmd_builtin_t *bp;
107 uint32_t ctxt = 0;
108 int err = 0;
110 ctxt |= (getzoneid() == GLOBAL_ZONEID) ? FMD_BUILTIN_CTXT_GLOBALZONE :
111 FMD_BUILTIN_CTXT_NONGLOBALZONE;
113 for (bp = _fmd_builtins; bp->bltin_name != NULL; bp++) {
114 if (!(ctxt & bp->bltin_ctxts))
115 continue;
117 if (fmd_modhash_load(mhp, bp->bltin_name,
118 &fmd_bltin_ops) == NULL)
119 err = -1;
122 return (err);