Thanks to visit codestin.com
Credit goes to doxygen.postgresql.org

PostgreSQL Source Code git master
dfmgr.c File Reference
#include "postgres.h"
#include <sys/stat.h>
#include <dlfcn.h>
#include "fmgr.h"
#include "lib/stringinfo.h"
#include "miscadmin.h"
#include "storage/fd.h"
#include "storage/shmem.h"
#include "utils/hsearch.h"
Include dependency graph for dfmgr.c:

Go to the source code of this file.

Data Structures

struct  rendezvousHashEntry
 
struct  DynamicFileList
 

Macros

#define SAME_INODE(A, B)   ((A).st_ino == (B).inode && (A).st_dev == (B).device)
 

Typedefs

typedef void(* PG_init_t) (void)
 

Functions

static void * internal_load_library (const char *libname)
 
static pg_noreturn void incompatible_module_error (const char *libname, const Pg_abi_values *module_magic_data)
 
static char * expand_dynamic_library_name (const char *name)
 
static void check_restricted_library_name (const char *name)
 
void * load_external_function (const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
 
void load_file (const char *filename, bool restricted)
 
void * lookup_external_function (void *filehandle, const char *funcname)
 
DynamicFileListget_first_loaded_module (void)
 
DynamicFileListget_next_loaded_module (DynamicFileList *dfptr)
 
void get_loaded_module_details (DynamicFileList *dfptr, const char **library_path, const char **module_name, const char **module_version)
 
char * substitute_path_macro (const char *str, const char *macro, const char *value)
 
char * find_in_path (const char *basename, const char *path, const char *path_param, const char *macro, const char *macro_val)
 
void ** find_rendezvous_variable (const char *varName)
 
Size EstimateLibraryStateSpace (void)
 
void SerializeLibraryState (Size maxsize, char *start_address)
 
void RestoreLibraryState (char *start_address)
 

Variables

static DynamicFileListfile_list = NULL
 
static DynamicFileListfile_tail = NULL
 
char * Dynamic_library_path
 
static const Pg_abi_values magic_data = PG_MODULE_ABI_DATA
 

Macro Definition Documentation

◆ SAME_INODE

#define SAME_INODE (   A,
 
)    ((A).st_ino == (B).inode && (A).st_dev == (B).device)

Definition at line 64 of file dfmgr.c.

Typedef Documentation

◆ PG_init_t

typedef void(* PG_init_t) (void)

Definition at line 32 of file dfmgr.c.

Function Documentation

◆ check_restricted_library_name()

static void check_restricted_library_name ( const char *  name)
static

Definition at line 521 of file dfmgr.c.

522{
523 if (strncmp(name, "$libdir/plugins/", 16) != 0 ||
524 first_dir_separator(name + 16) != NULL)
526 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
527 errmsg("access to library \"%s\" is not allowed",
528 name)));
529}
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:150
char * first_dir_separator(const char *filename)
Definition: path.c:110
const char * name

References ereport, errcode(), errmsg(), ERROR, first_dir_separator(), and name.

Referenced by load_file().

◆ EstimateLibraryStateSpace()

Size EstimateLibraryStateSpace ( void  )

Definition at line 702 of file dfmgr.c.

703{
704 DynamicFileList *file_scanner;
705 Size size = 1;
706
707 for (file_scanner = file_list;
708 file_scanner != NULL;
709 file_scanner = file_scanner->next)
710 size = add_size(size, strlen(file_scanner->filename) + 1);
711
712 return size;
713}
size_t Size
Definition: c.h:611
static DynamicFileList * file_list
Definition: dfmgr.c:59
Size add_size(Size s1, Size s2)
Definition: shmem.c:493
char filename[FLEXIBLE_ARRAY_MEMBER]
Definition: dfmgr.c:56
DynamicFileList * next
Definition: dfmgr.c:48

References add_size(), file_list, DynamicFileList::filename, and DynamicFileList::next.

Referenced by InitializeParallelDSM().

◆ expand_dynamic_library_name()

static char * expand_dynamic_library_name ( const char *  name)
static

Definition at line 466 of file dfmgr.c.

