/*********************************************************************** * module safe load implementation **********************************************************************/ Pothos::PluginModule Pothos::PluginModule::safeLoad(const std::string &path) { if (previousLoadWasSuccessful(path)) return PluginModule(path); const int success = 200; //create args Poco::Process::Args args; args.push_back("--load-module"); args.push_back("\""+path+"\""); //add quotes for paths with spaces args.push_back("--success-code"); args.push_back(std::to_string(success)); //launch Poco::Pipe outPipe, errPipe; Poco::Process::Env env; Poco::ProcessHandle ph(Poco::Process::launch( Pothos::System::getPothosUtilExecutablePath(), args, nullptr, &outPipe, &errPipe, env)); //close pipes to not overfill and backup outPipe.close(); errPipe.close(); //wait, check error condition, and throw if (ph.wait() != success) { throw Pothos::PluginModuleError("Pothos::PluginModule("+path+")", "failed safe load"); } //it was safe, load into this process now markCurrentLoadSuccessful(path); return PluginModule(path); }
Pothos::PluginModule::PluginModule(const std::string &path): _impl(new Impl()) { _impl->path = path; poco_information(Poco::Logger::get("Pothos.PluginModule.load"), path); try { std::lock_guard<std::mutex> lock(getModuleMutex()); registrySetActiveModuleLoading(*this); ErrorMessageDisableGuard emdg; _impl->sharedLibrary.load(path); registrySetActiveModuleLoading(PluginModule()); _impl->pluginPaths = ::getPluginPaths(*this); } catch(const Poco::LibraryLoadException &ex) { throw PluginModuleError("Pothos::PluginModule("+path+")", ex.displayText()); } }