]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/LoadableModule.cc
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
11 /* The original code has this constant ./configure-able.
12 * The "#else" branches use raw dlopen interface and have not been tested.
13 * We can remove that code if we are going to rely on libtool's ltdl in
14 * all environments. */
15 #define XSTD_USE_LIBLTDL 1
18 #include "libltdl/ltdl.h" /* generated file */
23 #include "base/TextException.h"
24 #include "LoadableModule.h"
26 // Note: We must use preprocessor instead of C ifs because if dlopen()
27 // is seen by the static linker, the linker will complain.
29 LoadableModule::LoadableModule(const String
&aName
): theName(aName
), theHandle(0)
32 // Initialise preloaded symbol lookup table.
33 LTDL_SET_PRELOADED_SYMBOLS();
35 throw TexcHere("internal error: cannot initialize libtool module loader");
39 LoadableModule::~LoadableModule()
44 assert(lt_dlexit() == 0); // XXX: replace with a warning
48 bool LoadableModule::loaded() const
50 return theHandle
!= 0;
53 void LoadableModule::load(int mode
)
56 throw TexcHere("internal error: reusing LoadableModule object");
58 theHandle
= openModule(mode
);
61 throw TexcHere(errorMsg());
64 void LoadableModule::unload()
67 throw TexcHere("internal error: unloading not loaded module");
70 throw TexcHere(errorMsg());
75 void *LoadableModule::openModule(int mode
)
78 return lt_dlopen(theName
.termedBuf());
80 return dlopen(theName
.termedBuf(),
81 mode
== lmNow
? RTLD_NOW
: RTLD_LAZY
);
85 bool LoadableModule::closeModule()
88 // we cast to avoid including ltdl.h in LoadableModule.h
89 return lt_dlclose(static_cast<lt_dlhandle
>(theHandle
)) == 0;
91 return dlclose(theHandle
) == 0;
95 const char *LoadableModule::errorMsg()