467{
468 bool have_slash;
469 char *new;
470 char *full;
471
472 Assert(name);
473
474 have_slash = (first_dir_separator(name) != NULL);
475
476 if (!have_slash)
477 {
478 full = find_in_path(name, Dynamic_library_path, "dynamic_library_path", "$libdir", pkglib_path);
479 if (full)
480 return full;
481 }
482 else
483 {
484 full = substitute_path_macro(name, "$libdir", pkglib_path);
485 if (pg_file_exists(full))
486 return full;
487 pfree(full);
488 }
489
490 new = psprintf("%s%s", name, DLSUFFIX);
491
492 if (!have_slash)
493 {
494 full = find_in_path(new, Dynamic_library_path, "dynamic_library_path", "$libdir", pkglib_path);
495 pfree(new);
496 if (full)
497 return full;
498 }
499 else
500 {
501 full = substitute_path_macro(new, "$libdir", pkglib_path);
502 pfree(new);
503 if (pg_file_exists(full))
504 return full;
505 pfree(full);
506 }
507
508 /*
509 * If we can't find the file, just return the string as-is. The ensuing
510 * load attempt will fail and report a suitable message.
511 */
512 return pstrdup(name);
513}
char * find_in_path(const char *basename, const char *path, const char *path_param, const char *macro, const char *macro_val)
Definition: dfmgr.c:574
char * Dynamic_library_path
Definition: dfmgr.c:69
char * substitute_path_macro(const char *str, const char *macro, const char *value)
Definition: dfmgr.c:536
bool pg_file_exists(const char *name)
Definition: fd.c:500
char pkglib_path[MAXPGPATH]
Definition: globals.c:82
Assert(PointerIsAligned(start, uint64))
char * pstrdup(const char *in)
Definition: mcxt.c:1759
void pfree(void *pointer)
Definition: mcxt.c:1594
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43

References Assert(), Dynamic_library_path, find_in_path(), first_dir_separator(), name, pfree(), pg_file_exists(), pkglib_path, psprintf(), pstrdup(), and substitute_path_macro().

Referenced by load_external_function(), and load_file().

◆ find_in_path()

char * find_in_path ( const char *  basename,
const char *  path,
const char *  path_param,
const char *  macro,
const char *  macro_val 
)

Definition at line 574 of file dfmgr.c.

576{
577 const char *p;
578 size_t baselen;
579
580 Assert(basename != NULL);
581 Assert(first_dir_separator(basename) == NULL);
582 Assert(path != NULL);
583 Assert(path_param != NULL);
584
585 p = path;
586
587 /*
588 * If the path variable is empty, don't do a path search.
589 */
590 if (strlen(p) == 0)
591 return NULL;
592
593 baselen = strlen(basename);
594
595 for (;;)
596 {
597 size_t len;
598 char *piece;
599 char *mangled;
600 char *full;
601
602 piece = first_path_var_separator(p);
603 if (piece == p)
605 (errcode(ERRCODE_INVALID_NAME),
606 errmsg("zero-length component in parameter \"%s\"", path_param)));
607
608 if (piece == NULL)
609 len = strlen(p);
610 else
611 len = piece - p;
612
613 piece = palloc(len + 1);
614 strlcpy(piece, p, len + 1);
615
616 mangled = substitute_path_macro(piece, macro, macro_val);
617 pfree(piece);
618
619 canonicalize_path(mangled);
620
621 /* only absolute paths */
622 if (!is_absolute_path(mangled))
624 (errcode(ERRCODE_INVALID_NAME),
625 errmsg("component in parameter \"%s\" is not an absolute path", path_param)));
626
627 full = palloc(strlen(mangled) + 1 + baselen + 1);
628 sprintf(full, "%s/%s", mangled, basename);
629 pfree(mangled);
630
631 elog(DEBUG3, "%s: trying \"%s\"", __func__, full);
632
633 if (pg_file_exists(full))
634 return full;
635
636 pfree(full);
637
638 if (p[len] == '\0')
639 break;
640 else
641 p += len + 1;
642 }
643
644 return NULL;
645}
#define DEBUG3
Definition: elog.h:28
#define elog(elevel,...)
Definition: elog.h:226
void * palloc(Size size)
Definition: mcxt.c:1365
const void size_t len
#define is_absolute_path(filename)
Definition: port.h:104
#define sprintf
Definition: port.h:241
char * first_path_var_separator(const char *pathlist)
Definition: path.c:127
void canonicalize_path(char *path)
Definition: path.c:337
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45

