PostgreSQL Source Code  git master
dfmgr.c File Reference
#include "postgres.h"
#include <sys/stat.h>
#include "fmgr.h"
#include "lib/stringinfo.h"
#include "miscadmin.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 void incompatible_module_error (const char *libname, const Pg_magic_struct *module_magic_data) pg_attribute_noreturn()
 
static bool file_exists (const char *name)
 
static char * expand_dynamic_library_name (const char *name)
 
static void check_restricted_library_name (const char *name)
 
static char * substitute_libpath_macro (const char *name)
 
static char * find_in_dynamic_libpath (const char *basename)
 
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)
 
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 71 of file dfmgr.c.

Typedef Documentation

◆ DynamicFileList

typedef struct df_files DynamicFileList

◆ PG_init_t

typedef void(* PG_init_t) (void)

Definition at line 41 of file dfmgr.c.

Function Documentation

◆ check_restricted_library_name()

static void check_restricted_library_name ( const char *  name)
static

Definition at line 486 of file dfmgr.c.

487 {
488  if (strncmp(name, "$libdir/plugins/", 16) != 0 ||
489  first_dir_separator(name + 16) != NULL)
490  ereport(ERROR,
491  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
492  errmsg("access to library \"%s\" is not allowed",
493  name)));
494 }
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
const char * name
Definition: encode.c:561
char * first_dir_separator(const char *filename)
Definition: path.c:104

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

Referenced by load_file().

◆ EstimateLibraryStateSpace()

Size EstimateLibraryStateSpace ( void  )

Definition at line 654 of file dfmgr.c.

655 {
656  DynamicFileList *file_scanner;
657  Size size = 1;
658 
659  for (file_scanner = file_list;
660  file_scanner != NULL;
661  file_scanner = file_scanner->next)
662  size = add_size(size, strlen(file_scanner->filename) + 1);
663 
664  return size;
665 }
size_t Size
Definition: c.h:540
static DynamicFileList * file_list
Definition: dfmgr.c:66
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
Definition: dfmgr.c:55
struct df_files * next
Definition: dfmgr.c:56
char filename[FLEXIBLE_ARRAY_MEMBER]
Definition: dfmgr.c:63

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

432 {
433  bool have_slash;
434  char *new;
435  char *full;
436 
437  AssertArg(name);
438 
439  have_slash = (first_dir_separator(name) != NULL);
440 
441  if (!have_slash)
442  {
444  if (full)
445  return full;
446  }
447  else
448  {
450  if (file_exists(full))
451  return full;
452  pfree(full);
453  }
454 
455  new = psprintf("%s%s", name, DLSUFFIX);
456 
457  if (!have_slash)
458  {
459  full = find_in_dynamic_libpath(new);
460  pfree(new);
461  if (full)
462  return full;
463  }
464  else
465  {
466  full = substitute_libpath_macro(new);
467  pfree(new);
468  if (file_exists(full))
469  return full;
470  pfree(full);
471  }
472 
473  /*
474  * If we can't find the file, just return the string as-is. The ensuing
475  * load attempt will fail and report a suitable message.
476  */
477  return pstrdup(name);
478 }
#define AssertArg(condition)
Definition: c.h:806
static char * find_in_dynamic_libpath(const char *basename)
Definition: dfmgr.c:532
static char * substitute_libpath_macro(const char *name)
Definition: dfmgr.c:501
static bool file_exists(const char *name)
Definition: dfmgr.c:404
char * pstrdup(const char *in)
Definition: mcxt.c:1305
void pfree(void *pointer)
Definition: mcxt.c:1175
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46

References AssertArg, file_exists(), find_in_dynamic_libpath(), first_dir_separator(), name, pfree(), psprintf(), pstrdup(), and substitute_libpath_macro().

Referenced by load_external_function(), and load_file().

◆ file_exists()

static bool file_exists ( const char *  name)
static

Definition at line 404 of file dfmgr.c.

405 {
406  struct stat st;
407 
408  AssertArg(name != NULL);
409 
410  if (stat(name, &st) == 0)
411  return !S_ISDIR(st.st_mode);
412  else if (!(errno == ENOENT || errno == ENOTDIR || errno == EACCES))
413  ereport(ERROR,
415  errmsg("could not access file \"%s\": %m", name)));
416 
417  return false;
418 }
int errcode_for_file_access(void)
Definition: elog.c:716
#define stat
Definition: win32_port.h:283
#define S_ISDIR(m)
Definition: win32_port.h:324

