Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit761a0bb

Browse files
committed
Add dynamic_library_path parameter and automatic appending of shared
library extension.
1 parent8266e8a commit761a0bb

File tree

5 files changed

+252
-5
lines changed

5 files changed

+252
-5
lines changed

‎doc/src/sgml/runtime.sgml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.66 2001/05/12 22:51:35 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.67 2001/05/17 17:44:17 petere Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -996,6 +996,49 @@ env PGOPTIONS='-c geqo=off' psql
996996
</listitem>
997997
</varlistentry>
998998

999+
<varlistentry>
1000+
<term>DYNAMIC_LIBRARY_PATH (<type>string</type>)</term>
1001+
<listitem>
1002+
<para>
1003+
If a dynamically loadable module needs to be opened and the
1004+
specified name does not have a directory component (i.e., the
1005+
name does not contain a slash), the system will search this
1006+
path for the specified file. (The name that is used is the
1007+
name specified in the <command>CREATE FUNCTION</command> or
1008+
<command>LOAD</command> command.)
1009+
</para>
1010+
1011+
<para>
1012+
The value for dynamic_library_path has to be a colon-separated
1013+
list of absolute directory names. If a directory name starts
1014+
with the special value <literal>$libdir</literal>, the
1015+
compiled-in PostgreSQL library directory, which is where the
1016+
modules provided by the PostgreSQL distribution are installed,
1017+
is substituted. An example value:
1018+
<informalexample>
1019+
<programlisting>
1020+
dynamic_library_path = '/usr/local/lib:/home/my_project/lib:$libdir:$libdir/contrib'
1021+
</programlisting>
1022+
</informalexample>
1023+
</para>
1024+
1025+
<para>
1026+
The default value for this parameter is
1027+
<literal>$libdir</literal>. If the value is set to the empty
1028+
string, the automatic path search is turned off.
1029+
</para>
1030+
1031+
<para>
1032+
This parameter can be changed at run time by superusers, but
1033+
note that a setting done that way will only persist till the
1034+
end of the client connection, so this method should be
1035+
reserved for development purposes. The recommended way to set
1036+
this parameter is in the <filename>postgresql.conf</filename>
1037+
configuration file.
1038+
</para>
1039+
</listitem>
1040+
</varlistentry>
1041+
9991042
<varlistentry>
10001043
<indexterm>
10011044
<primary>fsync</primary>

‎src/backend/utils/fmgr/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Makefile for utils/fmgr
55
#
66
# IDENTIFICATION
7-
# $Header: /cvsroot/pgsql/src/backend/utils/fmgr/Makefile,v 1.10 2000/08/31 16:10:50 petere Exp $
7+
# $Header: /cvsroot/pgsql/src/backend/utils/fmgr/Makefile,v 1.11 2001/05/17 17:44:18 petere Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -14,6 +14,9 @@ include $(top_builddir)/src/Makefile.global
1414

1515
OBJS = dfmgr.o fmgr.o
1616

17+
overrideCPPFLAGS += -DLIBDIR=\"$(libdir)\" -DDLSUFFIX=\"$(DLSUFFIX)\"
18+
19+
1720
all: SUBSYS.o
1821

1922
SUBSYS.o:$(OBJS)

‎src/backend/utils/fmgr/dfmgr.c

Lines changed: 197 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.48 2001/03/22 03:59:58 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.49 2001/05/17 17:44:18 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
1515
#include"postgres.h"
1616

17+
#include<errno.h>
1718
#include<sys/types.h>
1819
#include<sys/stat.h>
1920

2021
#include"dynloader.h"
22+
#include"miscadmin.h"
2123
#include"utils/dynamic_loader.h"
2224

2325

@@ -44,6 +46,12 @@ static DynamicFileList *file_tail = (DynamicFileList *) NULL;
4446

4547
#defineSAME_INODE(A,B) ((A).st_ino == (B).inode && (A).st_dev == (B).device)
4648

