diff --git a/src/common/plugin.c b/src/common/plugin.c index 45a8e0beb9f11e24093faeb7ffa9b5da60603b51..84e6cee71524b62d1623df3373f6a9848ec97757 100644 --- a/src/common/plugin.c +++ b/src/common/plugin.c @@ -1,8 +1,8 @@ /*****************************************************************************\ - * plugin.h - plugin architecture implementation. + * plugin.h - plugin architecture implementation. ***************************************************************************** * Copyright (C) 2002-2007 The Regents of the University of California. - * Copyright (C) 2008 Lawrence Livermore National Security. + * Copyright (C) 2008-2009 Lawrence Livermore National Security. * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). * Written by Jay Windley <jwindley@lnxi.com>. * CODE-OCEC-09-009. All rights reserved. @@ -44,7 +44,7 @@ #include <errno.h> #include <sys/types.h> #include <stdio.h> -#include <dlfcn.h> /* don't know if there's an autoconf for this. */ +#include <dlfcn.h> /* don't know if there's an autoconf for this. */ #include <string.h> #include "src/common/xmalloc.h" @@ -122,13 +122,13 @@ plugin_peek( const char *fq_path, } plugin_handle_t -plugin_load_from_file( const char *fq_path ) +plugin_load_from_file(const char *fq_path) { - plugin_handle_t plug; - int (*init)( void ); - - /* - * Try to open the shared object. + plugin_handle_t plug; + int (*init)(void); + + /* + * Try to open the shared object. * * Use RTLD_LAZY to allow plugins to use symbols that may be * defined in only one slurm entity (e.g. srun and not slurmd), @@ -136,45 +136,45 @@ plugin_load_from_file( const char *fq_path ) * entity from which it is available. (i.e. srun symbols are only * used in the context of srun, not slurmd.) * - */ - plug = dlopen( fq_path, RTLD_LAZY ); - if ( plug == NULL ) { - error( "plugin_load_from_file: dlopen(%s): %s", - fq_path, - _dlerror() ); - return PLUGIN_INVALID_HANDLE; - } - - /* Now see if our required symbols are defined. */ - if ( ( dlsym( plug, PLUGIN_NAME ) == NULL ) || - ( dlsym( plug, PLUGIN_TYPE ) == NULL ) || - ( dlsym( plug, PLUGIN_VERSION ) == NULL ) ) { - debug( "plugin_load_from_file: invalid symbol"); - /* slurm_seterrno( SLURM_PLUGIN_SYMBOLS ); */ - return PLUGIN_INVALID_HANDLE; - } + */ + plug = dlopen(fq_path, RTLD_LAZY); + if (plug == NULL) { + error("plugin_load_from_file: dlopen(%s): %s", + fq_path, + _dlerror()); + return PLUGIN_INVALID_HANDLE; + } - /* - * Now call its init() function, if present. If the function - * returns nonzero, unload the plugin and signal an error. - */ - if ( ( init = dlsym( plug, "init" ) ) != NULL ) { - if ( (*init)() != 0 ) { - error( "plugin_load_from_file(%s): init() returned SLURM_ERROR", - fq_path ); - (void) dlclose( plug ); - return PLUGIN_INVALID_HANDLE; - } - } - - return plug; + /* Now see if our required symbols are defined. */ + if ((dlsym(plug, PLUGIN_NAME) == NULL) || + (dlsym(plug, PLUGIN_TYPE) == NULL) || + (dlsym(plug, PLUGIN_VERSION) == NULL)) { + debug("plugin_load_from_file: invalid symbol"); + /* slurm_seterrno( SLURM_PLUGIN_SYMBOLS ); */ + return PLUGIN_INVALID_HANDLE; + } + + /* + * Now call its init() function, if present. If the function + * returns nonzero, unload the plugin and signal an error. + */ + if ((init = dlsym(plug, "init")) != NULL) { + if ((*init)() != 0) { + error("plugin_load_from_file(%s): init() returned SLURM_ERROR", + fq_path); + (void) dlclose(plug); + return PLUGIN_INVALID_HANDLE; + } + } + + return plug; } plugin_handle_t plugin_load_and_link(const char *type_name, int n_syms, const char *names[], void *ptrs[]) { - plugin_handle_t plug = PLUGIN_INVALID_HANDLE; + plugin_handle_t plug = PLUGIN_INVALID_HANDLE; struct stat st; char *head=NULL, *dir_array=NULL, *so_name = NULL, *file_name=NULL; @@ -240,72 +240,72 @@ plugin_load_and_link(const char *type_name, int n_syms, void plugin_unload( plugin_handle_t plug ) { - void (*fini)(void); - - if ( plug != PLUGIN_INVALID_HANDLE ) { - if ( ( fini = dlsym( plug, "fini" ) ) != NULL ) { - (*fini)(); - } - (void) dlclose( plug ); - } + void (*fini)(void); + + if ( plug != PLUGIN_INVALID_HANDLE ) { + if ( ( fini = dlsym( plug, "fini" ) ) != NULL ) { + (*fini)(); + } + (void) dlclose( plug ); + } } void * plugin_get_sym( plugin_handle_t plug, const char *name ) { - if ( plug != PLUGIN_INVALID_HANDLE ) - return dlsym( plug, name ); - else - return NULL; + if ( plug != PLUGIN_INVALID_HANDLE ) + return dlsym( plug, name ); + else + return NULL; } const char * plugin_get_name( plugin_handle_t plug ) { - if ( plug != PLUGIN_INVALID_HANDLE ) - return (const char *) dlsym( plug, PLUGIN_NAME ); - else - return NULL; + if ( plug != PLUGIN_INVALID_HANDLE ) + return (const char *) dlsym( plug, PLUGIN_NAME ); + else + return NULL; } const char * plugin_get_type( plugin_handle_t plug ) { - if ( plug != PLUGIN_INVALID_HANDLE ) - return (const char *) dlsym( plug, PLUGIN_TYPE ); - else - return NULL; + if ( plug != PLUGIN_INVALID_HANDLE ) + return (const char *) dlsym( plug, PLUGIN_TYPE ); + else + return NULL; } uint32_t plugin_get_version( plugin_handle_t plug ) { - uint32_t *ptr; + uint32_t *ptr; - if ( plug == PLUGIN_INVALID_HANDLE ) return 0; - ptr = (uint32_t *) dlsym( plug, PLUGIN_VERSION ); - return ptr ? *ptr : 0; + if ( plug == PLUGIN_INVALID_HANDLE ) return 0; + ptr = (uint32_t *) dlsym( plug, PLUGIN_VERSION ); + return ptr ? *ptr : 0; } int plugin_get_syms( plugin_handle_t plug, - int n_syms, - const char *names[], - void *ptrs[] ) + int n_syms, + const char *names[], + void *ptrs[] ) { - int i, count; + int i, count; - count = 0; - for ( i = 0; i < n_syms; ++i ) { - ptrs[ i ] = dlsym( plug, names[ i ] ); - if ( ptrs[ i ] ) + count = 0; + for ( i = 0; i < n_syms; ++i ) { + ptrs[ i ] = dlsym( plug, names[ i ] ); + if ( ptrs[ i ] ) ++count; else debug3("Couldn't find sym '%s' in the plugin", names[ i ]); } - return count; + return count; }