Chris@0: Chris@0: /** Chris@1: * Plugin Load Checker Helper Chris@0: * Chris@1: * This program accepts the name of a descriptor function as its only Chris@1: * command-line argument. It then reads a list of plugin library paths Chris@1: * from stdin, one per line. For each path read, it attempts to load Chris@1: * that library and retrieve the named descriptor function, printing a Chris@1: * line to stdout reporting whether this was successful or not and Chris@1: * then flushing stdout. The output line format is described Chris@1: * below. The program exits with code 0 if all libraries were loaded Chris@1: * successfully and non-zero otherwise. Chris@0: * Chris@0: * Note that library paths must be ready to pass to dlopen() or Chris@0: * equivalent; this usually means they should be absolute paths. Chris@0: * Chris@0: * Output line for successful load of library libname.so: Chris@0: * SUCCESS|/path/to/libname.so| Chris@0: * Chris@0: * Output line for failed load of library libname.so: Chris@0: * FAILURE|/path/to/libname.so|Reason for failure if available Chris@0: * Chris@0: * Note that sometimes plugins will crash completely on load, bringing Chris@0: * down this program with them. If the program exits before all listed Chris@0: * plugins have been checked, this means that the plugin following the Chris@0: * last reported one has crashed. Typically the caller may want to run Chris@0: * it again, omitting that plugin. Chris@0: */ Chris@0: Chris@0: #ifdef _WIN32 Chris@0: #include Chris@0: #include Chris@0: #define DLOPEN(a,b) LoadLibrary((a).toStdWString().c_str()) Chris@0: #define DLSYM(a,b) GetProcAddress((HINSTANCE)(a),(b)) Chris@0: #define DLCLOSE(a) (!FreeLibrary((HINSTANCE)(a))) Chris@0: #define DLERROR() "" Chris@0: #else Chris@0: #include Chris@0: #define DLOPEN(a,b) dlopen((a).c_str(),(b)) Chris@0: #define DLSYM(a,b) dlsym((a),(b).c_str()) Chris@0: #define DLCLOSE(a) dlclose((a)) Chris@0: #define DLERROR() dlerror() Chris@0: #endif Chris@0: Chris@0: #include Chris@0: #include Chris@0: Chris@0: using namespace std; Chris@0: Chris@0: string error() Chris@0: { Chris@0: string e = dlerror(); Chris@0: if (e == "") return "(unknown error)"; Chris@0: else return e; Chris@0: } Chris@0: Chris@1: string check(string soname, string descriptor) Chris@0: { Chris@0: void *handle = DLOPEN(soname, RTLD_NOW | RTLD_LOCAL); Chris@0: if (!handle) { Chris@0: return "Unable to open plugin library: " + error(); Chris@0: } Chris@0: Chris@0: void *fn = DLSYM(handle, descriptor); Chris@0: if (!fn) { Chris@0: return "Failed to find plugin descriptor " + descriptor + Chris@0: " in library: " + error(); Chris@0: } Chris@0: Chris@0: return ""; Chris@0: } Chris@0: Chris@0: int main(int argc, char **argv) Chris@0: { Chris@0: bool allGood = true; Chris@0: string soname; Chris@0: Chris@1: if (argc != 2) { Chris@1: cerr << "\nUsage:\n " << argv[0] << " descriptorname\n" Chris@1: "\nwhere descriptorname is the name of a plugin descriptor function to be sought\n" Chris@1: "in each library (e.g. vampGetPluginDescriptor for Vamp plugins). The list of\n" Chris@1: "candidate plugin library filenames is read from stdin.\n" << endl; Chris@1: return 2; Chris@1: } Chris@1: Chris@1: string descriptor = argv[1]; Chris@1: Chris@0: while (getline(cin, soname)) { Chris@1: string report = check(soname, descriptor); Chris@0: if (report != "") { Chris@0: cout << "FAILURE|" << soname << "|" << report << endl; Chris@0: allGood = false; Chris@0: } else { Chris@0: cout << "SUCCESS|" << soname << "|" << endl; Chris@0: } Chris@0: } Chris@0: Chris@0: return allGood ? 0 : 1; Chris@0: }