PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 514 of file dfmgr.c.

515{
516 if (strncmp(name, "$libdir/plugins/", 16) != 0 ||
517 first_dir_separator(name + 16) != NULL)
519 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
520 errmsg("access to library \"%s\" is not allowed",
521 name)));
522}
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:149
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 695 of file dfmgr.c.

696{
697 DynamicFileList *file_scanner;
698 Size size = 1;
699
700 for (file_scanner = file_list;
701 file_scanner != NULL;
702 file_scanner = file_scanner->next)
703 size = add_size(size, strlen(file_scanner->filename) + 1);
704
705 return size;
706}
size_t Size
Definition: c.h:576
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 451 of file dfmgr.c.

452{
453 bool have_slash;
454 char *new;
455 char *full;
456
457 Assert(name);
458
459 /*
460 * If the value starts with "$libdir/", strip that. This is because many
461 * extensions have hardcoded '$libdir/foo' as their library name, which
462 * prevents using the path.
463 */
464 if (strncmp(name, "$libdir/", 8) == 0)
465 name += 8;
466
467 have_slash = (first_dir_separator(name) != NULL);
468
469 if (!have_slash)
470 {
471 full = find_in_path(name, Dynamic_library_path, "dynamic_library_path", "$libdir", pkglib_path);
472 if (full)
473 return full;
474 }
475 else
476 {
477 full = substitute_path_macro(name, "$libdir", pkglib_path);
478 if (pg_file_exists(full))
479 return full;
480 pfree(full);
481 }
482
483 new = psprintf("%s%s", name, DLSUFFIX);
484
485 if (!have_slash)
486 {
487 full = find_in_path(new, Dynamic_library_path, "dynamic_library_path", "$libdir", pkglib_path);
488 pfree(new);
489 if (full)
490 return full;
491 }
492 else
493 {
494 full = substitute_path_macro(new, "$libdir", pkglib_path);
495 pfree(new);
496 if (pg_file_exists(full))
497 return full;
498 pfree(full);
499 }
500
501 /*
502 * If we can't find the file, just return the string as-is. The ensuing
503 * load attempt will fail and report a suitable message.
504 */
505 return pstrdup(name);
506}
char * find_in_path(const char *basename, const char *path, const char *path_param, const char *macro, const char *macro_val)
Definition: dfmgr.c:567
char * Dynamic_library_path
Definition: dfmgr.c:69
char * substitute_path_macro(const char *str, const char *macro, const char *value)
Definition: dfmgr.c:529
bool pg_file_exists(const char *name)
Definition: fd.c:503
char pkglib_path[MAXPGPATH]
Definition: globals.c:83
Assert(PointerIsAligned(start, uint64))
char * pstrdup(const char *in)
Definition: mcxt.c:2322
void pfree(void *pointer)
Definition: mcxt.c:2147
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 567 of file dfmgr.c.

569{
570 const char *p;
571 size_t baselen;
572
573 Assert(basename != NULL);
574 Assert(first_dir_separator(basename) == NULL);
575 Assert(path != NULL);
576 Assert(path_param != NULL);
577
578 p = path;
579
580 /*
581 * If the path variable is empty, don't do a path search.
582 */
583 if (strlen(p) == 0)
584 return NULL;
585
586 baselen = strlen(basename);
587
588 for (;;)
589 {
590 size_t len;
591 char *piece;
592 char *mangled;
593 char *full;
594
595 piece = first_path_var_separator(p);
596 if (piece == p)
598 (errcode(ERRCODE_INVALID_NAME),
599 errmsg("zero-length component in parameter \"%s\"", path_param)));
600
601 if (piece == NULL)
602 len = strlen(p);
603 else
604 len = piece - p;
605
606 piece = palloc(len + 1);
607 strlcpy(piece, p, len + 1);
608
609 mangled = substitute_path_macro(piece, macro, macro_val);
610 pfree(piece);
611
612 canonicalize_path(mangled);
613
614 /* only absolute paths */
615 if (!is_absolute_path(mangled))
617 (errcode(ERRCODE_INVALID_NAME),
618 errmsg("component in parameter \"%s\" is not an absolute path", path_param)));
619
620 full = palloc(strlen(mangled) + 1 + baselen + 1);
621 sprintf(full, "%s/%s", mangled, basename);
622 pfree(mangled);
623
624 elog(DEBUG3, "%s: trying \"%s\"", __func__, full);
625
626 if (pg_file_exists(full))
627 return full;
628
629 pfree(full);
630
631 if (p[len] == '\0')
632 break;
633 else
634 p += len + 1;
635 }
636
637 return NULL;
638}
#define DEBUG3
Definition: elog.h:28
#define elog(elevel,...)
Definition: elog.h:226
void * palloc(Size size)
Definition: mcxt.c:1940
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(), and find_extension_control_filename().

◆ find_rendezvous_variable()

void ** find_rendezvous_variable ( const char *  varName)

Definition at line 657 of file dfmgr.c.

658{
659 static HTAB *rendezvousHash = NULL;
660
661 rendezvousHashEntry *hentry;
662 bool found;
663
664 /* Create a hashtable if we haven't already done so in this process */
665 if (rendezvousHash == NULL)
666 {
667 HASHCTL ctl;
668
669 ctl.keysize = NAMEDATALEN;
670 ctl.entrysize = sizeof(rendezvousHashEntry);
671 rendezvousHash = hash_create("Rendezvous variable hash",
672 16,
673 &ctl,
675 }
676
677 /* Find or create the hashtable entry for this varName */
678 hentry = (rendezvousHashEntry *) hash_search(rendezvousHash,
679 varName,
681 &found);
682
683 /* Initialize to NULL if first time */
684 if (!found)
685 hentry->varValue = NULL;
686
687 return &hentry->varValue;
688}
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:955
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:352
#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:220
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 410 of file dfmgr.c.

411{
412 return file_list;
413}

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 430 of file dfmgr.c.

434{
435 *library_path = dfptr->filename;
436 *module_name = dfptr->magic->name;
437 *module_version = dfptr->magic->version;
438}
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 416 of file dfmgr.c.

417{
418 return dfptr->next;
419}

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 301 of file dfmgr.c.

303{
304 StringInfoData details;
305
306 /*
307 * If the version doesn't match, just report that, because the rest of the
308 * block might not even have the fields we expect.
309 */
310 if (magic_data.version != module_magic_data->version)
311 {
312 char library_version[32];
313
314 if (module_magic_data->version >= 1000)
315 snprintf(library_version, sizeof(library_version), "%d",
316 module_magic_data->version / 100);
317 else
318 snprintf(library_version, sizeof(library_version), "%d.%d",
319 module_magic_data->version / 100,
320 module_magic_data->version % 100);
322 (errmsg("incompatible library \"%s\": version mismatch",
323 libname),
324 errdetail("Server is version %d, library is version %s.",
325 magic_data.version / 100, library_version)));
326 }
327
328 /*
329 * Similarly, if the ABI extra field doesn't match, error out. Other
330 * fields below might also mismatch, but that isn't useful information if
331 * you're using the wrong product altogether.
332 */
333 if (strcmp(module_magic_data->abi_extra, magic_data.abi_extra) != 0)
334 {
336 (errmsg("incompatible library \"%s\": ABI mismatch",
337 libname),
338 errdetail("Server has ABI \"%s\", library has \"%s\".",
340 module_magic_data->abi_extra)));
341 }
342
343 /*
344 * Otherwise, spell out which fields don't agree.
345 *
346 * XXX this code has to be adjusted any time the set of fields in a magic
347 * block change!
348 */
349 initStringInfo(&details);
350
351 if (module_magic_data->funcmaxargs != magic_data.funcmaxargs)
352 {
353 if (details.len)
354 appendStringInfoChar(&details, '\n');
355 appendStringInfo(&details,
356 /* translator: %s is a variable name and %d its values */
357 _("Server has %s = %d, library has %d."),
358 "FUNC_MAX_ARGS", magic_data.funcmaxargs,
359 module_magic_data->funcmaxargs);
360 }
361 if (module_magic_data->indexmaxkeys != magic_data.indexmaxkeys)
362 {
363 if (details.len)
364 appendStringInfoChar(&details, '\n');
365 appendStringInfo(&details,
366 /* translator: %s is a variable name and %d its values */
367 _("Server has %s = %d, library has %d."),
368 "INDEX_MAX_KEYS", magic_data.indexmaxkeys,
369 module_magic_data->indexmaxkeys);
370 }
371 if (module_magic_data->namedatalen != magic_data.namedatalen)
372 {
373 if (details.len)
374 appendStringInfoChar(&details, '\n');
375 appendStringInfo(&details,
376 /* translator: %s is a variable name and %d its values */
377 _("Server has %s = %d, library has %d."),
378 "NAMEDATALEN", magic_data.namedatalen,
379 module_magic_data->namedatalen);
380 }
381 if (module_magic_data->float8byval != magic_data.float8byval)
382 {
383 if (details.len)
384 appendStringInfoChar(&details, '\n');
385 appendStringInfo(&details,
386 /* translator: %s is a variable name and %d its values */
387 _("Server has %s = %s, library has %s."),
388 "FLOAT8PASSBYVAL", magic_data.float8byval ? "true" : "false",
389 module_magic_data->float8byval ? "true" : "false");
390 }
391
392 if (details.len == 0)
393 appendStringInfoString(&details,
394 _("Magic block has unexpected length or padding difference."));
395
397 (errmsg("incompatible library \"%s\": magic block mismatch",
398 libname),
399 errdetail_internal("%s", details.data)));
400}
static const Pg_abi_values magic_data
Definition: dfmgr.c:78
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1231
int errdetail(const char *fmt,...)
Definition: elog.c:1204
#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 174 of file dfmgr.c.

175{
176 DynamicFileList *file_scanner;
177 PGModuleMagicFunction magic_func;
178 char *load_error;
179 struct stat stat_buf;
180 PG_init_t PG_init;
181
182 /*
183 * Scan the list of loaded FILES to see if the file has been loaded.
184 */
185 for (file_scanner = file_list;
186 file_scanner != NULL &&
187 strcmp(libname, file_scanner->filename) != 0;
188 file_scanner = file_scanner->next)
189 ;
190
191 if (file_scanner == NULL)
192 {
193 /*
194 * Check for same files - different paths (ie, symlink or link)
195 */
196 if (stat(libname, &stat_buf) == -1)
199 errmsg("could not access file \"%s\": %m",
200 libname)));
201
202 for (file_scanner = file_list;
203 file_scanner != NULL &&
204 !SAME_INODE(stat_buf, *file_scanner);
205 file_scanner = file_scanner->next)
206 ;
207 }
208
209 if (file_scanner == NULL)
210 {
211 /*
212 * File not loaded yet.
213 */
214 file_scanner = (DynamicFileList *)
215 malloc(offsetof(DynamicFileList, filename) + strlen(libname) + 1);
216 if (file_scanner == NULL)
218 (errcode(ERRCODE_OUT_OF_MEMORY),
219 errmsg("out of memory")));
220
221 MemSet(file_scanner, 0, offsetof(DynamicFileList, filename));
222 strcpy(file_scanner->filename, libname);
223 file_scanner->device = stat_buf.st_dev;
224#ifndef WIN32
225 file_scanner->inode = stat_buf.st_ino;
226#endif
227 file_scanner->next = NULL;
228
229 file_scanner->handle = dlopen(file_scanner->filename, RTLD_NOW | RTLD_GLOBAL);
230 if (file_scanner->handle == NULL)
231 {
232 load_error = dlerror();
233 free(file_scanner);
234 /* errcode_for_file_access might not be appropriate here? */
237 errmsg("could not load library \"%s\": %s",
238 libname, load_error)));
239 }
240
241 /* Check the magic function to determine compatibility */
242 magic_func = (PGModuleMagicFunction)
244 if (magic_func)
245 {
246 const Pg_magic_struct *magic_data_ptr = (*magic_func) ();
247
248 /* Check ABI compatibility fields */
249 if (magic_data_ptr->len != sizeof(Pg_magic_struct) ||
250 memcmp(&magic_data_ptr->abi_fields, &magic_data,
251 sizeof(Pg_abi_values)) != 0)
252 {
253 /* copy data block before unlinking library */
254 Pg_magic_struct module_magic_data = *magic_data_ptr;
255
256 /* try to close library */
257 dlclose(file_scanner->handle);
258 free(file_scanner);
259
260 /* issue suitable complaint */
261 incompatible_module_error(libname, &module_magic_data.abi_fields);
262 }
263
264 /* Remember the magic block's location for future use */
265 file_scanner->magic = magic_data_ptr;
266 }
267 else
268 {
269 /* try to close library */
270 dlclose(file_scanner->handle);
271 free(file_scanner);
272 /* complain */
274 (errmsg("incompatible library \"%s\": missing magic block",
275 libname),
276 errhint("Extension libraries are required to use the PG_MODULE_MAGIC macro.")));
277 }
278
279 /*
280 * If the library has a _PG_init() function, call it.
281 */
282 PG_init = (PG_init_t) dlsym(file_scanner->handle, "_PG_init");
283 if (PG_init)
284 (*PG_init) ();
285
286 /* OK to link it into list */
287 if (file_list == NULL)
288 file_list = file_scanner;
289 else
290 file_tail->next = file_scanner;
291 file_tail = file_scanner;
292 }
293
294 return file_scanner->handle;
295}
#define MemSet(start, val, len)
Definition: c.h:991
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:301
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:1318
#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:123
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 /* Expand the possibly-abbreviated filename to an exact path name */
104
105 /* Load the shared library, unless we already did */
106 lib_handle = internal_load_library(fullname);
107
108 /* Return handle if caller wants it */
109 if (filehandle)
110 *filehandle = lib_handle;
111
112 /* Look up the function within the library. */
113 retval = dlsym(lib_handle, funcname);
114
115 if (retval == NULL && signalNotFound)
117 (errcode(ERRCODE_UNDEFINED_FUNCTION),
118 errmsg("could not find function \"%s\" in file \"%s\"",
119 funcname, fullname)));
120
121 pfree(fullname);
122 return retval;
123}
static char * expand_dynamic_library_name(const char *name)
Definition: dfmgr.c:451
static void * internal_load_library(const char *libname)
Definition: dfmgr.c:174
#define funcname
Definition: indent_codes.h:69

References dlsym(), ereport, errcode(), errmsg(), ERROR, expand_dynamic_library_name(), filename, 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 134 of file dfmgr.c.

135{
136 char *fullname;
137
138 /* Apply security restriction if requested */
139 if (restricted)
141
142 /* Expand the possibly-abbreviated filename to an exact path name */
144
145 /* Load the shared library, unless we already did */
146 (void) internal_load_library(fullname);
147
148 pfree(fullname);
149}
static void check_restricted_library_name(const char *name)
Definition: dfmgr.c:514

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

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 156 of file dfmgr.c.

157{
158 return dlsym(filehandle, funcname);
159}

References dlsym(), and funcname.

Referenced by fetch_finfo_record().

◆ RestoreLibraryState()

void RestoreLibraryState ( char *  start_address)

Definition at line 734 of file dfmgr.c.

735{
736 while (*start_address != '\0')
737 {
738 internal_load_library(start_address);
739 start_address += strlen(start_address) + 1;
740 }
741}

References internal_load_library().

Referenced by ParallelWorkerMain().

◆ SerializeLibraryState()

void SerializeLibraryState ( Size  maxsize,
char *  start_address 
)

Definition at line 712 of file dfmgr.c.

713{
714 DynamicFileList *file_scanner;
715
716 for (file_scanner = file_list;
717 file_scanner != NULL;
718 file_scanner = file_scanner->next)
719 {
720 Size len;
721
722 len = strlcpy(start_address, file_scanner->filename, maxsize) + 1;
723 Assert(len < maxsize);
724 maxsize -= len;
725 start_address += len;
726 }
727 start_address[0] = '\0';
728}

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 529 of file dfmgr.c.

530{
531 const char *sep_ptr;
532
533 Assert(str != NULL);
534 Assert(macro[0] == '$');
535
536 /* Currently, we only recognize $macro at the start of the string */
537 if (str[0] != '$')
538 return pstrdup(str);
539
540 if ((sep_ptr = first_dir_separator(str)) == NULL)
541 sep_ptr = str + strlen(str);
542
543 if (strlen(macro) != sep_ptr - str ||
544 strncmp(str, macro, strlen(macro)) != 0)
546 (errcode(ERRCODE_INVALID_NAME),
547 errmsg("invalid macro name in path: %s",
548 str)));
549
550 return psprintf("%s%s", value, sep_ptr);
551}
const char * str
static struct @165 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().