aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2008-11-15 22:31:48 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2008-11-15 22:32:47 +0000
commit0007fc154be85f50a3d0f653cee66632b59e8652 (patch)
treeb5d5dde988a81ea1ccbd71f7277335ba2ecaf619
parent975390470d5f3635b1e2a4885af390cd3f405d17 (diff)
downloadpaludis-0007fc154be85f50a3d0f653cee66632b59e8652.tar.gz
paludis-0007fc154be85f50a3d0f653cee66632b59e8652.tar.xz
Don't segfault if one but not both of GLSAs and metadata.xml is enabled.
-rw-r--r--paludis/repositories/e/glsa.cc2
-rw-r--r--paludis/repositories/e/metadata_xml.cc2
-rw-r--r--paludis/repositories/e/xml_things_handle.cc101
-rw-r--r--paludis/repositories/e/xml_things_handle.hh9
4 files changed, 52 insertions, 62 deletions
diff --git a/paludis/repositories/e/glsa.cc b/paludis/repositories/e/glsa.cc
index fb425b8..e40b6e8 100644
--- a/paludis/repositories/e/glsa.cc
+++ b/paludis/repositories/e/glsa.cc
@@ -186,7 +186,7 @@ GLSA::title() const
std::tr1::shared_ptr<GLSA>
GLSA::create_from_xml_file(const std::string & filename)
{
- if (! erepository::XMLThingsHandle::get_instance()->available())
+ if (! erepository::XMLThingsHandle::get_instance()->create_glsa_from_xml_file())
{
#ifdef ENABLE_GLSA
throw NotAvailableError("Cannot create GLSA from XML file '" + filename + "' because your XML libraries are unusable");
diff --git a/paludis/repositories/e/metadata_xml.cc b/paludis/repositories/e/metadata_xml.cc
index f69d4a1..fd60056 100644
--- a/paludis/repositories/e/metadata_xml.cc
+++ b/paludis/repositories/e/metadata_xml.cc
@@ -73,7 +73,7 @@ MetadataXMLPool::metadata_if_exists(const FSEntry & f) const
{
try
{
- if (XMLThingsHandle::get_instance()->available())
+ if (XMLThingsHandle::get_instance()->create_metadata_xml_from_xml_file())
metadata_xml = XMLThingsHandle::get_instance()->create_metadata_xml_from_xml_file()(f);
}
catch (const Exception & e)
diff --git a/paludis/repositories/e/xml_things_handle.cc b/paludis/repositories/e/xml_things_handle.cc
index b8db73f..af64947 100644
--- a/paludis/repositories/e/xml_things_handle.cc
+++ b/paludis/repositories/e/xml_things_handle.cc
@@ -39,85 +39,78 @@ namespace paludis
{
void * handle;
- bool available;
- std::tr1::shared_ptr<GLSA> (* create_glsa_from_xml_file) (const std::string &);
- std::tr1::shared_ptr<MetadataXML> (* create_metadata_xml_from_xml_file) (const FSEntry &);
- void (* init) ();
- void (* cleanup) ();
+ typedef void (* InitPtr) ();
+ typedef void (* CleanupPtr) ();
+
+ XMLThingsHandle::CreateGLSAFromXMLFilePtr create_glsa_from_xml_file;
+ XMLThingsHandle::CreateMetadataXMLFromXMLFilePtr create_metadata_xml_from_xml_file;
+ InitPtr init;
+ CleanupPtr cleanup;
Implementation() :
handle(0),
- available(false),
create_glsa_from_xml_file(0),
create_metadata_xml_from_xml_file(0),
init(0),
cleanup(0)
{
#if defined(ENABLE_GLSA) || defined(ENABLE_METADATA_XML)
- available = true;
-
handle = ::dlopen(("libpaludiserepositoryxmlthings_" + stringify(PALUDIS_PC_SLOT) + ".so").c_str(), RTLD_NOW | RTLD_GLOBAL);
if (! handle)
{
Log::get_instance()->message("e.xml_things.dlopen_failed", ll_warning, lc_context) << "Got error '"
<< ::dlerror() << "' from dlopen for XML things";
- available = false;
+ return;
}
- if (available)
+ InitPtr i(STUPID_CAST(InitPtr, ::dlsym(handle, "paludis_xml_things_init")));
+ if (! i)
{
- init = STUPID_CAST(void (*)(), ::dlsym(handle, "paludis_xml_things_init"));
- if (! init)
- {
- Log::get_instance()->message("e.xml_things.dlsym_failed", ll_warning, lc_context) << "Got error '"
- << ::dlerror() << "' from dlsym for init";
- available = false;
- }
+ Log::get_instance()->message("e.xml_things.dlsym_failed", ll_warning, lc_context) << "Got error '"
+ << ::dlerror() << "' from dlsym for init";
+ return;
}
- if (available)
+ CleanupPtr c(STUPID_CAST(CleanupPtr, ::dlsym(handle, "paludis_xml_things_cleanup")));
+ if (! c)
{
- cleanup = STUPID_CAST(void (*)(), ::dlsym(handle, "paludis_xml_things_cleanup"));
- if (! cleanup)
- {
- Log::get_instance()->message("e.xml_things.dlsym_failed", ll_warning, lc_context) << "Got error '"
- << ::dlerror() << "' from dlsym for cleanup";
- available = false;
- }
+ Log::get_instance()->message("e.xml_things.dlsym_failed", ll_warning, lc_context) << "Got error '"
+ << ::dlerror() << "' from dlsym for cleanup";
+ return;
}
# ifdef ENABLE_GLSA
- if (available)
+ XMLThingsHandle::CreateGLSAFromXMLFilePtr g(STUPID_CAST(XMLThingsHandle::CreateGLSAFromXMLFilePtr,
+ ::dlsym(handle, "paludis_xml_things_create_glsa_from_xml_file")));
+ if (! g)
{
- create_glsa_from_xml_file = STUPID_CAST(std::tr1::shared_ptr<GLSA> (*)(const std::string &),
- ::dlsym(handle, "paludis_xml_things_create_glsa_from_xml_file"));
- if (! create_glsa_from_xml_file)
- {
- Log::get_instance()->message("e.xml_things.dlsym_failed", ll_warning, lc_context) << "Got error '"
- << ::dlerror() << "' from dlsym for GLSA things";
- available = false;
- }
+ Log::get_instance()->message("e.xml_things.dlsym_failed", ll_warning, lc_context) << "Got error '"
+ << ::dlerror() << "' from dlsym for GLSA things";
+ return;
}
# endif
# ifdef ENABLE_METADATA_XML
- if (available)
+ XMLThingsHandle::CreateMetadataXMLFromXMLFilePtr x(STUPID_CAST(XMLThingsHandle::CreateMetadataXMLFromXMLFilePtr,
+ ::dlsym(handle, "paludis_xml_things_create_metadata_xml_from_xml_file")));
+ if (! x)
{
- create_metadata_xml_from_xml_file = STUPID_CAST(std::tr1::shared_ptr<MetadataXML> (*)(const FSEntry &),
- ::dlsym(handle, "paludis_xml_things_create_metadata_xml_from_xml_file"));
- if (! create_metadata_xml_from_xml_file)
- {
- Log::get_instance()->message("e.xml_things.dlsym_failed", ll_warning, lc_context) << "Got error '"
- << ::dlerror() << "' from dlsym for metadata.xml things";
- available = false;
- }
+ Log::get_instance()->message("e.xml_things.dlsym_failed", ll_warning, lc_context) << "Got error '"
+ << ::dlerror() << "' from dlsym for metadata.xml things";
+ return;
}
# endif
- if (available)
- {
- init();
- }
+ init = i;
+ cleanup = c;
+# ifdef ENABLE_GLSA
+ create_glsa_from_xml_file = g;
+# endif
+# ifdef ENABLE_METADATA_XML
+ create_metadata_xml_from_xml_file = x;
+# endif
+
+ init();
#endif
}
};
@@ -138,20 +131,14 @@ XMLThingsHandle::~XMLThingsHandle()
// ::dlclose(_imp->handle);
}
-bool
-XMLThingsHandle::available() const
-{
- return _imp->available;
-}
-
-std::tr1::shared_ptr<GLSA>
-(* XMLThingsHandle::create_glsa_from_xml_file() const) (const std::string &)
+XMLThingsHandle::CreateGLSAFromXMLFilePtr
+XMLThingsHandle::create_glsa_from_xml_file() const
{
return _imp->create_glsa_from_xml_file;
}
-std::tr1::shared_ptr<MetadataXML>
-(* XMLThingsHandle::create_metadata_xml_from_xml_file() const) (const FSEntry &)
+XMLThingsHandle::CreateMetadataXMLFromXMLFilePtr
+XMLThingsHandle::create_metadata_xml_from_xml_file() const
{
return _imp->create_metadata_xml_from_xml_file;
}
diff --git a/paludis/repositories/e/xml_things_handle.hh b/paludis/repositories/e/xml_things_handle.hh
index 35ab7aa..5d267f9 100644
--- a/paludis/repositories/e/xml_things_handle.hh
+++ b/paludis/repositories/e/xml_things_handle.hh
@@ -41,10 +41,13 @@ namespace paludis
~XMLThingsHandle();
public:
- bool available() const PALUDIS_ATTRIBUTE((warn_unused_result));
+ typedef std::tr1::shared_ptr<GLSA> (* CreateGLSAFromXMLFilePtr) (const std::string &);
+ typedef std::tr1::shared_ptr<MetadataXML> (* CreateMetadataXMLFromXMLFilePtr) (const FSEntry &);
- std::tr1::shared_ptr<GLSA> (* create_glsa_from_xml_file() const) (const std::string &);
- std::tr1::shared_ptr<MetadataXML> (* create_metadata_xml_from_xml_file() const) (const FSEntry &);
+ CreateGLSAFromXMLFilePtr create_glsa_from_xml_file() const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
+ CreateMetadataXMLFromXMLFilePtr create_metadata_xml_from_xml_file() const
+ PALUDIS_ATTRIBUTE((warn_unused_result));
};
}