From 6576fb0dfe3a644d2c9ab9a92129d3c98ef34a18 Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 14 Sep 2009 06:57:51 +0000 Subject: [PATCH] report dlerror() --- direct/src/plugin/load_plugin.cxx | 16 +++++++++++----- direct/src/plugin/load_plugin.h | 3 ++- direct/src/plugin_npapi/ppInstance.cxx | 2 +- direct/src/plugin_standalone/panda3d.cxx | 2 +- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/direct/src/plugin/load_plugin.cxx b/direct/src/plugin/load_plugin.cxx index 76e6ea52ac..15b4b02b00 100755 --- a/direct/src/plugin/load_plugin.cxx +++ b/direct/src/plugin/load_plugin.cxx @@ -127,7 +127,8 @@ load_plugin(const string &p3d_plugin_filename, const string &contents_filename, const string &download_url, bool verify_contents, const string &platform, const string &log_directory, const string &log_basename, - bool trusted_environment) { + bool trusted_environment, + ostream &logfile) { string filename = p3d_plugin_filename; if (filename.empty()) { // Look for the plugin along the path. @@ -156,7 +157,7 @@ load_plugin(const string &p3d_plugin_filename, module = LoadLibrary(filename.c_str()); if (module == NULL) { // Couldn't load the DLL. - cerr << "Couldn't load " << filename << "\n"; + logfile << "Couldn't load " << filename << "\n"; return false; } @@ -168,7 +169,12 @@ load_plugin(const string &p3d_plugin_filename, module = dlopen(filename.c_str(), RTLD_LAZY | RTLD_LOCAL); if (module == NULL) { // Couldn't load the .so. - cerr << "Couldn't load " << filename << "\n"; + const char *message = dlerror(); + if (message == (char *)NULL) { + message = "No error"; + } + logfile << "Couldn't load " << filename << ": " << message << "\n"; + return false; } @@ -253,7 +259,7 @@ load_plugin(const string &p3d_plugin_filename, P3D_instance_feed_url_stream == NULL || P3D_instance_handle_event == NULL) { - cerr + logfile << "Some function pointers not found:" << "\nP3D_initialize = " << P3D_initialize << "\nP3D_finalize = " << P3D_finalize @@ -303,7 +309,7 @@ load_plugin(const string &p3d_plugin_filename, log_directory.c_str(), log_basename.c_str(), trusted_environment)) { // Oops, failure to initialize. - cerr << "Failed to initialize plugin (wrong API version?)\n"; + logfile << "Failed to initialize plugin (wrong API version?)\n"; unload_plugin(); return false; } diff --git a/direct/src/plugin/load_plugin.h b/direct/src/plugin/load_plugin.h index d7b4845668..9da12b83d1 100755 --- a/direct/src/plugin/load_plugin.h +++ b/direct/src/plugin/load_plugin.h @@ -63,7 +63,8 @@ load_plugin(const string &p3d_plugin_filename, const string &contents_filename, const string &download_url, bool verify_contents, const string &platform, const string &log_directory, const string &log_basename, - bool trusted_environment); + bool trusted_environment, + ostream &logfile); void unload_plugin(); bool is_plugin_loaded(); diff --git a/direct/src/plugin_npapi/ppInstance.cxx b/direct/src/plugin_npapi/ppInstance.cxx index c1cfa79b6e..7d7a96b1df 100644 --- a/direct/src/plugin_npapi/ppInstance.cxx +++ b/direct/src/plugin_npapi/ppInstance.cxx @@ -951,7 +951,7 @@ do_load_plugin() { #endif // P3D_PLUGIN_P3D_PLUGIN nout << "Attempting to load core API from " << pathname << "\n"; - if (!load_plugin(pathname, "", "", true, "", "", "", false)) { + if (!load_plugin(pathname, "", "", true, "", "", "", false, nout)) { nout << "Unable to launch core API in " << pathname << "\n"; return; } diff --git a/direct/src/plugin_standalone/panda3d.cxx b/direct/src/plugin_standalone/panda3d.cxx index 2ff2812bde..2e24429a05 100644 --- a/direct/src/plugin_standalone/panda3d.cxx +++ b/direct/src/plugin_standalone/panda3d.cxx @@ -507,7 +507,7 @@ get_core_api(const Filename &contents_filename, const string &download_url, if (!load_plugin(pathname, contents_filename.to_os_specific(), download_url, verify_contents, this_platform, _log_dirname, - _log_basename, true)) { + _log_basename, true, cerr)) { cerr << "Unable to launch core API in " << pathname << "\n" << flush; return false; }