References Assert(), canonicalize_path(), DEBUG3, elog, ereport, errcode(), errmsg(), ERROR, first_dir_separator(), first_path_var_separator(), is_absolute_path, len, palloc(), pfree(), pg_file_exists(), sprintf, strlcpy(), and substitute_path_macro().

Referenced by expand_dynamic_library_name().

◆ find_rendezvous_variable()

void ** find_rendezvous_variable ( const char *  varName)

Definition at line 664 of file dfmgr.c.

665{
666 static HTAB *rendezvousHash = NULL;
667
668 rendezvousHashEntry *hentry;
669 bool found;
670
671 /* Create a hashtable if we haven't already done so in this process */
672 if (rendezvousHash == NULL)
673 {
674 HASHCTL ctl;
675
676 ctl.keysize = NAMEDATALEN;
677 ctl.entrysize = sizeof(rendezvousHashEntry);
678 rendezvousHash = hash_create("Rendezvous variable hash",
679 16,
680 &ctl,
682 }
683
684 /* Find or create the hashtable entry for this varName */
685 hentry = (rendezvousHashEntry *) hash_search(rendezvousHash,
686 varName,
688 &found);
689
690 /* Initialize to NULL if first time */
691 if (!found)
692 hentry->varValue = NULL;
693
694 return &hentry->varValue;
695}
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:952
HTAB * hash_create(const char *tabname, int64 nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:358
#define HASH_STRINGS
Definition: hsearch.h:96
@ HASH_ENTER
Definition: hsearch.h:114
#define HASH_ELEM
Definition: hsearch.h:95
#define NAMEDATALEN
tree ctl
Definition: radixtree.h:1838
Definition: dynahash.c:222
void * varValue
Definition: dfmgr.c:38

References ctl, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), HASH_STRINGS, NAMEDATALEN, and rendezvousHashEntry::varValue.

Referenced by _PG_init().

◆ get_first_loaded_module()

DynamicFileList * get_first_loaded_module ( void  )

Definition at line 425 of file dfmgr.c.

426{
427 return file_list;
428}

References file_list.

Referenced by pg_get_loaded_modules().

◆ get_loaded_module_details()

void get_loaded_module_details ( DynamicFileList dfptr,
const char **  library_path,
const char **  module_name,
const char **  module_version 
)

Definition at line 445 of file dfmgr.c.

449{
450 *library_path = dfptr->filename;
451 *module_name = dfptr->magic->name;
452 *module_version = dfptr->magic->version;
453}
const Pg_magic_struct * magic
Definition: dfmgr.c:55
const char * name
Definition: fmgr.h:482
const char * version
Definition: fmgr.h:483

References DynamicFileList::filename, DynamicFileList::magic, Pg_magic_struct::name, and Pg_magic_struct::version.

Referenced by pg_get_loaded_modules().

◆ get_next_loaded_module()

DynamicFileList * get_next_loaded_module ( DynamicFileList dfptr)

Definition at line 431 of file dfmgr.c.

432{
433 return dfptr->next;
434}

References DynamicFileList::next.

Referenced by pg_get_loaded_modules().

◆ incompatible_module_error()

static void incompatible_module_error ( const char *  libname,
const Pg_abi_values module_magic_data 
)
static

Definition at line 316 of file dfmgr.c.

318{
319 StringInfoData details;
320
321 /*
322 * If the version doesn't match, just report that, because the rest of the
323 * block might not even have the fields we expect.
324 */
325 if (magic_data.version != module_magic_data->version)
326 {
327 char library_version[32];
328
329 if (module_magic_data->version >= 1000)
330 snprintf(library_version, sizeof(library_version), "%d",
331 module_magic_data->version / 100);
332 else
333 snprintf(library_version, sizeof(library_version), "%d.%d",
334 module_magic_data->version / 100,
335 module_magic_data->version % 100);
337 (errmsg("incompatible library \"%s\": version mismatch",
338 libname),
339 errdetail("Server is version %d, library is version %s.",
340 magic_data.version / 100, library_version)));
341 }
342
343 /*
344 * Similarly, if the ABI extra field doesn't match, error out. Other
345 * fields below might also mismatch, but that isn't useful information if
346 * you're using the wrong product altogether.
347 */
348 if (strcmp(module_magic_data->abi_extra, magic_data.abi_extra) != 0)
349 {
351 (errmsg("incompatible library \"%s\": ABI mismatch",
352 libname),
353 errdetail("Server has ABI \"%s\", library has \"%s\".",
355 module_magic_data->abi_extra)));
356 }
357
358 /*
359 * Otherwise, spell out which fields don't agree.
360 *
361 * XXX this code has to be adjusted any time the set of fields in a magic
362 * block change!
363 */
364 initStringInfo(&details);
365
366 if (module_magic_data->funcmaxargs != magic_data.funcmaxargs)
367 {
368 if (details.len)
369 appendStringInfoChar(&details, '\n');
370 appendStringInfo(&details,
371 /* translator: %s is a variable name and %d its values */
372 _("Server has %s = %d, library has %d."),
373 "FUNC_MAX_ARGS", magic_data.funcmaxargs,
374 module_magic_data->funcmaxargs);
375 }
376 if (module_magic_data->indexmaxkeys != magic_data.indexmaxkeys)
377 {
378 if (details.len)
379 appendStringInfoChar(&details, '\n');
380 appendStringInfo(&details,
381 /* translator: %s is a variable name and %d its values */
382 _("Server has %s = %d, library has %d."),
383 "INDEX_MAX_KEYS", magic_data.indexmaxkeys,
384 module_magic_data->indexmaxkeys);
385 }
386 if (module_magic_data->namedatalen != magic_data.namedatalen)
387 {
388 if (details.len)
389 appendStringInfoChar(&details, '\n');
390 appendStringInfo(&details,
391 /* translator: %s is a variable name and %d its values */
392 _("Server has %s = %d, library has %d."),
393 "NAMEDATALEN", magic_data.namedatalen,
394 module_magic_data->namedatalen);
395 }
396 if (module_magic_data->float8byval != magic_data.float8byval)
397 {
398 if (details.len)
399 appendStringInfoChar(&details, '\n');
400 appendStringInfo(&details,
401 /* translator: %s is a variable name and %d its values */
402 _("Server has %s = %s, library has %s."),
403 "FLOAT8PASSBYVAL", magic_data.float8byval ? "true" : "false",
404 module_magic_data->float8byval ? "true" : "false");
405 }
406
407 if (details.len == 0)
408 appendStringInfoString(&details,
409 _("Magic block has unexpected length or padding difference."));
410
412 (errmsg("incompatible library \"%s\": magic block mismatch",
413 libname),
414 errdetail_internal("%s", details.data)));
415}
static const Pg_abi_values magic_data
Definition: dfmgr.c:78
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1234
int errdetail(const char *fmt,...)
Definition: elog.c:1207
#define _(x)
Definition: elog.c:91
#define snprintf
Definition: port.h:239
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:230
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:242
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
int funcmaxargs
Definition: fmgr.h:469
int version
Definition: fmgr.h:468
char abi_extra[32]
Definition: fmgr.h:473
int float8byval
Definition: fmgr.h:472
int indexmaxkeys
Definition: fmgr.h:470
int namedatalen
Definition: fmgr.h:471

