Chris@0: Chris@0: /** Chris@0: * Vamp Plugin Load Checker Chris@0: * Chris@0: * This program reads a list of Vamp plugin library paths from stdin, Chris@0: * one per line. For each path read, it attempts to load that library Chris@0: * and retrieve its descriptor function, printing a line to stdout Chris@0: * reporting whether this was successful or not and then flushing Chris@0: * stdout. The output line format is described below. The program Chris@0: * exits with code 0 if all libraries were loaded successfully and Chris@0: * 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@0: string check(string soname) 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: string descriptor = "vampGetPluginDescriptor"; //!!! todo: make an arg 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@0: while (getline(cin, soname)) { Chris@0: string report = check(soname); 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: }