49+
char*Dynamic_library_path;
50+
51+
staticboolfile_exists(constchar*name);
52+
staticchar*find_in_dynamic_libpath(constchar*basename);
53+
staticchar*expand_dynamic_library_name(constchar*name);
54+
4755

4856
/*
4957
* Load the specified dynamic-link library file, and look for a function
@@ -60,6 +68,11 @@ load_external_function(char *filename, char *funcname,
6068
PGFunctionretval;
6169
char*load_error;
6270
structstatstat_buf;
71+
char*fullname;
72+
73+
fullname=expand_dynamic_library_name(filename);
74+
if (fullname)
75+
filename=fullname;
6376

6477
/*
6578
* Scan the list of loaded FILES to see if the file has been loaded.
@@ -143,6 +156,11 @@ load_file(char *filename)
143156
DynamicFileList*file_scanner,
144157
*p;
145158
structstatstat_buf;
159+
char*fullname;
160+
161+
fullname=expand_dynamic_library_name(filename);
162+
if (fullname)
163+
filename=fullname;
146164

147165
/*
148166
* We need to do stat() in order to determine whether this is the same
@@ -181,3 +199,181 @@ load_file(char *filename)
181199

182200
load_external_function(filename, (char*)NULL, false);
183201
}
202+
203+
204+
205+
staticbool
206+
file_exists(constchar*name)
207+
{
208+
structstatst;
209+
210+
AssertArg(name!=NULL);
211+
212+
if (stat(name,&st)==0)
213+
return true;
214+
elseif (!(errno==ENOENT||errno==ENOTDIR||errno==EACCES))
215+
elog(ERROR,"stat failed on %s: %s",name,strerror(errno));
216+
217+
return false;
218+
}
219+
220+
221+
/* Example format: ".so" */
222+
#ifndefDLSUFFIX
223+
#error "DLSUFFIX must be defined to compile this file."
224+
#endif
225+
226+
/* Example format: "/usr/local/pgsql/lib" */
227+
#ifndefLIBDIR
228+
#error "LIBDIR needs to be defined to compile this file."
229+
#endif
230+
231+
232+
/*
233+
* If name contains a slash, check if the file exists, if so return
234+
* the name. Else (no slash) try to expand using search path (see
235+
* find_in_dynamic_libpath below); if that works, return the fully
236+
* expanded file name. If the previous failed, append DLSUFFIX and
237+
* try again. If all fails, return NULL. The return value is
238+
* palloc'ed.
239+
*/
240+
staticchar*
241+
expand_dynamic_library_name(constchar*name)
242+
{
243+
boolhave_slash;
244+
char*new;
245+
size_tlen;
246+
247+
AssertArg(name);
248+
249+
have_slash= (strchr(name,'/')!=NULL);
250+
251+
if (!have_slash)
252+
{
253+
char*full;
254+
255+
full=find_in_dynamic_libpath(name);
256+
if (full)
257+
returnfull;
258+
}
259+
else
260+
{
261+
if (file_exists(name))
262+
returnpstrdup(name);
263+
}
264+
265+
len=strlen(name);
266+
267+
new=palloc(len+strlen(DLSUFFIX)+1);
268+
strcpy(new,name);
269+
strcpy(new+len,DLSUFFIX);
270+
271+
if (!have_slash)
272+
{
273+
char*full;
274+
275+
full=find_in_dynamic_libpath(new);
276+
pfree(new);
277+
if (full)
278+
returnfull;
279+
}
280+
else
281+
{
282+
if (file_exists(new))
283+
returnnew;
284+
}
285+
286+
returnNULL;
287+
}
288+
289+
290+
291+
/*
292+
* Search for a file called 'basename' in the colon-separated search
293+
* path 'path'. If the file is found, the full file name is returned
294+
* in palloced memory. The the file is not found, return NULL.
295+
*/
296+
staticchar*
297+
find_in_dynamic_libpath(constchar*basename)
298+
{
299+
constchar*p;
300+
char*full;
301+
size_tlen;
302+
size_tbaselen;
303+
304+
AssertArg(basename!=NULL);
305+
AssertArg(strchr(basename,'/')==NULL);
306+
AssertState(Dynamic_library_path!=NULL);
307+
308+
p=Dynamic_library_path;
309+
if (strlen(p)==0)
310+
returnNULL;
311+
312+
baselen=strlen(basename);
313+
314+
do {
315+
len=strcspn(p,":");
316+
317+
if (len==0)
318+
elog(ERROR,"zero length dynamic_library_path component");
319+
320+
/* substitute special value */
321+
if (p[0]=='$')
322+
{
323+
size_tvarname_len=strcspn(p+1,"/")+1;
324+
constchar*replacement=NULL;
325+
size_trepl_len;
326+
327+
if (strncmp(p,"$libdir",varname_len)==0)
328+
replacement=LIBDIR;
329+
else
330+
elog(ERROR,"invalid dynamic_library_path specification");
331+
332+
repl_len=strlen(replacement);
333+
334+
if (p[varname_len]=='\0')
335+
{
336+
full=palloc(repl_len+1+baselen+1);
337+
snprintf(full,repl_len+1+baselen+1,
338+
"%s/%s",replacement,basename);
339+
}
340+
else
341+
{
342+
full=palloc(repl_len+ (len-varname_len)+1+baselen+1);
343+
344+
strcpy(full,replacement);
345+
strncat(full,p+varname_len,len-varname_len);
346+
full[repl_len+ (len-varname_len)]='\0';
347+
strcat(full,"/");
348+
strcat(full,basename);
349+
}
350+
}
351+
352+
/* regular case */
353+
else
354+
{
355+
/* only absolute paths */
356+
if (p[0]!='/')
357+
elog(ERROR,"dynamic_library_path component is not absolute");
358+
359+
full=palloc(len+1+baselen+1);
360+
strncpy(full,p,len);
361+
full[len]='/';
362+
strcpy(full+len+1,basename);
363+
}
364+
365+
if (DebugLvl>1)
366+
elog(DEBUG,"find_in_dynamic_libpath: trying %s",full);
367+
368+
if (file_exists(full))
369+
returnfull;
370+
371+
pfree(full);
372+
if (p[len]=='\0')
373+
break;
374+
else
375+
p+=len+1;
376+
}while(1);
377+
378+
returnNULL;
379+
}

