~ubuntu-branches/ubuntu/precise/postgresql-9.1/precise-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * dynloader.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-2011, PostgreSQL Global Development Group
 
10
 * Portions Copyright (c) 1994, Regents of the University of California
 
11
 *
 
12
 *
 
13
 * IDENTIFICATION
 
14
 *        src/backend/port/dynloader/bsdi.c
 
15
 *
 
16
 *-------------------------------------------------------------------------
 
17
 */
 
18
#include "postgres.h"
 
19
#ifndef HAVE_DLOPEN
 
20
 
 
21
extern char my_exec_path[];
 
22
 
 
23
void *
 
24
pg_dlopen(char *filename)
 
25
{
 
26
        static int      dl_initialized = 0;
 
27
 
 
28
        /*
 
29
         * initializes the dynamic loader with the executable's pathname. (only
 
30
         * needs to do this the first time pg_dlopen is called.)
 
31
         */
 
32
        if (!dl_initialized)
 
33
        {
 
34
                if (dld_init(dld_find_executable(my_exec_path)))
 
35
                        return NULL;
 
36
 
 
37
                /*
 
38
                 * if there are undefined symbols, we want dl to search from the
 
39
                 * following libraries also.
 
40
                 */
 
41
                dl_initialized = 1;
 
42
        }
 
43
 
 
44
        /*
 
45
         * link the file, then check for undefined symbols!
 
46
         */
 
47
        if (dld_link(filename))
 
48
                return NULL;
 
49
 
 
50
        /*
 
51
         * If undefined symbols: try to link with the C and math libraries! This
 
52
         * could be smarter, if the dynamic linker was able to handle shared libs!
 
53
         */
 
54
        if (dld_undefined_sym_count > 0)
 
55
        {
 
56
                if (dld_link("/usr/lib/libc.a"))
 
57
                {
 
58
                        elog(WARNING, "could not link C library");
 
59
                        return NULL;
 
60
                }
 
61
                if (dld_undefined_sym_count > 0)
 
62
                {
 
63
                        if (dld_link("/usr/lib/libm.a"))
 
64
                        {
 
65
                                elog(WARNING, "could not link math library");
 
66
                                return NULL;
 
67
                        }
 
68
                        if (dld_undefined_sym_count > 0)
 
69
                        {
 
70
                                int                     count = dld_undefined_sym_count;
 
71
                                char      **list = dld_list_undefined_sym();
 
72
 
 
73
                                /* list the undefined symbols, if any */
 
74
                                do
 
75
                                {
 
76
                                        elog(WARNING, "\"%s\" is undefined", *list);
 
77
                                        list++;
 
78
                                        count--;
 
79
                                } while (count > 0);
 
80
 
 
81
                                dld_unlink_by_file(filename, 1);
 
82
                                return NULL;
 
83
                        }
 
84
                }
 
85
        }
 
86
 
 
87
        return (void *) strdup(filename);
 
88
}
 
89
 
 
90
char *
 
91
pg_dlerror()
 
92
{
 
93
        return dld_strerror(dld_errno);
 
94
}
 
95
 
 
96
#endif   /* not HAVE_DLOPEN */