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
17
LoadableModule::LoadableModule
(
const
SBuf
&aName):
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
26
LoadableModule::~LoadableModule
()
27
{
28
if
(
loaded
())
29
unload
();
30
assert
(lt_dlexit() == 0);
// XXX: replace with a warning
31
}
32
33
bool
34
LoadableModule::loaded
()
const
35
{
36
return
theHandle
!=
nullptr
;
37
}
38
39
void
40
LoadableModule::load
()
41
{
42
if
(
loaded
())
43
throw
TexcHere
(
"internal error: reusing LoadableModule object"
);
44
45
theHandle
=
openModule
();
46
47
if
(!
loaded
())
48
throw
TexcHere
(
errorMsg
());
49
}
50
51
void
52
LoadableModule::unload
()
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
63
void
*
64
LoadableModule::openModule
()
65
{
66
return
lt_dlopen(
theName
.
c_str
());
67
}
68
69
bool
70
LoadableModule::closeModule
()
71
{
72
// we cast to avoid including ltdl.h in LoadableModule.h
73
return
lt_dlclose(
static_cast<
lt_dlhandle
>
(
theHandle
)) == 0;
74
}
75
76
const
char
*
77
LoadableModule::errorMsg
()
78
{
79
return
lt_dlerror();
80
}
81
LoadableModule.h
TextException.h
TexcHere
#define TexcHere(msg)
legacy convenience macro; it is not difficult to type Here() now
Definition
TextException.h:63
assert
#define assert(EX)
Definition
assert.h:17
LoadableModule::unload
void unload()
Definition
LoadableModule.cc:52
LoadableModule::theHandle
void * theHandle
Definition
LoadableModule.h:31
LoadableModule::load
void load()
Definition
LoadableModule.cc:40
LoadableModule::closeModule
bool closeModule()
Definition
LoadableModule.cc:70
LoadableModule::errorMsg
const char * errorMsg()
Definition
LoadableModule.cc:77
LoadableModule::LoadableModule
LoadableModule(const SBuf &aName)
Definition
LoadableModule.cc:17
LoadableModule::~LoadableModule
~LoadableModule()
Definition
LoadableModule.cc:26
LoadableModule::theName
SBuf theName
Definition
LoadableModule.h:29
LoadableModule::openModule
void * openModule()
Definition
LoadableModule.cc:64
LoadableModule::loaded
bool loaded() const
Definition
LoadableModule.cc:34
SBuf
Definition
SBuf.h:94
SBuf::c_str
const char * c_str()
Definition
SBuf.cc:516
squid.h
squid
src
LoadableModule.cc
Generated by
1.9.8