References AssertArg, ereport, errcode_for_file_access(), errmsg(), ERROR, name, S_ISDIR, stat::st_mode, and stat.

Referenced by expand_dynamic_library_name(), and find_in_dynamic_libpath().

◆ find_in_dynamic_libpath()

static char * find_in_dynamic_libpath ( const char *  basename)
static

Definition at line 532 of file dfmgr.c.

533 {
534  const char *p;
535  size_t baselen;
536 
537  AssertArg(basename != NULL);
538  AssertArg(first_dir_separator(basename) == NULL);
540 
542  if (strlen(p) == 0)
543  return NULL;
544 
545  baselen = strlen(basename);
546 
547  for (;;)
548  {
549  size_t len;
550  char *piece;
551  char *mangled;
552  char *full;
553 
554  piece = first_path_var_separator(p);
555  if (piece == p)
556  ereport(ERROR,
557  (errcode(ERRCODE_INVALID_NAME),
558  errmsg("zero-length component in parameter \"dynamic_library_path\"")));
559 
560  if (piece == NULL)
561  len = strlen(p);
562  else
563  len = piece - p;
564 
565  piece = palloc(len + 1);
566  strlcpy(piece, p, len + 1);
567 
568  mangled = substitute_libpath_macro(piece);
569  pfree(piece);
570 
571  canonicalize_path(mangled);
572 
573  /* only absolute paths */
574  if (!is_absolute_path(mangled))
575  ereport(ERROR,
576  (errcode(ERRCODE_INVALID_NAME),
577  errmsg("component in parameter \"dynamic_library_path\" is not an absolute path")));
578 
579  full = palloc(strlen(mangled) + 1 + baselen + 1);
580  sprintf(full, "%s/%s", mangled, basename);
581  pfree(mangled);
582 
583  elog(DEBUG3, "find_in_dynamic_libpath: trying \"%s\"", full);
584 
585  if (file_exists(full))
586  return full;
587 
588  pfree(full);
589 
590  if (p[len] == '\0')
591  break;
592  else
593  p += len + 1;
594  }
595 
596  return NULL;
597 }
#define AssertState(condition)
Definition: c.h:807
char * Dynamic_library_path
Definition: dfmgr.c:76
#define DEBUG3
Definition: elog.h:22
#define elog(elevel,...)
Definition: elog.h:218
void * palloc(Size size)
Definition: mcxt.c:1068
const void size_t len
#define is_absolute_path(filename)
Definition: port.h:89
#define sprintf
Definition: port.h:227
void canonicalize_path(char *path)
Definition: path.c:264
char * first_path_var_separator(const char *pathlist)
Definition: path.c:121
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45

References AssertArg, AssertState, canonicalize_path(), DEBUG3, Dynamic_library_path, elog, ereport, errcode(), errmsg(), ERROR, file_exists(), first_dir_separator(), first_path_var_separator(), is_absolute_path, len, palloc(), pfree(), sprintf, strlcpy(), and substitute_libpath_macro().

Referenced by expand_dynamic_library_name().

◆ find_rendezvous_variable()

void** find_rendezvous_variable ( const char *  varName)

Definition at line 616 of file dfmgr.c.

617 {
618  static HTAB *rendezvousHash = NULL;
619 
620  rendezvousHashEntry *hentry;
621  bool found;
622 
623  /* Create a hashtable if we haven't already done so in this process */
624  if (rendezvousHash == NULL)
625  {
626  HASHCTL ctl;
627 
628  ctl.keysize = NAMEDATALEN;
629  ctl.entrysize = sizeof(rendezvousHashEntry);
630  rendezvousHash = hash_create("Rendezvous variable hash",
631  16,
632  &ctl,
634  }
635 
636  /* Find or create the hashtable entry for this varName */
637  hentry = (rendezvousHashEntry *) hash_search(rendezvousHash,
638  varName,
639  HASH_ENTER,
640  &found);
641 
642  /* Initialize to NULL if first time */
643  if (!found)
644  hentry->varValue = NULL;
645 
646  return &hentry->varValue;
647 }
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:349
#define HASH_STRINGS
Definition: hsearch.h:96
@ HASH_ENTER
Definition: hsearch.h:114
#define HASH_ELEM
Definition: hsearch.h:95
#define NAMEDATALEN
Size keysize
Definition: hsearch.h:75
Size entrysize
Definition: hsearch.h:76
Definition: dynahash.c:220
void * varValue
Definition: dfmgr.c:47

References HASHCTL::entrysize, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), HASH_STRINGS, HASHCTL::keysize, 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 306 of file dfmgr.c.

308 {
309  StringInfoData details;
310 
311  /*
312  * If the version doesn't match, just report that, because the rest of the
313  * block might not even have the fields we expect.
314  */
315  if (magic_data.version != module_magic_data->version)
316  {
317  char library_version[32];
318 
319  if (module_magic_data->version >= 1000)
320  snprintf(library_version, sizeof(library_version), "%d",
321  module_magic_data->version / 100);
322  else
323  snprintf(library_version, sizeof(library_version), "%d.%d",
324  module_magic_data->version / 100,
325  module_magic_data->version % 100);
326  ereport(ERROR,
327  (errmsg("incompatible library \"%s\": version mismatch",
328  libname),
329  errdetail("Server is version %d, library is version %s.",
330  magic_data.version / 100, library_version)));
331  }
332 
333  /*
334  * Similarly, if the ABI extra field doesn't match, error out. Other
335  * fields below might also mismatch, but that isn't useful information if
336  * you're using the wrong product altogether.
337  */
338  if (strcmp(module_magic_data->abi_extra, magic_data.abi_extra) != 0)
339  {
340  ereport(ERROR,
341  (errmsg("incompatible library \"%s\": ABI mismatch",
342  libname),
343  errdetail("Server has ABI \"%s\", library has \"%s\".",
345  module_magic_data->abi_extra)));
346  }
347 
348  /*
349  * Otherwise, spell out which fields don't agree.
350  *
351  * XXX this code has to be adjusted any time the set of fields in a magic
352  * block change!
353  */
354  initStringInfo(&details);
355 
356  if (module_magic_data->funcmaxargs != magic_data.funcmaxargs)
357  {
358  if (details.len)
359  appendStringInfoChar(&details, '\n');
360  appendStringInfo(&details,
361  _("Server has FUNC_MAX_ARGS = %d, library has %d."),
363  module_magic_data->funcmaxargs);
364  }
365  if (module_magic_data->indexmaxkeys != magic_data.indexmaxkeys)
366  {
367  if (details.len)
368  appendStringInfoChar(&details, '\n');
369  appendStringInfo(&details,
370  _("Server has INDEX_MAX_KEYS = %d, library has %d."),
372  module_magic_data->indexmaxkeys);
373  }
374  if (module_magic_data->namedatalen != magic_data.namedatalen)
375  {
376  if (details.len)
377  appendStringInfoChar(&details, '\n');
378  appendStringInfo(&details,
379  _("Server has NAMEDATALEN = %d, library has %d."),
381  module_magic_data->namedatalen);
382  }
383  if (module_magic_data->float8byval != magic_data.float8byval)
384  {
385  if (details.len)
386  appendStringInfoChar(&details, '\n');
387  appendStringInfo(&details,
388  _("Server has FLOAT8PASSBYVAL = %s, library has %s."),
389  magic_data.float8byval ? "true" : "false",
390  module_magic_data->float8byval ? "true" : "false");
391  }
392 
393  if (details.len == 0)
394  appendStringInfoString(&details,
395  _("Magic block has unexpected length or padding difference."));
396 
397  ereport(ERROR,
398  (errmsg("incompatible library \"%s\": magic block mismatch",
399  libname),
400  errdetail_internal("%s", details.data)));
401 }
static const Pg_magic_struct magic_data
Definition: dfmgr.c:88
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1064
int errdetail(const char *fmt,...)
Definition: elog.c:1037
#define _(x)
Definition: elog.c:89
#define snprintf
Definition: port.h:225
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
void appendStringInfoChar(StringInfo str, char ch)
Definition: stringinfo.c:188
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
char abi_extra[32]
Definition: fmgr.h:461
int float8byval
Definition: fmgr.h:460
int funcmaxargs
Definition: fmgr.h:457
int indexmaxkeys
Definition: fmgr.h:458
int namedatalen
Definition: fmgr.h:459
int version
Definition: fmgr.h:456

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

185 {
186  DynamicFileList *file_scanner;
187  PGModuleMagicFunction magic_func;
188  char *load_error;
189  struct stat stat_buf;
190  PG_init_t PG_init;
191 
192  /*
193  * Scan the list of loaded FILES to see if the file has been loaded.
194  */
195  for (file_scanner = file_list;
196  file_scanner != NULL &&
197  strcmp(libname, file_scanner->filename) != 0;
198  file_scanner = file_scanner->next)
199  ;
200 
201  if (file_scanner == NULL)
202  {
203  /*
204  * Check for same files - different paths (ie, symlink or link)
205  */
206  if (stat(libname, &stat_buf) == -1)
207  ereport(ERROR,
209  errmsg("could not access file \"%s\": %m",
210  libname)));
211 
212  for (file_scanner = file_list;
213  file_scanner != NULL &&
214  !SAME_INODE(stat_buf, *file_scanner);
215  file_scanner = file_scanner->next)
216  ;
217  }
218 
219  if (file_scanner == NULL)
220  {
221  /*
222  * File not loaded yet.
223  */
224  file_scanner = (DynamicFileList *)
225  malloc(offsetof(DynamicFileList, filename) + strlen(libname) + 1);
226  if (file_scanner == NULL)
227  ereport(ERROR,
228  (errcode(ERRCODE_OUT_OF_MEMORY),
229  errmsg("out of memory")));
230 
231  MemSet(file_scanner, 0, offsetof(DynamicFileList, filename));
232  strcpy(file_scanner->filename, libname);
233  file_scanner->device = stat_buf.st_dev;
234 #ifndef WIN32
235  file_scanner->inode = stat_buf.st_ino;
236 #endif
237  file_scanner->next = NULL;
238 
239  file_scanner->handle = dlopen(file_scanner->filename, RTLD_NOW | RTLD_GLOBAL);
240  if (file_scanner->handle == NULL)
241  {
242  load_error = dlerror();
243  free((char *) file_scanner);
244  /* errcode_for_file_access might not be appropriate here? */
245  ereport(ERROR,
247  errmsg("could not load library \"%s\": %s",
248  libname, load_error)));
249  }
250 
251  /* Check the magic function to determine compatibility */
252  magic_func = (PGModuleMagicFunction)
254  if (magic_func)
255  {
256  const Pg_magic_struct *magic_data_ptr = (*magic_func) ();
257 
258  if (magic_data_ptr->len != magic_data.len ||
259  memcmp(magic_data_ptr, &magic_data, magic_data.len) != 0)
260  {
261  /* copy data block before unlinking library */
262  Pg_magic_struct module_magic_data = *magic_data_ptr;
263 
264  /* try to close library */
265  dlclose(file_scanner->handle);
266  free((char *) file_scanner);
267 
268  /* issue suitable complaint */
269  incompatible_module_error(libname, &module_magic_data);
270  }
271  }
272  else
273  {
274  /* try to close library */
275  dlclose(file_scanner->handle);
276  free((char *) file_scanner);
277  /* complain */
278  ereport(ERROR,
279  (errmsg("incompatible library \"%s\": missing magic block",
280  libname),
281  errhint("Extension libraries are required to use the PG_MODULE_MAGIC macro.")));
282  }
283 
284  /*
285  * If the library has a _PG_init() function, call it.
286  */
287  PG_init = (PG_init_t) dlsym(file_scanner->handle, "_PG_init");
288  if (PG_init)
289  (*PG_init) ();
290 
291  /* OK to link it into list */
292  if (file_list == NULL)
293  file_list = file_scanner;
294  else
295  file_tail->next = file_scanner;
296  file_tail = file_scanner;
297  }
298 
299  return file_scanner->handle;
300 }
#define offsetof(type, field)
Definition: c.h:727
#define MemSet(start, val, len)
Definition: c.h:1008
static DynamicFileList * file_tail
Definition: dfmgr.c:67
static void incompatible_module_error(const char *libname, const Pg_magic_struct *module_magic_data) pg_attribute_noreturn()
Definition: dfmgr.c:306
void(* PG_init_t)(void)
Definition: dfmgr.c:41
#define SAME_INODE(A, B)
Definition: dfmgr.c:71
int errhint(const char *fmt,...)
Definition: elog.c:1151
#define PG_MAGIC_FUNCTION_NAME_STRING
Definition: fmgr.h:486
const Pg_magic_struct *(* PGModuleMagicFunction)(void)
Definition: fmgr.h:483
#define free(a)
Definition: header.h:65
#define malloc(a)
Definition: header.h:50
static char * filename
Definition: pg_dumpall.c:94
char * dlerror(void)
void * dlsym(void *handle, const char *symbol)
void * dlopen(const char *file, int mode)
#define RTLD_NOW
Definition: port.h:474
#define RTLD_GLOBAL
Definition: port.h:482
int dlclose(void *handle)
dev_t device
Definition: dfmgr.c:57
ino_t inode
Definition: dfmgr.c:60
void * handle
Definition: dfmgr.c:62

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, offsetof, 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 105 of file dfmgr.c.

