const std::string& path) {
void *handle = dlopen(path.c_str(), RTLD_NOW);
if (handle == NULL) {
- derr << "Failed to load class: " << dlerror() << dendl;
+ std::cerr << "Failed to load class: " << name << " (" << path << "): "
+ << dlerror() << std::endl;
return;
}
- m_class_handles.push_back(handle);
+
+ // clear any existing error
+ dlerror();
// initialize
void (*cls_init)() = reinterpret_cast<void (*)()>(
- dlsym(handle, "__cls_init"));
- if (cls_init) {
+ dlsym(handle, "__cls_init"));
+
+ char* error = nullptr;
+ if ((error = dlerror()) != nullptr) {
+ std::cerr << "Error locating initializer: " << error << std::endl;
+ } else if (cls_init) {
+ m_class_handles.push_back(handle);
cls_init();
+ return;
}
+
+ std::cerr << "Class: " << name << " (" << path << ") missing initializer"
+ << std::endl;
+ dlclose(handle);
}
void TestClassHandler::open_all_classes() {
ceph_abort();;
}
+ std::set<std::string> names;
struct dirent *pde = nullptr;
while ((pde = ::readdir(dir))) {
std::string name(pde->d_name);
!boost::algorithm::ends_with(name, ".so")) {
continue;
}
+ names.insert(name);
+ }
+
+ for (auto& name : names) {
std::string class_name = name.substr(7, name.size() - 10);
open_class(class_name, CEPH_LIB + "/" + name);
}
int TestClassHandler::create(const std::string &name, cls_handle_t *handle) {
if (m_classes.find(name) != m_classes.end()) {
+ std::cerr << "Class " << name << " already exists" << std::endl;
return -EEXIST;
}
cls_method_handle_t *handle) {
Class *cls = reinterpret_cast<Class*>(hclass);
if (cls->methods.find(name) != cls->methods.end()) {
+ std::cerr << "Class method " << hclass << ":" << name << " already exists"
+ << std::endl;
return -EEXIST;
}
const std::string &method) {
Classes::iterator c_it = m_classes.find(cls);
if (c_it == m_classes.end()) {
+ std::cerr << "Failed to located class " << cls << std::endl;
return NULL;
}
SharedClass scls = c_it->second;
Methods::iterator m_it = scls->methods.find(method);
if (m_it == scls->methods.end()) {
+ std::cerr << "Failed to located class method" << cls << "." << method
+ << std::endl;
return NULL;
}
return m_it->second->class_call;