References _, Pg_abi_values::abi_extra, appendStringInfo(), appendStringInfoChar(), appendStringInfoString(), StringInfoData::data, ereport, errdetail(), errdetail_internal(), errmsg(), ERROR, Pg_abi_values::float8byval, Pg_abi_values::funcmaxargs, Pg_abi_values::indexmaxkeys, initStringInfo(), StringInfoData::len, magic_data, Pg_abi_values::namedatalen, snprintf, and Pg_abi_values::version.

Referenced by internal_load_library().

◆ internal_load_library()

static void * internal_load_library ( const char *  libname)
static

Definition at line 189 of file dfmgr.c.

190{
191 DynamicFileList *file_scanner;
192 PGModuleMagicFunction magic_func;
193 char *load_error;
194 struct stat stat_buf;
195 PG_init_t PG_init;
196
197 /*
198 * Scan the list of loaded FILES to see if the file has been loaded.
199 */
200 for (file_scanner = file_list;
201 file_scanner != NULL &&
202 strcmp(libname, file_scanner->filename) != 0;
203 file_scanner = file_scanner->next)
204 ;
205
206 if (file_scanner == NULL)
207 {
208 /*
209 * Check for same files - different paths (ie, symlink or link)
210 */
211 if (stat(libname, &stat_buf) == -1)
214 errmsg("could not access file \"%s\": %m",
215 libname)));
216
217 for (file_scanner = file_list;
218 file_scanner != NULL &&
219 !SAME_INODE(stat_buf, *file_scanner);
220 file_scanner = file_scanner->next)
221 ;
222 }
223
224 if (file_scanner == NULL)
225 {
226 /*
227 * File not loaded yet.
228 */
229 file_scanner = (DynamicFileList *)
230 malloc(offsetof(DynamicFileList, filename) + strlen(libname) + 1);
231 if (file_scanner == NULL)
233 (errcode(ERRCODE_OUT_OF_MEMORY),
234 errmsg("out of memory")));
235
236 MemSet(file_scanner, 0, offsetof(DynamicFileList, filename));
237 strcpy(file_scanner->filename, libname);
238 file_scanner->device = stat_buf.st_dev;
239#ifndef WIN32
240 file_scanner->inode = stat_buf.st_ino;
241#endif
242 file_scanner->next = NULL;
243
244 file_scanner->handle = dlopen(file_scanner->filename, RTLD_NOW | RTLD_GLOBAL);
245 if (file_scanner->handle == NULL)
246 {
247 load_error = dlerror();
248 free(file_scanner);
249 /* errcode_for_file_access might not be appropriate here? */
252 errmsg("could not load library \"%s\": %s",
253 libname, load_error)));
254 }
255
256 /* Check the magic function to determine compatibility */
257 magic_func = (PGModuleMagicFunction)
259 if (magic_func)
260 {
261 const Pg_magic_struct *magic_data_ptr = (*magic_func) ();
262
263 /* Check ABI compatibility fields */
264 if (magic_data_ptr->len != sizeof(Pg_magic_struct) ||
265 memcmp(&magic_data_ptr->abi_fields, &magic_data,
266 sizeof(Pg_abi_values)) != 0)
267 {
268 /* copy data block before unlinking library */
269 Pg_magic_struct module_magic_data = *magic_data_ptr;
270
271 /* try to close library */
272 dlclose(file_scanner->handle);
273 free(file_scanner);
274
275 /* issue suitable complaint */
276 incompatible_module_error(libname, &module_magic_data.abi_fields);
277 }
278
279 /* Remember the magic block's location for future use */
280 file_scanner->magic = magic_data_ptr;
281 }
282 else
283 {
284 /* try to close library */
285 dlclose(file_scanner->handle);
286 free(file_scanner);
287 /* complain */
289 (errmsg("incompatible library \"%s\": missing magic block",
290 libname),
291 errhint("Extension libraries are required to use the PG_MODULE_MAGIC macro.")));
292 }
293
294 /*
295 * If the library has a _PG_init() function, call it.
296 */
297 PG_init = (PG_init_t) dlsym(file_scanner->handle, "_PG_init");
298 if (PG_init)
299 (*PG_init) ();
300
301 /* OK to link it into list */
302 if (file_list == NULL)
303 file_list = file_scanner;
304 else
305 file_tail->next = file_scanner;
306 file_tail = file_scanner;
307 }
308
309 return file_scanner->handle;
310}
#define MemSet(start, val, len)
Definition: c.h:1020
static DynamicFileList * file_tail
Definition: dfmgr.c:60
static pg_noreturn void incompatible_module_error(const char *libname, const Pg_abi_values *module_magic_data)
Definition: dfmgr.c:316
void(* PG_init_t)(void)
Definition: dfmgr.c:32
#define SAME_INODE(A, B)
Definition: dfmgr.c:64
int errcode_for_file_access(void)
Definition: elog.c:877
int errhint(const char *fmt,...)
Definition: elog.c:1321
#define PG_MAGIC_FUNCTION_NAME_STRING
Definition: fmgr.h:518
const Pg_magic_struct *(* PGModuleMagicFunction)(void)
Definition: fmgr.h:515
#define free(a)
Definition: header.h:65
#define malloc(a)
Definition: header.h:50
static char * filename
Definition: pg_dumpall.c:120
ino_t inode
Definition: dfmgr.c:52
dev_t device
Definition: dfmgr.c:49
void * handle
Definition: dfmgr.c:54
Pg_abi_values abi_fields
Definition: fmgr.h:480
void * dlopen(const char *file, int mode)
Definition: win32dlopen.c:76
#define stat
Definition: win32_port.h:274
char * dlerror(void)
Definition: win32dlopen.c:40
void * dlsym(void *handle, const char *symbol)
Definition: win32dlopen.c:61
#define RTLD_NOW
Definition: win32_port.h:533
#define RTLD_GLOBAL
Definition: win32_port.h:534
int dlclose(void *handle)
Definition: win32dlopen.c:49

