PostgreSQL Source Code  git master
dfmgr.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * dfmgr.c
4  * Dynamic function manager code.
5  *
6  * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  * src/backend/utils/fmgr/dfmgr.c
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16 
17 #include <sys/stat.h>
18 
19 #ifdef HAVE_DLOPEN
20 #include <dlfcn.h>
21 
22 /*
23  * On macOS, <dlfcn.h> insists on including <stdbool.h>. If we're not
24  * using stdbool, undef bool to undo the damage.
25  */
26 #ifndef PG_USE_STDBOOL
27 #ifdef bool
28 #undef bool
29 #endif
30 #endif
31 #endif /* HAVE_DLOPEN */
32 
33 #include "fmgr.h"
34 #include "lib/stringinfo.h"
35 #include "miscadmin.h"
36 #include "storage/shmem.h"
37 #include "utils/hsearch.h"
38 
39 
40 /* signatures for PostgreSQL-specific library init/fini functions */
41 typedef void (*PG_init_t) (void);
42 typedef void (*PG_fini_t) (void);
43 
44 /* hashtable entry for rendezvous variables */
45 typedef struct
46 {
47  char varName[NAMEDATALEN]; /* hash key (must be first) */
48  void *varValue;
50 
51 /*
52  * List of dynamically loaded files (kept in malloc'd memory).
53  */
54 
55 typedef struct df_files
56 {
57  struct df_files *next; /* List link */
58  dev_t device; /* Device file is on */
59 #ifndef WIN32 /* ensures we never again depend on this under
60  * win32 */
61  ino_t inode; /* Inode number of file */
62 #endif
63  void *handle; /* a handle for pg_dl* functions */
64  char filename[FLEXIBLE_ARRAY_MEMBER]; /* Full pathname of file */
66 
67 static DynamicFileList *file_list = NULL;
68 static DynamicFileList *file_tail = NULL;
69 
70 /* stat() call under Win32 returns an st_ino field, but it has no meaning */
71 #ifndef WIN32
72 #define SAME_INODE(A,B) ((A).st_ino == (B).inode && (A).st_dev == (B).device)
73 #else
74 #define SAME_INODE(A,B) false
75 #endif
76 
78 
79 static void *internal_load_library(const char *libname);
80 static void incompatible_module_error(const char *libname,
81  const Pg_magic_struct *module_magic_data) pg_attribute_noreturn();
82 static void internal_unload_library(const char *libname);
83 static bool file_exists(const char *name);
84 static char *expand_dynamic_library_name(const char *name);
85 static void check_restricted_library_name(const char *name);
86 static char *substitute_libpath_macro(const char *name);
87 static char *find_in_dynamic_libpath(const char *basename);
88 
89 /* Magic structure that module needs to match to be accepted */
91 
92 
93 /*
94  * Load the specified dynamic-link library file, and look for a function
95  * named funcname in it.
96  *
97  * If the function is not found, we raise an error if signalNotFound is true,
98  * else return NULL. Note that errors in loading the library
99  * will provoke ereport() regardless of signalNotFound.
100  *
101  * If filehandle is not NULL, then *filehandle will be set to a handle
102  * identifying the library file. The filehandle can be used with
103  * lookup_external_function to lookup additional functions in the same file
104  * at less cost than repeating load_external_function.
105  */
106 void *
107 load_external_function(const char *filename, const char *funcname,
108  bool signalNotFound, void **filehandle)
109 {
110  char *fullname;
111  void *lib_handle;
112  void *retval;
113 
114  /* Expand the possibly-abbreviated filename to an exact path name */
116 
117  /* Load the shared library, unless we already did */
118  lib_handle = internal_load_library(fullname);
119 
120  /* Return handle if caller wants it */
121  if (filehandle)
122  *filehandle = lib_handle;
123 
124  /* Look up the function within the library. */
125  retval = dlsym(lib_handle, funcname);
126 
127  if (retval == NULL && signalNotFound)
128  ereport(ERROR,
129  (errcode(ERRCODE_UNDEFINED_FUNCTION),
130  errmsg("could not find function \"%s\" in file \"%s\"",
131  funcname, fullname)));
132 
133  pfree(fullname);
134  return retval;
135 }
136 
137 /*
138  * This function loads a shlib file without looking up any particular
139  * function in it. If the same shlib has previously been loaded,
140  * unload and reload it.
141  *
142  * When 'restricted' is true, only libraries in the presumed-secure
143  * directory $libdir/plugins may be referenced.
144  */
145 void
146 load_file(const char *filename, bool restricted)
147 {
148  char *fullname;
149 
150  /* Apply security restriction if requested */
151  if (restricted)
153 
154  /* Expand the possibly-abbreviated filename to an exact path name */
156 
157  /* Unload the library if currently loaded */
158  internal_unload_library(fullname);
159 
160  /* Load the shared library */
161  (void) internal_load_library(fullname);
162 
163  pfree(fullname);
164 }
165 
166 /*
167  * Lookup a function whose library file is already loaded.
168  * Return NULL if not found.
169  */
170 void *
171 lookup_external_function(void *filehandle, const char *funcname)
172 {
173  return dlsym(filehandle, funcname);
174 }
175 
176 
177 /*
178  * Load the specified dynamic-link library file, unless it already is
179  * loaded. Return the pg_dl* handle for the file.
180  *
181  * Note: libname is expected to be an exact name for the library file.
182  */
183 static void *
184 internal_load_library(const char *libname)
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 }
301 
302 /*
303  * Report a suitable error for an incompatible magic block.
304  */
305 static void
306 incompatible_module_error(const char *libname,
307  const Pg_magic_struct *module_magic_data)
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 }
402 
403 /*
404  * Unload the specified dynamic-link library file, if it is loaded.
405  *
406  * Note: libname is expected to be an exact name for the library file.
407  *
408  * XXX for the moment, this is disabled, resulting in LOAD of an already-loaded
409  * library always being a no-op. We might re-enable it someday if we can
410  * convince ourselves we have safe protocols for un-hooking from hook function
411  * pointers, releasing custom GUC variables, and perhaps other things that
412  * are definitely unsafe currently.
413  */
414 static void
415 internal_unload_library(const char *libname)
416 {
417 #ifdef NOT_USED
418  DynamicFileList *file_scanner,
419  *prv,
420  *nxt;
421  struct stat stat_buf;
422  PG_fini_t PG_fini;
423 
424  /*
425  * We need to do stat() in order to determine whether this is the same
426  * file as a previously loaded file; it's also handy so as to give a good
427  * error message if bogus file name given.
428  */
429  if (stat(libname, &stat_buf) == -1)
430  ereport(ERROR,
432  errmsg("could not access file \"%s\": %m", libname)));
433 
434  /*
435  * We have to zap all entries in the list that match on either filename or
436  * inode, else internal_load_library() will still think it's present.
437  */
438  prv = NULL;
439  for (file_scanner = file_list; file_scanner != NULL; file_scanner = nxt)
440  {
441  nxt = file_scanner->next;
442  if (strcmp(libname, file_scanner->filename) == 0 ||
443  SAME_INODE(stat_buf, *file_scanner))
444  {
445  if (prv)
446  prv->next = nxt;
447  else
448  file_list = nxt;
449 
450  /*
451  * If the library has a _PG_fini() function, call it.
452  */
453  PG_fini = (PG_fini_t) dlsym(file_scanner->handle, "_PG_fini");
454  if (PG_fini)
455  (*PG_fini) ();
456 
457  clear_external_function_hash(file_scanner->handle);
458  dlclose(file_scanner->handle);
459  free((char *) file_scanner);
460  /* prv does not change */
461  }
462  else
463  prv = file_scanner;
464  }
465 #endif /* NOT_USED */
466 }
467 
468 static bool
469 file_exists(const char *name)
470 {
471  struct stat st;
472 
473  AssertArg(name != NULL);
474 
475  if (stat(name, &st) == 0)
476  return !S_ISDIR(st.st_mode);
477  else if (!(errno == ENOENT || errno == ENOTDIR || errno == EACCES))
478  ereport(ERROR,
480  errmsg("could not access file \"%s\": %m", name)));
481 
482  return false;
483 }
484 
485 
486 /* Example format: ".so" */
487 #ifndef DLSUFFIX
488 #error "DLSUFFIX must be defined to compile this file."
489 #endif
490 
491 /*
492  * If name contains a slash, check if the file exists, if so return
493  * the name. Else (no slash) try to expand using search path (see
494  * find_in_dynamic_libpath below); if that works, return the fully
495  * expanded file name. If the previous failed, append DLSUFFIX and
496  * try again. If all fails, just return the original name.
497  *
498  * The result will always be freshly palloc'd.
499  */
500 static char *
502 {
503  bool have_slash;
504  char *new;
505  char *full;
506 
507  AssertArg(name);
508 
509  have_slash = (first_dir_separator(name) != NULL);
510 
511  if (!have_slash)
512  {
514  if (full)
515  return full;
516  }
517  else
518  {
520  if (file_exists(full))
521  return full;
522  pfree(full);
523  }
524 
525  new = psprintf("%s%s", name, DLSUFFIX);
526 
527  if (!have_slash)
528  {
529  full = find_in_dynamic_libpath(new);
530  pfree(new);
531  if (full)
532  return full;
533  }
534  else
535  {
536  full = substitute_libpath_macro(new);
537  pfree(new);
538  if (file_exists(full))
539  return full;
540  pfree(full);
541  }
542 
543  /*
544  * If we can't find the file, just return the string as-is. The ensuing
545  * load attempt will fail and report a suitable message.
546  */
547  return pstrdup(name);
548 }
549 
550 /*
551  * Check a restricted library name. It must begin with "$libdir/plugins/"
552  * and there must not be any directory separators after that (this is
553  * sufficient to prevent ".." style attacks).
554  */
555 static void
557 {
558  if (strncmp(name, "$libdir/plugins/", 16) != 0 ||
559  first_dir_separator(name + 16) != NULL)
560  ereport(ERROR,
561  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
562  errmsg("access to library \"%s\" is not allowed",
563  name)));
564 }
565 
566 /*
567  * Substitute for any macros appearing in the given string.
568  * Result is always freshly palloc'd.
569  */
570 static char *
572 {
573  const char *sep_ptr;
574 
575  AssertArg(name != NULL);
576 
577  /* Currently, we only recognize $libdir at the start of the string */
578  if (name[0] != '$')
579  return pstrdup(name);
580 
581  if ((sep_ptr = first_dir_separator(name)) == NULL)
582  sep_ptr = name + strlen(name);
583 
584  if (strlen("$libdir") != sep_ptr - name ||
585  strncmp(name, "$libdir", strlen("$libdir")) != 0)
586  ereport(ERROR,
587  (errcode(ERRCODE_INVALID_NAME),
588  errmsg("invalid macro name in dynamic library path: %s",
589  name)));
590 
591  return psprintf("%s%s", pkglib_path, sep_ptr);
592 }
593 
594 
595 /*
596  * Search for a file called 'basename' in the colon-separated search
597  * path Dynamic_library_path. If the file is found, the full file name
598  * is returned in freshly palloc'd memory. If the file is not found,
599  * return NULL.
600  */
601 static char *
602 find_in_dynamic_libpath(const char *basename)
603 {
604  const char *p;
605  size_t baselen;
606 
607  AssertArg(basename != NULL);
608  AssertArg(first_dir_separator(basename) == NULL);
610 
612  if (strlen(p) == 0)
613  return NULL;
614 
615  baselen = strlen(basename);
616 
617  for (;;)
618  {
619  size_t len;
620  char *piece;
621  char *mangled;
622  char *full;
623 
624  piece = first_path_var_separator(p);
625  if (piece == p)
626  ereport(ERROR,
627  (errcode(ERRCODE_INVALID_NAME),
628  errmsg("zero-length component in parameter \"dynamic_library_path\"")));
629 
630  if (piece == NULL)
631  len = strlen(p);
632  else
633  len = piece - p;
634 
635  piece = palloc(len + 1);
636  strlcpy(piece, p, len + 1);
637 
638  mangled = substitute_libpath_macro(piece);
639  pfree(piece);
640 
641  canonicalize_path(mangled);
642 
643  /* only absolute paths */
644  if (!is_absolute_path(mangled))
645  ereport(ERROR,
646  (errcode(ERRCODE_INVALID_NAME),
647  errmsg("component in parameter \"dynamic_library_path\" is not an absolute path")));
648 
649  full = palloc(strlen(mangled) + 1 + baselen + 1);
650  sprintf(full, "%s/%s", mangled, basename);
651  pfree(mangled);
652 
653  elog(DEBUG3, "find_in_dynamic_libpath: trying \"%s\"", full);
654 
655  if (file_exists(full))
656  return full;
657 
658  pfree(full);
659 
660  if (p[len] == '\0')
661  break;
662  else
663  p += len + 1;
664  }
665 
666  return NULL;
667 }
668 
669 
670 /*
671  * Find (or create) a rendezvous variable that one dynamically
672  * loaded library can use to meet up with another.
673  *
674  * On the first call of this function for a particular varName,
675  * a "rendezvous variable" is created with the given name.
676  * The value of the variable is a void pointer (initially set to NULL).
677  * Subsequent calls with the same varName just return the address of
678  * the existing variable. Once created, a rendezvous variable lasts
679  * for the life of the process.
680  *
681  * Dynamically loaded libraries can use rendezvous variables
682  * to find each other and share information: they just need to agree
683  * on the variable name and the data it will point to.
684  */
685 void **
686 find_rendezvous_variable(const char *varName)
687 {
688  static HTAB *rendezvousHash = NULL;
689 
690  rendezvousHashEntry *hentry;
691  bool found;
692 
693  /* Create a hashtable if we haven't already done so in this process */
694  if (rendezvousHash == NULL)
695  {
696  HASHCTL ctl;
697 
698  ctl.keysize = NAMEDATALEN;
699  ctl.entrysize = sizeof(rendezvousHashEntry);
700  rendezvousHash = hash_create("Rendezvous variable hash",
701  16,
702  &ctl,
704  }
705 
706  /* Find or create the hashtable entry for this varName */
707  hentry = (rendezvousHashEntry *) hash_search(rendezvousHash,
708  varName,
709  HASH_ENTER,
710  &found);
711 
712  /* Initialize to NULL if first time */
713  if (!found)
714  hentry->varValue = NULL;
715 
716  return &hentry->varValue;
717 }
718 
719 /*
720  * Estimate the amount of space needed to serialize the list of libraries
721  * we have loaded.
722  */
723 Size
725 {
726  DynamicFileList *file_scanner;
727  Size size = 1;
728 
729  for (file_scanner = file_list;
730  file_scanner != NULL;
731  file_scanner = file_scanner->next)
732  size = add_size(size, strlen(file_scanner->filename) + 1);
733 
734  return size;
735 }
736 
737 /*
738  * Serialize the list of libraries we have loaded to a chunk of memory.
739  */
740 void
741 SerializeLibraryState(Size maxsize, char *start_address)
742 {
743  DynamicFileList *file_scanner;
744 
745  for (file_scanner = file_list;
746  file_scanner != NULL;
747  file_scanner = file_scanner->next)
748  {
749  Size len;
750 
751  len = strlcpy(start_address, file_scanner->filename, maxsize) + 1;
752  Assert(len < maxsize);
753  maxsize -= len;
754  start_address += len;
755  }
756  start_address[0] = '\0';
757 }
758 
759 /*
760  * Load every library the serializing backend had loaded.
761  */
762 void
763 RestoreLibraryState(char *start_address)
764 {
765  while (*start_address != '\0')
766  {
767  internal_load_library(start_address);
768  start_address += strlen(start_address) + 1;
769  }
770 }
#define AssertState(condition)
Definition: c.h:807
#define offsetof(type, field)
Definition: c.h:727
#define pg_attribute_noreturn()
Definition: c.h:179
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:350
#define MemSet(start, val, len)
Definition: c.h:1008
size_t Size
Definition: c.h:540
#define AssertArg(condition)
Definition: c.h:806
static char * expand_dynamic_library_name(const char *name)
Definition: dfmgr.c:501
static DynamicFileList * file_tail
Definition: dfmgr.c:68
static void internal_unload_library(const char *libname)
Definition: dfmgr.c:415
static char * find_in_dynamic_libpath(const char *basename)
Definition: dfmgr.c:602
void RestoreLibraryState(char *start_address)
Definition: dfmgr.c:763
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
Definition: dfmgr.c:107
void(* PG_fini_t)(void)
Definition: dfmgr.c:42
char * Dynamic_library_path
Definition: dfmgr.c:77
static char * substitute_libpath_macro(const char *name)
Definition: dfmgr.c:571
static void incompatible_module_error(const char *libname, const Pg_magic_struct *module_magic_data) pg_attribute_noreturn()
Definition: dfmgr.c:306
static void * internal_load_library(const char *libname)
Definition: dfmgr.c:184
void SerializeLibraryState(Size maxsize, char *start_address)
Definition: dfmgr.c:741
void load_file(const char *filename, bool restricted)
Definition: dfmgr.c:146
static const Pg_magic_struct magic_data
Definition: dfmgr.c:90
Size EstimateLibraryStateSpace(void)
Definition: dfmgr.c:724
void ** find_rendezvous_variable(const char *varName)
Definition: dfmgr.c:686
static DynamicFileList * file_list
Definition: dfmgr.c:67
void(* PG_init_t)(void)
Definition: dfmgr.c:41
struct df_files DynamicFileList
static void check_restricted_library_name(const char *name)
Definition: dfmgr.c:556
#define SAME_INODE(A, B)
Definition: dfmgr.c:72
void * lookup_external_function(void *filehandle, const char *funcname)
Definition: dfmgr.c:171
static bool file_exists(const char *name)
Definition: dfmgr.c:469
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
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1064
int errcode_for_file_access(void)
Definition: elog.c:716
int errdetail(const char *fmt,...)
Definition: elog.c:1037
int errhint(const char *fmt,...)
Definition: elog.c:1151
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define _(x)
Definition: elog.c:89
#define DEBUG3
Definition: elog.h:22
#define ERROR
Definition: elog.h:33
#define elog(elevel,...)
Definition: elog.h:218
#define ereport(elevel,...)
Definition: elog.h:143
const char * name
Definition: encode.c:561
void clear_external_function_hash(void *filehandle)
Definition: fmgr.c:592
#define PG_MAGIC_FUNCTION_NAME_STRING
Definition: fmgr.h:486
const Pg_magic_struct *(* PGModuleMagicFunction)(void)
Definition: fmgr.h:483
#define PG_MODULE_MAGIC_DATA
Definition: fmgr.h:465
char pkglib_path[MAXPGPATH]
Definition: globals.c:76
#define free(a)
Definition: header.h:65
#define malloc(a)
Definition: header.h:50
#define HASH_STRINGS
Definition: hsearch.h:96
@ HASH_ENTER
Definition: hsearch.h:114
#define HASH_ELEM
Definition: hsearch.h:95
Assert(fmt[strlen(fmt) - 1] !='\n')
char * pstrdup(const char *in)
Definition: mcxt.c:1299
void pfree(void *pointer)
Definition: mcxt.c:1169
void * palloc(Size size)
Definition: mcxt.c:1062
#define NAMEDATALEN
const void size_t len
static char * filename
Definition: pg_dumpall.c:92
#define is_absolute_path(filename)
Definition: port.h:89
char * first_dir_separator(const char *filename)
Definition: path.c:103
char * dlerror(void)
#define sprintf
Definition: port.h:227
void canonicalize_path(char *path)
Definition: path.c:254
void * dlsym(void *handle, const char *symbol)
void * dlopen(const char *file, int mode)
#define RTLD_NOW
Definition: port.h:474
char * first_path_var_separator(const char *pathlist)
Definition: path.c:120
#define snprintf
Definition: port.h:225
#define RTLD_GLOBAL
Definition: port.h:482
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45
int dlclose(void *handle)
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
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
Size keysize
Definition: hsearch.h:75
Size entrysize
Definition: hsearch.h:76
Definition: dynahash.c:220
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
Definition: dfmgr.c:56
dev_t device
Definition: dfmgr.c:58
ino_t inode
Definition: dfmgr.c:61
void * handle
Definition: dfmgr.c:63
struct df_files * next
Definition: dfmgr.c:57
char filename[FLEXIBLE_ARRAY_MEMBER]
Definition: dfmgr.c:64
void * varValue
Definition: dfmgr.c:48
unsigned short st_mode
Definition: win32_port.h:268
_dev_t st_dev
Definition: win32_port.h:266
_ino_t st_ino
Definition: win32_port.h:267
#define stat
Definition: win32_port.h:283
#define S_ISDIR(m)
Definition: win32_port.h:324