‎src/backend/utils/misc/guc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Support for grand unified configuration scheme, including SET
55
* command, configuration file, and command line options.
66
*
7-
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.35 2001/03/22 17:41:47 tgl Exp $
7+
* $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.36 2001/05/17 17:44:18 petere Exp $
88
*
99
* Copyright 2000 by PostgreSQL Global Development Group
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
@@ -22,6 +22,7 @@
2222

2323
#include"access/xlog.h"
2424
#include"commands/async.h"
25+
#include"fmgr.h"
2526
#include"libpq/auth.h"
2627
#include"libpq/pqcomm.h"
2728
#include"miscadmin.h"
@@ -328,6 +329,9 @@ static struct config_real
328329
staticstructconfig_string
329330
ConfigureNamesString[]=
330331
{
332+
{"dynamic_library_path",PGC_SUSET,&Dynamic_library_path,
333+
"$libdir",NULL,NULL},
334+
331335
{"krb_server_keyfile",PGC_POSTMASTER,&pg_krb_server_keyfile,
332336
PG_KRB_SRVTAB,NULL,NULL},
333337

‎src/include/fmgr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
14-
* $Id: fmgr.h,v 1.13 2001/03/22 04:00:25 momjian Exp $
14+
* $Id: fmgr.h,v 1.14 2001/05/17 17:44:18 petere Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -350,6 +350,7 @@ extern Oidfmgr_internal_function(const char *proname);
350350
externPGFunctionload_external_function(char*filename,char*funcname,
351351
boolsignalNotFound);
352352
externvoidload_file(char*filename);
353+
externchar*Dynamic_library_path;
353354

354355

355356
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp