~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to src/backend/port/dynloader/linux.c

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * linux.c
 
4
 *        Dynamic Loader for Postgres for Linux, generated from those for
 
5
 *        Ultrix.
 
6
 *
 
7
 *        You need to install the dld library on your Linux system!
 
8
 *
 
9
 * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
 
10
 * Portions Copyright (c) 1994, Regents of the University of California
 
11
 *
 
12
 *
 
13
 * IDENTIFICATION
 
14
 *        $PostgreSQL: pgsql/src/backend/port/dynloader/linux.c,v 1.30 2004-12-31 22:00:32 pgsql Exp $
 
15
 *
 
16
 *-------------------------------------------------------------------------
 
17
 */
 
18
 
 
19
#include "postgres.h"
 
20
 
 
21
#ifdef HAVE_DLD_H
 
22
#include <dld.h>
 
23
#endif
 
24
 
 
25
#include "dynloader.h"
 
26
#include "miscadmin.h"
 
27
 
 
28
 
 
29
#ifndef HAVE_DLOPEN
 
30
 
 
31
void *
 
32
pg_dlopen(char *filename)
 
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.
 
42
         * (only 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!
 
64
         * This could be smarter, if the dynamic linker was able to handle
 
65
         * shared libs!
 
66
         */
 
67
        if (dld_undefined_sym_count > 0)
 
68
        {
 
69
                if (dld_link("/usr/lib/libc.a"))
 
70
                {
 
71
                        elog(WARNING, "could not link C library");
 
72
                        return NULL;
 
73
                }
 
74
                if (dld_undefined_sym_count > 0)
 
75
                {
 
76
                        if (dld_link("/usr/lib/libm.a"))
 
77
                        {
 
78
                                elog(WARNING, "could not link math library");
 
79
                                return NULL;
 
80
                        }
 
81
                        if (dld_undefined_sym_count > 0)
 
82
                        {
 
83
                                int                     count = dld_undefined_sym_count;
 
84
                                char      **list = dld_list_undefined_sym();
 
85
 
 
86
                                /* list the undefined symbols, if any */
 
87
                                do
 
88
                                {
 
89
                                        elog(WARNING, "\"%s\" is undefined", *list);
 
90
                                        list++;
 
91
                                        count--;
 
92
                                } while (count > 0);
 
93
 
 
94
                                dld_unlink_by_file(filename, 1);
 
95
                                return NULL;
 
96
                        }
 
97
                }
 
98
        }
 
99
 
 
100
        return (void *) strdup(filename);
 
101
#endif
 
102
}
 
103
 
 
104
PGFunction
 
105
pg_dlsym(void *handle, char *funcname)
 
106
{
 
107
#ifndef HAVE_DLD_H
 
108
        return NULL;
 
109
#else
 
110
        return (PGFunction) dld_get_func((funcname));
 
111
#endif
 
112
}
 
113
 
 
114
void
 
115
pg_dlclose(void *handle)
 
116
{
 
117
#ifndef HAVE_DLD_H
 
118
#else
 
119
        dld_unlink_by_file(handle, 1);
 
120
        free(handle);
 
121
#endif
 
122
}
 
123
 
 
124
char *
 
125
pg_dlerror(void)
 
126
{
 
127
#ifndef HAVE_DLD_H
 
128
        return "dynaloader unspported";
 
129
#else
 
130
        return dld_strerror(dld_errno);
 
131
#endif
 
132
}
 
133
 
 
134
#endif   /* !HAVE_DLOPEN */