References Pg_magic_struct::abi_fields, DynamicFileList::device, dlclose(), dlerror(), dlopen(), dlsym(), ereport, errcode(), errcode_for_file_access(), errhint(), errmsg(), ERROR, file_list, file_tail, DynamicFileList::filename, filename, free, DynamicFileList::handle, incompatible_module_error(), DynamicFileList::inode, Pg_magic_struct::len, DynamicFileList::magic, magic_data, malloc, MemSet, DynamicFileList::next, PG_MAGIC_FUNCTION_NAME_STRING, RTLD_GLOBAL, RTLD_NOW, SAME_INODE, stat::st_dev, stat::st_ino, and stat.

Referenced by load_external_function(), load_file(), and RestoreLibraryState().

◆ load_external_function()

void * load_external_function ( const char *  filename,
const char *  funcname,
bool  signalNotFound,
void **  filehandle 
)

Definition at line 95 of file dfmgr.c.

97{
98 char *fullname;
99 void *lib_handle;
100 void *retval;
101
102 /*
103 * For extensions with hardcoded '$libdir/' library names, we strip the
104 * prefix to allow the library search path to be used. This is done only
105 * for simple names (e.g., "$libdir/foo"), not for nested paths (e.g.,
106 * "$libdir/foo/bar").
107 *
108 * For nested paths, 'expand_dynamic_library_name' directly expands the
109 * '$libdir' macro, so we leave them untouched.
110 */
111 if (strncmp(filename, "$libdir/", 8) == 0)
112 {
113 if (first_dir_separator(filename + 8) == NULL)
114 filename += 8;
115 }
116
117 /* Expand the possibly-abbreviated filename to an exact path name */
119
120 /* Load the shared library, unless we already did */
121 lib_handle = internal_load_library(fullname);
122
123 /* Return handle if caller wants it */
124 if (filehandle)
125 *filehandle = lib_handle;
126
127 /* Look up the function within the library. */
128 retval = dlsym(lib_handle, funcname);
129
130 if (retval == NULL && signalNotFound)
132 (errcode(ERRCODE_UNDEFINED_FUNCTION),
133 errmsg("could not find function \"%s\" in file \"%s\"",
134 funcname, fullname)));
135
136 pfree(fullname);
137 return retval;
138}
static char * expand_dynamic_library_name(const char *name)
Definition: dfmgr.c:466
static void * internal_load_library(const char *libname)
Definition: dfmgr.c:189
#define funcname
Definition: indent_codes.h:69

