/* applets */ static int _auth(void) { int ret = 0; const char path[] = "../src/auth"; #ifdef __APPLE__ const char ext[] = ".dylib"; #else const char ext[] = ".so"; #endif DIR * dir; struct dirent * de; size_t len; char * s; void * p; LockerAuthDefinition * lad; if((dir = opendir(path)) == NULL) return -_perror(path, 1); while((de = readdir(dir)) != NULL) { if((len = strlen(de->d_name)) < sizeof(ext)) continue; if(strcmp(&de->d_name[len - sizeof(ext) + 1], ext) != 0) continue; if((s = malloc(sizeof(path) + len + 1)) == NULL) { ret += _perror(de->d_name, 1); continue; } snprintf(s, sizeof(path) + len + 1, "%s/%s", path, de->d_name); if((p = dlopen(s, RTLD_LAZY)) == NULL) { ret += _dlerror(s, 1); free(s); continue; } if((lad = dlsym(p, "plugin")) == NULL) ret += _dlerror(s, 1); else { if(lad->icon == NULL) ret += _error(s, "No icon defined", 1); else printf("\n%s: %s (%s)\n%s\n", de->d_name, lad->name, lad->icon, (lad->description != NULL) ? lad->description : "(no description)"); if(lad->get_widget == NULL) ret += _error(s, "No widget available", 1); if(lad->action == NULL) ret += _error(s, "No action handler", 1); } free(s); dlclose(p); } closedir(dir); return ret; }
/* plugins */ static int _plugins(void) { int ret = 0; const char path[] = "../src/plugins"; /* FIXME broken with OBJDIR */ #ifdef __APPLE__ const char ext[] = ".dylib"; #else const char ext[] = ".so"; #endif DIR * dir; struct dirent * de; size_t len; char * s; void * p; BrowserPluginDefinition * bpd; if((dir = opendir(path)) == NULL) return -_perror(path, 1); while((de = readdir(dir)) != NULL) { if((len = strlen(de->d_name)) < sizeof(ext)) continue; if(strcmp(&de->d_name[len - sizeof(ext) + 1], ext) != 0) continue; if((s = malloc(sizeof(path) + len + 1)) == NULL) { ret += _perror(de->d_name, 1); continue; } snprintf(s, sizeof(path) + len + 1, "%s/%s", path, de->d_name); if((p = dlopen(s, RTLD_LAZY)) == NULL) { ret += _dlerror(s, 1); free(s); continue; } if((bpd = dlsym(p, "plugin")) == NULL) ret += _dlerror(s, 1); else if(bpd->icon == NULL) ret += _error(s, "No icon defined", 1); else printf("\n%s: %s (%s)\n%s\n", de->d_name, bpd->name, bpd->icon, (bpd->description != NULL) ? bpd->description : "(no description)"); free(s); dlclose(p); } closedir(dir); return ret; }
int plugin_peek( const char *fq_path, char *plugin_type, const size_t type_len, uint32_t *plugin_version ) { plugin_handle_t plug; char *type; uint32_t *version; plug = dlopen( fq_path, RTLD_LAZY ); if ( plug == NULL ) { debug3( "plugin_peek: dlopen(%s): %s", fq_path, _dlerror() ); return SLURM_ERROR; } if ( ( type = dlsym( plug, PLUGIN_TYPE ) ) != NULL ) { if ( plugin_type != NULL ) { strlcpy(plugin_type, type, type_len); } } else { dlclose( plug ); /* could be vestigial library, don't treat as an error */ verbose( "%s: not a Slurm plugin", fq_path ); return SLURM_ERROR; } version = (uint32_t *) dlsym(plug, PLUGIN_VERSION); if (!version) { verbose("%s: plugin_version symbol not defined", fq_path); } else if ((*version != SLURM_VERSION_NUMBER) && xstrcmp(type,"spank")){ /* NOTE: We could alternatly test just the MAJOR.MINOR values */ int plugin_major, plugin_minor, plugin_micro; plugin_major = SLURM_VERSION_MAJOR(*version); plugin_minor = SLURM_VERSION_MINOR(*version); plugin_micro = SLURM_VERSION_MICRO(*version); dlclose(plug); info("%s: Incompatible Slurm plugin version (%d.%d.%d)", fq_path, plugin_major, plugin_minor, plugin_micro); return SLURM_ERROR; } dlclose( plug ); return SLURM_SUCCESS; }
plugin_err_t plugin_load_from_file(plugin_handle_t *p, const char *fq_path) { plugin_handle_t plug; int (*init)(void); uint32_t *version; char *type = NULL; *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. * * Use RTLD_LAZY to allow plugins to use symbols that may be * defined in only one slurm entity (e.g. srun and not slurmd), * when the use of that symbol is restricted to within the * 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 EPLUGIN_DLOPEN_FAILED; } /* Now see if our required symbols are defined. */ if ((dlsym(plug, PLUGIN_NAME) == NULL) || ((type = dlsym(plug, PLUGIN_TYPE)) == NULL)) { dlclose(plug); return EPLUGIN_MISSING_NAME; } version = (uint32_t *) dlsym(plug, PLUGIN_VERSION); if (!version) { verbose("%s: plugin_version symbol not defined", fq_path); } else if ((*version != SLURM_VERSION_NUMBER) && xstrcmp(type,"spank")){ /* NOTE: We could alternatly test just the MAJOR.MINOR values */ int plugin_major, plugin_minor, plugin_micro; plugin_major = SLURM_VERSION_MAJOR(*version); plugin_minor = SLURM_VERSION_MINOR(*version); plugin_micro = SLURM_VERSION_MICRO(*version); dlclose(plug); info("%s: Incompatible Slurm plugin version (%d.%d.%d)", fq_path, plugin_major, plugin_minor, plugin_micro); return EPLUGIN_BAD_VERSION; } /* * 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) { dlclose(plug); return EPLUGIN_INIT_FAILED; } } *p = plug; return EPLUGIN_SUCCESS; }
const char *dlerror(void) { return _dlerror(); }