PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
linux.c File Reference
#include "postgres.h"
#include "dynloader.h"
#include "miscadmin.h"
Include dependency graph for linux.c:

Go to the source code of this file.

Functions

void * pg_dlopen (char *filename)
 
PGFunction pg_dlsym (void *handle, char *funcname)
 
void pg_dlclose (void *handle)
 
char * pg_dlerror (void)
 

Function Documentation

void pg_dlclose ( void *  handle)

Definition at line 114 of file linux.c.

References FALSE, and free.

115 {
116 #ifndef HAVE_DLD_H
117 #else
118  dld_unlink_by_file(handle, 1);
119  free(handle);
120 #endif
121 }
#define free(a)
Definition: header.h:65
char* pg_dlerror ( void  )

Definition at line 124 of file linux.c.

References cofiff_result, and NULL.

125 {
126 #ifndef HAVE_DLD_H
127  return "dynaloader unsupported";
128 #else
129  return dld_strerror(dld_errno);
130 #endif
131 }
void* pg_dlopen ( char *  filename)

Definition at line 32 of file linux.c.

References cofiff_result, elog, ERROR, sort-test::list, my_exec_path, NULL, and WARNING.

33 {
34 #ifndef HAVE_DLD_H
35  elog(ERROR, "dynamic load not supported");
36  return NULL;
37 #else
38  static int dl_initialized = 0;
39 
40  /*
41  * initializes the dynamic loader with the executable's pathname. (only
42  * needs to do this the first time pg_dlopen is called.)
43  */
44  if (!dl_initialized)
45  {
46  if (dld_init(dld_find_executable(my_exec_path)))
47  return NULL;
48 
49  /*
50  * if there are undefined symbols, we want dl to search from the
51  * following libraries also.
52  */
53  dl_initialized = 1;
54  }
55 
56  /*
57  * link the file, then check for undefined symbols!
58  */
59  if (dld_link(filename))
60  return NULL;
61 
62  /*
63  * If undefined symbols: try to link with the C and math libraries! This
64  * could be smarter, if the dynamic linker was able to handle shared libs!
65  */
66  if (dld_undefined_sym_count > 0)
67  {
68  if (dld_link("/usr/lib/libc.a"))
69  {
70  elog(WARNING, "could not link C library");
71  return NULL;
72  }
73  if (dld_undefined_sym_count > 0)
74  {
75  if (dld_link("/usr/lib/libm.a"))
76  {
77  elog(WARNING, "could not link math library");
78  return NULL;
79  }
80  if (dld_undefined_sym_count > 0)
81  {
82  int count = dld_undefined_sym_count;
83  char **list = dld_list_undefined_sym();
84 
85  /* list the undefined symbols, if any */
86  do
87  {
88  elog(WARNING, "\"%s\" is undefined", *list);
89  list++;
90  count--;
91  } while (count > 0);
92 
93  dld_unlink_by_file(filename, 1);
94  return NULL;
95  }
96  }
97  }
98 
99  return (void *) strdup(filename);
100 #endif
101 }
#define ERROR
Definition: elog.h:43
#define WARNING
Definition: elog.h:40
char my_exec_path[MAXPGPATH]
Definition: globals.c:64
#define NULL
Definition: c.h:229
static char * filename
Definition: pg_dumpall.c:89
tuple list
Definition: sort-test.py:11
#define elog
Definition: elog.h:219
PGFunction pg_dlsym ( void *  handle,
char *  funcname 
)

Definition at line 104 of file linux.c.

References free, malloc, and NULL.

105 {
106 #ifndef HAVE_DLD_H
107  return NULL;
108 #else
109  return (PGFunction) dld_get_func((funcname));
110 #endif
111 }
Datum(* PGFunction)(FunctionCallInfo fcinfo)
Definition: fmgr.h:40
#define NULL
Definition: c.h:229