References dlsym(), ereport, errcode(), errmsg(), ERROR, expand_dynamic_library_name(), filename, first_dir_separator(), funcname, internal_load_library(), and pfree().

Referenced by _PG_init(), fmgr_c_validator(), fmgr_info_C_lang(), llvm_resolve_symbol(), load_validator_library(), LoadArchiveLibrary(), LoadOutputPlugin(), LookupBackgroundWorkerFunction(), LookupParallelWorkerFunction(), and provider_init().

◆ load_file()

void load_file ( const char *  filename,
bool  restricted 
)

Definition at line 149 of file dfmgr.c.

150{
151 char *fullname;
152
153 /* Apply security restriction if requested */
154 if (restricted)
156
157 /* Expand the possibly-abbreviated filename to an exact path name */
159
160 /* Load the shared library, unless we already did */
161 (void) internal_load_library(fullname);
162
163 pfree(fullname);
164}
static bool restricted
Definition: command.c:199
static void check_restricted_library_name(const char *name)
Definition: dfmgr.c:521

References check_restricted_library_name(), expand_dynamic_library_name(), filename, internal_load_library(), pfree(), and restricted.

Referenced by AlterSubscription(), AlterSubscription_refresh(), CreateSubscription(), DropSubscription(), load_libraries(), pg_sync_replication_slots(), ReplicationSlotDropAtPubNode(), ReplSlotSyncWorkerMain(), SetupApplyOrSyncWorker(), standard_ProcessUtility(), and WalReceiverMain().