107 {
108  char *fullname;
109  void *lib_handle;
110  void *retval;
111 
112  /* Expand the possibly-abbreviated filename to an exact path name */
114 
115  /* Load the shared library, unless we already did */
116  lib_handle = internal_load_library(fullname);
117 
118  /* Return handle if caller wants it */
119  if (filehandle)
120  *filehandle = lib_handle;
121 
122  /* Look up the function within the library. */
123  retval = dlsym(lib_handle, funcname);
124 
125  if (retval == NULL && signalNotFound)
126  ereport(ERROR,
127  (errcode(ERRCODE_UNDEFINED_FUNCTION),
128  errmsg("could not find function \"%s\" in file \"%s\"",
129  funcname, fullname)));
130 
131  pfree(fullname);
132  return retval;
133 }
static char * expand_dynamic_library_name(const char *name)
Definition: dfmgr.c:431
static void * internal_load_library(const char *libname)
Definition: dfmgr.c:184

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

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

◆ load_file()

void load_file ( const char *  filename,
bool  restricted 
)

Definition at line 144 of file dfmgr.c.

145 {
146  char *fullname;
147 
148  /* Apply security restriction if requested */
149  if (restricted)
151 
152  /* Expand the possibly-abbreviated filename to an exact path name */
154 
155  /* Load the shared library */
156  (void) internal_load_library(fullname);
157 
158  pfree(fullname);
159 }
static void check_restricted_library_name(const char *name)
Definition: dfmgr.c:486

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

Referenced by AlterSubscription(), AlterSubscription_refresh(), ApplyWorkerMain(), CreateSubscription(), DropSubscription(), load_libraries(), ReplicationSlotDropAtPubNode(), standard_ProcessUtility(), and WalReceiverMain().

◆ lookup_external_function()

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

Definition at line 166 of file dfmgr.c.

167 {
168  return dlsym(filehandle, funcname);
169 }

References dlsym().

Referenced by fetch_finfo_record().

◆ RestoreLibraryState()

void RestoreLibraryState ( char *  start_address)

Definition at line 693 of file dfmgr.c.

694 {
695  while (*start_address != '\0')
696  {
697  internal_load_library(start_address);
698  start_address += strlen(start_address) + 1;
699  }
700 }

References internal_load_library().

Referenced by ParallelWorkerMain().

◆ SerializeLibraryState()

void SerializeLibraryState ( Size  maxsize,
char *  start_address 
)

Definition at line 671 of file dfmgr.c.

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

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

Referenced by InitializeParallelDSM().

◆ substitute_libpath_macro()

static char * substitute_libpath_macro ( const char *  name)
static

Definition at line 501 of file dfmgr.c.

502 {
503  const char *sep_ptr;
504 
505  AssertArg(name != NULL);
506 
507  /* Currently, we only recognize $libdir at the start of the string */
508  if (name[0] != '$')
509  return pstrdup(name);
510 
511  if ((sep_ptr = first_dir_separator(name)) == NULL)
512  sep_ptr = name + strlen(name);
513 
514  if (strlen("$libdir") != sep_ptr - name ||
515  strncmp(name, "$libdir", strlen("$libdir")) != 0)
516  ereport(ERROR,
517  (errcode(ERRCODE_INVALID_NAME),
518  errmsg("invalid macro name in dynamic library path: %s",
519  name)));
520 
521  return psprintf("%s%s", pkglib_path, sep_ptr);
522 }
char pkglib_path[MAXPGPATH]
Definition: globals.c:77

References AssertArg, ereport, errcode(), errmsg(), ERROR, first_dir_separator(), name, pkglib_path, psprintf(), and pstrdup().

Referenced by expand_dynamic_library_name(), and find_in_dynamic_libpath().

Variable Documentation

◆ Dynamic_library_path

char* Dynamic_library_path

Definition at line 76 of file dfmgr.c.

Referenced by find_in_dynamic_libpath().

◆ file_list

DynamicFileList* file_list = NULL
static

Definition at line 66 of file dfmgr.c.

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

◆ file_tail

DynamicFileList* file_tail = NULL
static

Definition at line 67 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 88 of file dfmgr.c.

Referenced by incompatible_module_error(), and internal_load_library().