source changes for static plugin support

This commit is contained in:
Duncan Laurie 2004-01-26 17:31:13 +00:00
parent ccd0920f37
commit 98035ca03d
3 changed files with 82 additions and 6 deletions

View File

@ -39,6 +39,11 @@
#include <ipmitool/ipmi.h>
struct static_intf {
char * name;
int (*setup)(struct ipmi_intf ** intf);
};
int ipmi_intf_init(void);
void ipmi_intf_exit(void);
struct ipmi_intf * ipmi_intf_load(char * name);

View File

@ -42,6 +42,8 @@
#include <ipmitool/ipmi_intf.h>
#include <ipmitool/ipmi.h>
extern struct static_intf static_intf_list[];
/* ipmi_intf_init
* initialize dynamic plugin interface
*/
@ -78,23 +80,43 @@ struct ipmi_intf * ipmi_intf_load(char * name)
{
lt_dlhandle handle;
struct ipmi_intf * intf;
int (*intf_setup)(struct ipmi_intf ** intf);
int (*setup)(struct ipmi_intf ** intf);
struct static_intf *i = static_intf_list;
char libname[16];
handle = lt_dlopenext(name);
if (handle == NULL) {
while (i->name) {
if (!strcmp(name, i->name)) {
if (i->setup(&intf) < 0) {
printf("ERROR: Unable to setup static interface %s\n", name);
return NULL;
}
return intf;
}
i++;
}
memset(libname, 0, 16);
if (snprintf(libname, sizeof(libname), "lib%s", name) <= 0) {
printf("ERROR: Unable to find plugin '%s' in '%s'\n",
name, PLUGIN_PATH);
return NULL;
}
intf_setup = lt_dlsym(handle, "intf_setup");
if (!intf_setup) {
handle = lt_dlopenext(libname);
if (handle == NULL) {
printf("ERROR: Unable to find plugin '%s' in '%s'\n",
libname, PLUGIN_PATH);
return NULL;
}
setup = lt_dlsym(handle, "intf_setup");
if (!setup) {
printf("ERROR: Unable to find interface setup symbol in plugin %s\n", name);
lt_dlclose(handle);
return NULL;
}
if (intf_setup(&intf) < 0) {
if (setup(&intf) < 0) {
printf("ERROR: Unable to run interface setup for plugin %s\n", name);
lt_dlclose(handle);
return NULL;

View File

@ -0,0 +1,49 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
* SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
* OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
* SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
* OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
* LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
*/
#include <stdio.h>
#include <stdlib.h>
#include <config.h>
#include <ipmitool/ipmi_intf.h>
#include <ipmitool/ipmi.h>
@STATIC_INTF_EXT@
struct static_intf static_intf_list[] = {
@STATIC_INTF@
{ 0, 0 }
};