◆ lookup_external_function()

void * lookup_external_function ( void *  filehandle,
const char *  funcname 
)

Definition at line 171 of file dfmgr.c.

172{
173 return dlsym(filehandle, funcname);
174}

References dlsym(), and funcname.

Referenced by fetch_finfo_record().

◆ RestoreLibraryState()

void RestoreLibraryState ( char *  start_address)

Definition at line 741 of file dfmgr.c.

742{
743 while (*start_address != '\0')
744 {
745 internal_load_library(start_address);
746 start_address += strlen(start_address) + 1;
747 }
748}

References internal_load_library().

Referenced by ParallelWorkerMain().

◆ SerializeLibraryState()

void SerializeLibraryState ( Size  maxsize,
char *  start_address 
)

Definition at line 719 of file dfmgr.c.

720{
721 DynamicFileList *file_scanner;
722
723 for (file_scanner = file_list;
724 file_scanner != NULL;
725 file_scanner = file_scanner->next)
726 {
727 Size len;
728
729 len = strlcpy(start_address, file_scanner->filename, maxsize) + 1;
730 Assert(len < maxsize);
731 maxsize -= len;
732 start_address += len;
733 }
734 start_address[0] = '\0';
735}

References Assert(), file_list, DynamicFileList::filename, len, DynamicFileList::next, and strlcpy().

Referenced by InitializeParallelDSM().

◆ substitute_path_macro()

char * substitute_path_macro ( const char *  str,
const char *  macro,
const char *  value 
)

Definition at line 536 of file dfmgr.c.

537{
538 const char *sep_ptr;
539
540 Assert(str != NULL);
541 Assert(macro[0] == '$');
542
543 /* Currently, we only recognize $macro at the start of the string */
544 if (str[0] != '$')
545 return pstrdup(str);
546
547 if ((sep_ptr = first_dir_separator(str)) == NULL)
548 sep_ptr = str + strlen(str);
549
550 if (strlen(macro) != sep_ptr - str ||
551 strncmp(str, macro, strlen(macro)) != 0)
553 (errcode(ERRCODE_INVALID_NAME),
554 errmsg("invalid macro name in path: %s",
555 str)));
556
557 return psprintf("%s%s", value, sep_ptr);
558}
const char * str
static struct @166 value

References Assert(), ereport, errcode(), errmsg(), ERROR, first_dir_separator(), psprintf(), pstrdup(), str, and value.

Referenced by expand_dynamic_library_name(), find_in_path(), and get_extension_control_directories().

Variable Documentation

◆ Dynamic_library_path

char* Dynamic_library_path

Definition at line 69 of file dfmgr.c.

Referenced by expand_dynamic_library_name().

◆ file_list

DynamicFileList* file_list = NULL
static

◆ file_tail

DynamicFileList* file_tail = NULL
static

Definition at line 60 of file dfmgr.c.

Referenced by internal_load_library().

◆ magic_data

const Pg_abi_values magic_data = PG_MODULE_ABI_DATA
static

Definition at line 78 of file dfmgr.c.

Referenced by incompatible_module_error(), and internal_load_library().