Squid Web Cache master
Loading...
Searching...
No Matches
LoadableModule.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9#include "squid.h"
10#include "base/TextException.h"
11#include "libltdl/ltdl.h" /* generated file */
12#include "LoadableModule.h"
13
14// Note: We must use preprocessor instead of C ifs because if dlopen()
15// is seen by the static linker, the linker will complain.
16
18 theName(aName)
19{
20 // Initialise preloaded symbol lookup table.
21 LTDL_SET_PRELOADED_SYMBOLS();
22 if (lt_dlinit() != 0)
23 throw TexcHere("internal error: cannot initialize libtool module loader");
24}
25
27{
28 if (loaded())
29 unload();
30 assert(lt_dlexit() == 0); // XXX: replace with a warning
31}
32
33bool
35{
36 return theHandle != nullptr;
37}
38
39void
41{
42 if (loaded())
43 throw TexcHere("internal error: reusing LoadableModule object");
44
46
47 if (!loaded())
48 throw TexcHere(errorMsg());
49}
50
51void
53{
54 if (!loaded())
55 throw TexcHere("internal error: unloading not loaded module");
56
57 if (!closeModule())
58 throw TexcHere(errorMsg());
59
60 theHandle = nullptr;
61}
62
63void *
65{
66 return lt_dlopen(theName.c_str());
67}
68
69bool
71{
72 // we cast to avoid including ltdl.h in LoadableModule.h
73 return lt_dlclose(static_cast<lt_dlhandle>(theHandle)) == 0;
74}
75
76const char *
78{
79 return lt_dlerror();
80}
81
#define TexcHere(msg)
legacy convenience macro; it is not difficult to type Here() now
#define assert(EX)
Definition assert.h:17
const char * errorMsg()
LoadableModule(const SBuf &aName)
bool loaded() const
Definition SBuf.h:94
const char * c_str()
Definition SBuf.cc:516