LoadableModule.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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
17LoadableModule::LoadableModule(const String &aName): theName(aName), theHandle(nullptr)
18{
19 // Initialise preloaded symbol lookup table.
20 LTDL_SET_PRELOADED_SYMBOLS();
21 if (lt_dlinit() != 0)
22 throw TexcHere("internal error: cannot initialize libtool module loader");
23}
24
26{
27 if (loaded())
28 unload();
29 assert(lt_dlexit() == 0); // XXX: replace with a warning
30}
31
32bool
34{
35 return theHandle != nullptr;
36}
37
38void
40{
41 if (loaded())
42 throw TexcHere("internal error: reusing LoadableModule object");
43
45
46 if (!loaded())
47 throw TexcHere(errorMsg());
48}
49
50void
52{
53 if (!loaded())
54 throw TexcHere("internal error: unloading not loaded module");
55
56 if (!closeModule())
57 throw TexcHere(errorMsg());
58
59 theHandle = nullptr;
60}
61
62void *
64{
65 return lt_dlopen(theName.termedBuf());
66}
67
68bool
70{
71 // we cast to avoid including ltdl.h in LoadableModule.h
72 return lt_dlclose(static_cast<lt_dlhandle>(theHandle)) == 0;
73}
74
75const char *
77{
78 return lt_dlerror();
79}
80
#define TexcHere(msg)
legacy convenience macro; it is not difficult to type Here() now
Definition: TextException.h:59
#define assert(EX)
Definition: assert.h:19
const char * errorMsg()
LoadableModule(const String &aName)
void * openModule()
bool loaded() const
char const * termedBuf() const
Definition: SquidString.h:92

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors