Skip to content
Snippets Groups Projects
Commit 8cfcb320 authored by Moe Jette's avatar Moe Jette
Browse files

Return a plugin_err_t from plugin_load_from_file in order to allow

callers to better handle and report errors from this function. Also
update all callers to use new calling style. Update call site in
plugstack.c to report error using plugin_strerror(). Other callers
ignore errors as before.
parent 2bc313e5
No related branches found
No related tags found
No related merge requests found
...@@ -140,12 +140,25 @@ plugin_peek( const char *fq_path, ...@@ -140,12 +140,25 @@ plugin_peek( const char *fq_path,
return SLURM_SUCCESS; return SLURM_SUCCESS;
} }
plugin_handle_t plugin_err_t
plugin_load_from_file(const char *fq_path) plugin_load_from_file(plugin_handle_t *p, const char *fq_path)
{ {
struct stat st;
plugin_handle_t plug; plugin_handle_t plug;
int (*init)(void); int (*init)(void);
*p = PLUGIN_INVALID_HANDLE;
/*
* Check for file existence and access permissions
*/
if (access(fq_path, R_OK) < 0) {
if (errno == ENOENT)
return EPLUGIN_NOTFOUND;
else
return EPLUGIN_ACCESS_ERROR;
}
/* /*
* Try to open the shared object. * Try to open the shared object.
* *
...@@ -161,16 +174,15 @@ plugin_load_from_file(const char *fq_path) ...@@ -161,16 +174,15 @@ plugin_load_from_file(const char *fq_path)
error("plugin_load_from_file: dlopen(%s): %s", error("plugin_load_from_file: dlopen(%s): %s",
fq_path, fq_path,
_dlerror()); _dlerror());
return PLUGIN_INVALID_HANDLE; return EPLUGIN_DLOPEN_FAILED;
} }
/* Now see if our required symbols are defined. */ /* Now see if our required symbols are defined. */
if ((dlsym(plug, PLUGIN_NAME) == NULL) || if ((dlsym(plug, PLUGIN_NAME) == NULL) ||
(dlsym(plug, PLUGIN_TYPE) == NULL) || (dlsym(plug, PLUGIN_TYPE) == NULL) ||
(dlsym(plug, PLUGIN_VERSION) == NULL)) { (dlsym(plug, PLUGIN_VERSION) == NULL)) {
debug("plugin_load_from_file: invalid symbol"); dlclose (plug);
/* slurm_seterrno( SLURM_PLUGIN_SYMBOLS ); */ return EPLUGIN_MISSING_SYMBOL;
return PLUGIN_INVALID_HANDLE;
} }
/* /*
...@@ -179,14 +191,13 @@ plugin_load_from_file(const char *fq_path) ...@@ -179,14 +191,13 @@ plugin_load_from_file(const char *fq_path)
*/ */
if ((init = dlsym(plug, "init")) != NULL) { if ((init = dlsym(plug, "init")) != NULL) {
if ((*init)() != 0) { if ((*init)() != 0) {
error("plugin_load_from_file(%s): init() returned SLURM_ERROR", dlclose(plug);
fq_path); return EPLUGIN_INIT_FAILED;
(void) dlclose(plug);
return PLUGIN_INVALID_HANDLE;
} }
} }
return plug; *p = plug;
return EPLUGIN_SUCCESS;
} }
plugin_handle_t plugin_handle_t
...@@ -230,7 +241,7 @@ plugin_load_and_link(const char *type_name, int n_syms, ...@@ -230,7 +241,7 @@ plugin_load_and_link(const char *type_name, int n_syms,
debug4("No Good."); debug4("No Good.");
xfree(file_name); xfree(file_name);
} else { } else {
plug = plugin_load_from_file(file_name); plugin_load_from_file(&plug, file_name);
xfree(file_name); xfree(file_name);
if (plugin_get_syms(plug, n_syms, names, ptrs) >= if (plugin_get_syms(plug, n_syms, names, ptrs) >=
n_syms) { n_syms) {
......
...@@ -119,15 +119,17 @@ int plugin_peek( const char *fq_path, ...@@ -119,15 +119,17 @@ int plugin_peek( const char *fq_path,
/* /*
* Simplest way to get a plugin -- load it from a file. * Simplest way to get a plugin -- load it from a file.
* *
* pph - Pointer to a plugin handle
* fq_path - the fully-qualified pathname (i.e., from root) to * fq_path - the fully-qualified pathname (i.e., from root) to
* the plugin to load. * the plugin to load.
* *
* Returns a handle if successful, or NULL if not. * Returns EPLUGIN_SUCCESS on success, and an plugin_err_t error
* code on failure.
* *
* The plugin's initialization code will be executed prior * The plugin's initialization code will be executed prior
* to this function's return. * to this function's return.
*/ */
plugin_handle_t plugin_load_from_file( const char *fq_path ); plugin_err_t plugin_load_from_file(plugin_handle_t *pph, const char *fq_path);
/* /*
* load plugin and link hooks. * load plugin and link hooks.
......
...@@ -548,7 +548,7 @@ plugrack_load_all( plugrack_t rack ) ...@@ -548,7 +548,7 @@ plugrack_load_all( plugrack_t rack )
it = list_iterator_create( rack->entries ); it = list_iterator_create( rack->entries );
while ( ( e = list_next( it ) ) != NULL ) { while ( ( e = list_next( it ) ) != NULL ) {
if ( e->plug == PLUGIN_INVALID_HANDLE ) { if ( e->plug == PLUGIN_INVALID_HANDLE ) {
e->plug = plugin_load_from_file( e->fq_path ); plugin_load_from_file(&e->plug, e->fq_path);
} }
} }
...@@ -585,7 +585,7 @@ plugrack_use_by_type( plugrack_t rack, ...@@ -585,7 +585,7 @@ plugrack_use_by_type( plugrack_t rack,
/* See if plugin is loaded. */ /* See if plugin is loaded. */
if ( e->plug == PLUGIN_INVALID_HANDLE ) if ( e->plug == PLUGIN_INVALID_HANDLE )
e->plug = plugin_load_from_file( e->fq_path ); plugin_load_from_file(&e->plug, e->fq_path);
/* If load was successful, increment the reference count. */ /* If load was successful, increment the reference count. */
if ( e->plug == PLUGIN_INVALID_HANDLE ) if ( e->plug == PLUGIN_INVALID_HANDLE )
......
...@@ -260,10 +260,13 @@ static struct spank_plugin *_spank_plugin_create(char *path, int ac, ...@@ -260,10 +260,13 @@ static struct spank_plugin *_spank_plugin_create(char *path, int ac,
{ {
struct spank_plugin *plugin; struct spank_plugin *plugin;
plugin_handle_t p; plugin_handle_t p;
plugin_err_t e;
struct spank_plugin_operations ops; struct spank_plugin_operations ops;
if (!(p = plugin_load_from_file(path))) if ((e = plugin_load_from_file(&p, path)) != EPLUGIN_SUCCESS) {
error ("spank: %s: %s\n", path, plugin_strerror(e));
return NULL; return NULL;
}
if (plugin_get_syms(p, n_spank_syms, spank_syms, (void **)&ops) == 0) { if (plugin_get_syms(p, n_spank_syms, spank_syms, (void **)&ops) == 0) {
error("spank: \"%s\" exports 0 symbols\n", path); error("spank: \"%s\" exports 0 symbols\n", path);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment