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  df_files
 

Macros

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

Typedefs

typedef void(* PG_init_t) (void)
 
typedef struct df_files DynamicFileList
 

Functions

static void * internal_load_library (const char *libname)
 
static pg_noreturn void incompatible_module_error (const char *libname, const Pg_magic_struct *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)
 
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_magic_struct magic_data = PG_MODULE_MAGIC_DATA
 

Macro Definition Documentation

◆ SAME_INODE

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

Definition at line 62 of file dfmgr.c.

Typedef Documentation

◆ DynamicFileList

typedef struct df_files DynamicFileList

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

470{
471 if (strncmp(name, "$libdir/plugins/", 16) != 0 ||
472 first_dir_separator(name + 16) != NULL)
474 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
475 errmsg("access to library \"%s\" is not allowed",
476 name)));
477}
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#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 650 of file dfmgr.c.

651{
652 DynamicFileList *file_scanner;
653 Size size = 1;
654
655 for (file_scanner = file_list;
656 file_scanner != NULL;
657 file_scanner = file_scanner->next)
658 size = add_size(size, strlen(file_scanner->filename) + 1);
659
660 return size;
661}
size_t Size
Definition: c.h:576
static DynamicFileList * file_list
Definition: dfmgr.c:57
Size add_size(Size s1, Size s2)
Definition: shmem.c:488
Definition: dfmgr.c:46
struct df_files * next
Definition: dfmgr.c:47
char filename[FLEXIBLE_ARRAY_MEMBER]
Definition: dfmgr.c:54

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

Referenced by InitializeParallelDSM().

◆ expand_dynamic_library_name()

static char * expand_dynamic_library_name ( const char *  name)
static

Definition at line 406 of file dfmgr.c.

407{
408 bool have_slash;
409 char *new;
410 char *full;
411
412 Assert(name);
413
414 /*
415 * If the value starts with "$libdir/", strip that. This is because many
416 * extensions have hardcoded '$libdir/foo' as their library name, which
417 * prevents using the path.
418 */
419 if (strncmp(name, "$libdir/", 8) == 0)
420 name += 8;
421
422 have_slash = (first_dir_separator(name) != NULL);
423
424 if (!have_slash)
425 {
426 full = find_in_path(name, Dynamic_library_path, "dynamic_library_path", "$libdir", pkglib_path);
427 if (full)
428 return full;
429 }
430 else
431 {
432 full = substitute_path_macro(name, "$libdir", pkglib_path);
433 if (pg_file_exists(full))
434 return full;
435 pfree(full);
436 }
437
438 new = psprintf("%s%s", name, DLSUFFIX);
439
440 if (!have_slash)
441 {
442 full = find_in_path(new, Dynamic_library_path, "dynamic_library_path", "$libdir", pkglib_path);
443 pfree(new);
444 if (full)
445 return full;
446 }
447 else
448 {
449 full = substitute_path_macro(new, "$libdir", pkglib_path);
450 pfree(new);
451 if (pg_file_exists(full))
452 return full;
453 pfree(full);
454 }
455
456 /*
457 * If we can't find the file, just return the string as-is. The ensuing
458 * load attempt will fail and report a suitable message.
459 */
460 return pstrdup(name);
461}
char * find_in_path(const char *basename, const char *path, const char *path_param, const char *macro, const char *macro_val)
Definition: dfmgr.c:522
char * Dynamic_library_path
Definition: dfmgr.c:67
char * substitute_path_macro(const char *str, const char *macro, const char *value)
Definition: dfmgr.c:484
bool pg_file_exists(const char *name)
Definition: fd.c:502
char pkglib_path[MAXPGPATH]
Definition: globals.c:81
Assert(PointerIsAligned(start, uint64))
char * pstrdup(const char *in)
Definition: mcxt.c:1699
void pfree(void *pointer)
Definition: mcxt.c:1524
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 522 of file dfmgr.c.

524{
525 const char *p;
526 size_t baselen;
527
528 Assert(basename != NULL);
529 Assert(first_dir_separator(basename) == NULL);
530 Assert(path != NULL);
531 Assert(path_param != NULL);
532
533 p = path;
534
535 /*
536 * If the path variable is empty, don't do a path search.
537 */
538 if (strlen(p) == 0)
539 return NULL;
540
541 baselen = strlen(basename);
542
543 for (;;)
544 {
545 size_t len;
546 char *piece;
547 char *mangled;
548 char *full;
549
550 piece = first_path_var_separator(p);
551 if (piece == p)
553 (errcode(ERRCODE_INVALID_NAME),
554 errmsg("zero-length component in parameter \"%s\"", path_param)));
555
556 if (piece == NULL)
557 len = strlen(p);
558 else
559 len = piece - p;
560
561 piece = palloc(len + 1);
562 strlcpy(piece, p, len + 1);
563
564 mangled = substitute_path_macro(piece, macro, macro_val);
565 pfree(piece);
566
567 canonicalize_path(mangled);
568
569 /* only absolute paths */
570 if (!is_absolute_path(mangled))
572 (errcode(ERRCODE_INVALID_NAME),
573 errmsg("component in parameter \"%s\" is not an absolute path", path_param)));
574
575 full = palloc(strlen(mangled) + 1 + baselen + 1);
576 sprintf(full, "%s/%s", mangled, basename);
577 pfree(mangled);
578
579 elog(DEBUG3, "%s: trying \"%s\"", __func__, full);
580
581 if (pg_file_exists(full))
582 return full;
583
584 pfree(full);
585
586 if (p[len] == '\0')
587 break;
588 else
589 p += len + 1;
590 }
591
592 return NULL;
593}
#define DEBUG3
Definition: elog.h:28
#define elog(elevel,...)
Definition: elog.h:225
void * palloc(Size size)
Definition: mcxt.c:1317
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 612 of file dfmgr.c.

613{
614 static HTAB *rendezvousHash = NULL;
615
616 rendezvousHashEntry *hentry;
617 bool found;
618
619 /* Create a hashtable if we haven't already done so in this process */
620 if (rendezvousHash == NULL)
621 {
622 HASHCTL ctl;
623
624 ctl.keysize = NAMEDATALEN;
625 ctl.entrysize = sizeof(rendezvousHashEntry);
626 rendezvousHash = hash_create("Rendezvous variable hash",
627 16,
628 &ctl,
630 }
631
632 /* Find or create the hashtable entry for this varName */
633 hentry = (rendezvousHashEntry *) hash_search(rendezvousHash,
634 varName,
636 &found);
637
638 /* Initialize to NULL if first time */
639 if (!found)
640 hentry->varValue = NULL;
641
642 return &hentry->varValue;
643}
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().

◆ incompatible_module_error()

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

Definition at line 294 of file dfmgr.c.

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

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

Referenced by internal_load_library().

◆ internal_load_library()

static void * internal_load_library ( const char *  libname)
static

Definition at line 172 of file dfmgr.c.

173{
174 DynamicFileList *file_scanner;
175 PGModuleMagicFunction magic_func;
176 char *load_error;
177 struct stat stat_buf;
178 PG_init_t PG_init;
179
180 /*
181 * Scan the list of loaded FILES to see if the file has been loaded.
182 */
183 for (file_scanner = file_list;
184 file_scanner != NULL &&
185 strcmp(libname, file_scanner->filename) != 0;
186 file_scanner = file_scanner->next)
187 ;
188
189 if (file_scanner == NULL)
190 {
191 /*
192 * Check for same files - different paths (ie, symlink or link)
193 */
194 if (stat(libname, &stat_buf) == -1)
197 errmsg("could not access file \"%s\": %m",
198 libname)));
199
200 for (file_scanner = file_list;
201 file_scanner != NULL &&
202 !SAME_INODE(stat_buf, *file_scanner);
203 file_scanner = file_scanner->next)
204 ;
205 }
206
207 if (file_scanner == NULL)
208 {
209 /*
210 * File not loaded yet.
211 */
212 file_scanner = (DynamicFileList *)
213 malloc(offsetof(DynamicFileList, filename) + strlen(libname) + 1);
214 if (file_scanner == NULL)
216 (errcode(ERRCODE_OUT_OF_MEMORY),
217 errmsg("out of memory")));
218
219 MemSet(file_scanner, 0, offsetof(DynamicFileList, filename));
220 strcpy(file_scanner->filename, libname);
221 file_scanner->device = stat_buf.st_dev;
222#ifndef WIN32
223 file_scanner->inode = stat_buf.st_ino;
224#endif
225 file_scanner->next = NULL;
226
227 file_scanner->handle = dlopen(file_scanner->filename, RTLD_NOW | RTLD_GLOBAL);
228 if (file_scanner->handle == NULL)
229 {
230 load_error = dlerror();
231 free(file_scanner);
232 /* errcode_for_file_access might not be appropriate here? */
235 errmsg("could not load library \"%s\": %s",
236 libname, load_error)));
237 }
238
239 /* Check the magic function to determine compatibility */
240 magic_func = (PGModuleMagicFunction)
242 if (magic_func)
243 {
244 const Pg_magic_struct *magic_data_ptr = (*magic_func) ();
245
246 if (magic_data_ptr->len != magic_data.len ||
247 memcmp(magic_data_ptr, &magic_data, magic_data.len) != 0)
248 {
249 /* copy data block before unlinking library */
250 Pg_magic_struct module_magic_data = *magic_data_ptr;
251
252 /* try to close library */
253 dlclose(file_scanner->handle);
254 free(file_scanner);
255
256 /* issue suitable complaint */
257 incompatible_module_error(libname, &module_magic_data);
258 }
259 }
260 else
261 {
262 /* try to close library */
263 dlclose(file_scanner->handle);
264 free(file_scanner);
265 /* complain */
267 (errmsg("incompatible library \"%s\": missing magic block",
268 libname),
269 errhint("Extension libraries are required to use the PG_MODULE_MAGIC macro.")));
270 }
271
272 /*
273 * If the library has a _PG_init() function, call it.
274 */
275 PG_init = (PG_init_t) dlsym(file_scanner->handle, "_PG_init");
276 if (PG_init)
277 (*PG_init) ();
278
279 /* OK to link it into list */
280 if (file_list == NULL)
281 file_list = file_scanner;
282 else
283 file_tail->next = file_scanner;
284 file_tail = file_scanner;
285 }
286
287 return file_scanner->handle;
288}
#define MemSet(start, val, len)
Definition: c.h:991
static DynamicFileList * file_tail
Definition: dfmgr.c:58
static pg_noreturn void incompatible_module_error(const char *libname, const Pg_magic_struct *module_magic_data)
Definition: dfmgr.c:294
void(* PG_init_t)(void)
Definition: dfmgr.c:32
#define SAME_INODE(A, B)
Definition: dfmgr.c:62
int errcode_for_file_access(void)
Definition: elog.c:876
int errhint(const char *fmt,...)
Definition: elog.c:1317
#define PG_MAGIC_FUNCTION_NAME_STRING
Definition: fmgr.h:496
const Pg_magic_struct *(* PGModuleMagicFunction)(void)
Definition: fmgr.h:493
#define free(a)
Definition: header.h:65
#define malloc(a)
Definition: header.h:50
static char * filename
Definition: pg_dumpall.c:124
dev_t device
Definition: dfmgr.c:48
ino_t inode
Definition: dfmgr.c:51
void * handle
Definition: dfmgr.c:53
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 df_files::device, dlclose(), dlerror(), dlopen(), dlsym(), ereport, errcode(), errcode_for_file_access(), errhint(), errmsg(), ERROR, file_list, file_tail, df_files::filename, filename, free, df_files::handle, incompatible_module_error(), df_files::inode, Pg_magic_struct::len, magic_data, malloc, MemSet, df_files::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 93 of file dfmgr.c.

95{
96 char *fullname;
97 void *lib_handle;
98 void *retval;
99
100 /* Expand the possibly-abbreviated filename to an exact path name */
102
103 /* Load the shared library, unless we already did */
104 lib_handle = internal_load_library(fullname);
105
106 /* Return handle if caller wants it */
107 if (filehandle)
108 *filehandle = lib_handle;
109
110 /* Look up the function within the library. */
111 retval = dlsym(lib_handle, funcname);
112
113 if (retval == NULL && signalNotFound)
115 (errcode(ERRCODE_UNDEFINED_FUNCTION),
116 errmsg("could not find function \"%s\" in file \"%s\"",
117 funcname, fullname)));
118
119 pfree(fullname);
120 return retval;
121}
static char * expand_dynamic_library_name(const char *name)
Definition: dfmgr.c:406
static void * internal_load_library(const char *libname)
Definition: dfmgr.c:172
#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 132 of file dfmgr.c.

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

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

155{
156 return dlsym(filehandle, funcname);
157}

References dlsym(), and funcname.

Referenced by fetch_finfo_record().

◆ RestoreLibraryState()

void RestoreLibraryState ( char *  start_address)

Definition at line 689 of file dfmgr.c.

690{
691 while (*start_address != '\0')
692 {
693 internal_load_library(start_address);
694 start_address += strlen(start_address) + 1;
695 }
696}

References internal_load_library().

Referenced by ParallelWorkerMain().

◆ SerializeLibraryState()

void SerializeLibraryState ( Size  maxsize,
char *  start_address 
)

Definition at line 667 of file dfmgr.c.

668{
669 DynamicFileList *file_scanner;
670
671 for (file_scanner = file_list;
672 file_scanner != NULL;
673 file_scanner = file_scanner->next)
674 {
675 Size len;
676
677 len = strlcpy(start_address, file_scanner->filename, maxsize) + 1;
678 Assert(len < maxsize);
679 maxsize -= len;
680 start_address += len;
681 }
682 start_address[0] = '\0';
683}

References Assert(), file_list, df_files::filename, len, df_files::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 484 of file dfmgr.c.

485{
486 const char *sep_ptr;
487
488 Assert(str != NULL);
489 Assert(macro[0] == '$');
490
491 /* Currently, we only recognize $macro at the start of the string */
492 if (str[0] != '$')
493 return pstrdup(str);
494
495 if ((sep_ptr = first_dir_separator(str)) == NULL)
496 sep_ptr = str + strlen(str);
497
498 if (strlen(macro) != sep_ptr - str ||
499 strncmp(str, macro, strlen(macro)) != 0)
501 (errcode(ERRCODE_INVALID_NAME),
502 errmsg("invalid macro name in path: %s",
503 str)));
504
505 return psprintf("%s%s", value, sep_ptr);
506}
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 67 of file dfmgr.c.

Referenced by expand_dynamic_library_name().

◆ file_list

DynamicFileList* file_list = NULL
static

Definition at line 57 of file dfmgr.c.

Referenced by EstimateLibraryStateSpace(), internal_load_library(), and SerializeLibraryState().

◆ file_tail

DynamicFileList* file_tail = NULL
static

Definition at line 58 of file dfmgr.c.

Referenced by internal_load_library().

◆ magic_data

const Pg_magic_struct magic_data = PG_MODULE_MAGIC_DATA
static

Definition at line 76 of file dfmgr.c.

Referenced by incompatible_module_error(), and internal_load_library().