4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <fmd_module.h>
33 #include <fmd_error.h>
34 #include <fmd_alloc.h>
36 #include <fmd_event.h>
39 typedef struct fmd_rtld
{
40 void *rtld_dlp
; /* libdl(3DL) handle for shared library */
41 void (*rtld_init
)(fmd_hdl_t
*); /* shared library's _fmd_init() */
42 void (*rtld_fini
)(fmd_hdl_t
*); /* shared library's _fmd_fini() */
46 rtld_init(fmd_module_t
*mp
)
51 if ((dlp
= dlopen(mp
->mod_path
, RTLD_LOCAL
| RTLD_NOW
)) == NULL
) {
52 fmd_error(EFMD_RTLD_OPEN
, "%s\n", dlerror());
53 return (fmd_set_errno(EFMD_RTLD_OPEN
));
56 rp
= mp
->mod_data
= fmd_alloc(sizeof (fmd_rtld_t
), FMD_SLEEP
);
59 rp
->rtld_init
= (void (*)())dlsym(dlp
, "_fmd_init");
60 rp
->rtld_fini
= (void (*)())dlsym(dlp
, "_fmd_fini");
62 if (rp
->rtld_init
== NULL
) {
64 fmd_free(rp
, sizeof (fmd_rtld_t
));
65 return (fmd_set_errno(EFMD_RTLD_INIT
));
68 (void) pthread_mutex_unlock(&mp
->mod_lock
);
71 * Call _fmd_init() in the module. If this causes a module abort and
72 * mod_info has been registered, unregister it on behalf of the module.
74 if (fmd_module_enter(mp
, rp
->rtld_init
) != 0 && mp
->mod_info
!= NULL
)
75 fmd_hdl_unregister((fmd_hdl_t
*)mp
);
78 (void) pthread_mutex_lock(&mp
->mod_lock
);
80 if (mp
->mod_info
== NULL
) {
82 fmd_free(rp
, sizeof (fmd_rtld_t
));
83 return (fmd_set_errno(EFMD_HDL_INIT
));
90 rtld_fini(fmd_module_t
*mp
)
92 fmd_rtld_t
*rp
= mp
->mod_data
;
93 int doclose
= 1, err
= 0;
95 if (mp
->mod_info
!= NULL
) {
96 (void) fmd_module_enter(mp
, rp
->rtld_fini
);
98 if (mp
->mod_info
!= NULL
) {
100 fmd_module_unregister(mp
);
101 fmd_module_unlock(mp
);
107 (void) fmd_conf_getprop(fmd
.d_conf
, "plugin.close", &doclose
);
109 err
= dlclose(rp
->rtld_dlp
);
111 fmd_free(rp
, sizeof (fmd_rtld_t
));
115 const fmd_modops_t fmd_rtld_ops
= {
119 fmd_module_transport
,