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

Commit3febb47

Browse files
committed
Reorganize code to allow path-relative installs.
Create new get_* functions to access compiled-in paths and adjust ifrelative installs are to be used.Clean up substitute_libpath_macro() code.
1 parent8538321 commit3febb47

File tree

19 files changed

+376
-172
lines changed

19 files changed

+376
-172
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.387 2004/05/14 17:04:44 momjian Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.388 2004/05/17 14:35:29 momjian Exp $
4141
*
4242
* NOTES
4343
*
@@ -697,6 +697,8 @@ PostmasterMain(int argc, char *argv[])
697697
ereport(FATAL,
698698
(errmsg("%s: could not locate my own executable path",
699699
progname)));
700+
if (strlen(pkglib_path)==0)
701+
get_pkglib_path(my_exec_path,pkglib_path);
700702

701703
#ifdefEXEC_BACKEND
702704
if (find_other_exec(argv[0],"postgres",PG_VERSIONSTR,postgres_exec_path)<0)

‎src/backend/tcop/postgres.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.406 2004/05/14 17:04:45 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.407 2004/05/17 14:35:31 momjian Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -2652,6 +2652,9 @@ PostgresMain(int argc, char *argv[], const char *username)
26522652
ereport(FATAL,
26532653
(errmsg("%s: could not locate postgres executable",
26542654
argv[0])));
2655+
if (strlen(pkglib_path)==0)
2656+
get_pkglib_path(my_exec_path,pkglib_path);
2657+
26552658
/*
26562659
* Validate we have been given a reasonable-looking DataDir (if
26572660
* under postmaster, assume postmaster did this already).

‎src/backend/utils/fmgr/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Makefile for utils/fmgr
55
#
66
# IDENTIFICATION
7-
# $PostgreSQL: pgsql/src/backend/utils/fmgr/Makefile,v 1.15 2003/12/23 21:56:20 tgl Exp $
7+
# $PostgreSQL: pgsql/src/backend/utils/fmgr/Makefile,v 1.16 2004/05/17 14:35:31 momjian Exp $
88
#
99
#-------------------------------------------------------------------------
1010

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

1515
OBJS = dfmgr.o fmgr.o funcapi.o
1616

17-
overrideCPPFLAGS += -DPKGLIBDIR=\"$(pkglibdir)\" -DDLSUFFIX=\"$(DLSUFFIX)\"
17+
overrideCPPFLAGS += -DDLSUFFIX=\"$(DLSUFFIX)\"
1818

1919

2020
all: SUBSYS.o

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

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.71 2004/03/09 05:06:45 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.72 2004/05/17 14:35:31 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -270,12 +270,6 @@ file_exists(const char *name)
270270
#error "DLSUFFIX must be defined to compile this file."
271271
#endif
272272

273-
/* Example format: "/usr/local/pgsql/lib" */
274-
#ifndefPKGLIBDIR
275-
#error "PKGLIBDIR needs to be defined to compile this file."
276-
#endif
277-
278-
279273
/*
280274
* If name contains a slash, check if the file exists, if so return
281275
* the name. Else (no slash) try to expand using search path (see
@@ -341,62 +335,29 @@ expand_dynamic_library_name(const char *name)
341335
staticchar*
342336
substitute_libpath_macro(constchar*name)
343337
{
344-
size_tmacroname_len;
345-
char*replacement=NULL;
346-
#ifdefWIN32
347-
charbasename[MAXPGPATH];
348-
#endif
349-
338+
constchar*sep_ptr;
339+
char*ret;
340+
350341
AssertArg(name!=NULL);
351342

352343
if (name[0]!='$')
353344
returnpstrdup(name);
354345

355-
#ifndefWIN32
356-
macroname_len=strcspn(name+1,"/")+1;
357-
#else
358-
macroname_len=strcspn(name+1,"/\\")+1;
359-
#endif
360-
361-
if (strncmp(name,"$libdir",macroname_len)==0)
362-
#ifndefWIN32
363-
replacement=PKGLIBDIR;
364-
#else
365-
{
366-
char*p;
367-
if (GetModuleFileName(NULL,basename,MAXPGPATH)==0)
368-
ereport(FATAL,
369-
(errmsg("GetModuleFileName failed (%i)",(int)GetLastError())));
370-
371-
canonicalize_path(basename);
372-
if ((p=last_path_separator(basename))==NULL)
373-
ereport(FATAL,
374-
(errmsg("unexpected failure in determining PKGLIBDIR (%s)",basename)));
375-
else
376-
*p='\0';
377-
378-
strcat(basename,"/../lib");
379-
replacement=basename;
380-
}
381-
#endif
382-
else
346+
if ((sep_ptr=first_path_separator(name))==NULL)
347+
sep_ptr=name+strlen(name);
348+
349+
if (strlen("$libdir")!=sep_ptr-name||
350+
strncmp(name,"$libdir",strlen("$libdir"))!=0)
383351
ereport(ERROR,
384352
(errcode(ERRCODE_INVALID_NAME),
385353
errmsg("invalid macro name in dynamic library path")));
386354

387-
if (name[macroname_len]=='\0')
388-
returnpstrdup(replacement);
389-
else
390-
{
391-
char*new;
355+
ret=palloc(strlen(pkglib_path)+strlen(sep_ptr)+1);
392356

393-
new=palloc(strlen(replacement)+ (strlen(name)-macroname_len)+1);
357+
strcpy(ret,pkglib_path);
358+
strcat(ret,sep_ptr);
394359

395-
strcpy(new,replacement);
396-
strcat(new,name+macroname_len);
397-
398-
returnnew;
399-
}
360+
returnret;
400361
}
401362

402363

‎src/backend/utils/init/globals.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.85 2004/05/13 22:45:03 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.86 2004/05/17 14:35:32 momjian Exp $
1212
*
1313
* NOTES
1414
* Globals used all over the place should be declared here and not
@@ -46,6 +46,7 @@ char *DataDir = NULL;
4646
charOutputFileName[MAXPGPATH];
4747

4848
charmy_exec_path[MAXPGPATH];/* full path to postgres executable */
49+
charpkglib_path[MAXPGPATH];/* full path to lib directory */
4950

5051
BackendIdMyBackendId;
5152

‎src/bin/initdb/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
# Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
66
# Portions Copyright (c) 1994, Regents of the University of California
77
#
8-
# $PostgreSQL: pgsql/src/bin/initdb/Makefile,v 1.37 2004/05/11 21:57:14 momjian Exp $
8+
# $PostgreSQL: pgsql/src/bin/initdb/Makefile,v 1.38 2004/05/17 14:35:33 momjian Exp $
99
#
1010
#-------------------------------------------------------------------------
1111

1212
subdir = src/bin/initdb
1313
top_builddir = ../../..
1414
include$(top_builddir)/src/Makefile.global
1515

16-
overrideCPPFLAGS := -DPGDATADIR=\"$(datadir)\" -DFRONTEND -I$(libpq_srcdir)$(CPPFLAGS)
16+
overrideCPPFLAGS := -DFRONTEND -I$(libpq_srcdir)$(CPPFLAGS)
1717

1818
OBJS=initdb.o\
1919
$(filter exec.o,$(LIBOBJS))

‎src/bin/initdb/initdb.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* Portions Copyright (c) 1994, Regents of the University of California
4040
* Portions taken from FreeBSD.
4141
*
42-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.30 2004/05/1713:17:29 momjian Exp $
42+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.31 2004/05/1714:35:33 momjian Exp $
4343
*
4444
*-------------------------------------------------------------------------
4545
*/
@@ -69,11 +69,8 @@ intoptreset;
6969

7070
/*
7171
* these values are passed in by makefile defines
72-
*
73-
* Note that "datadir" is not the directory we're going to initialize,
74-
* it's merely how Autoconf names PREFIX/share.
7572
*/
76-
char*datadir=PGDATADIR;
73+
char*share_path=NULL;
7774

7875
/* values to be obtained from arguments */
7976
char*pg_data="";
@@ -129,7 +126,7 @@ static const char *backend_options = "-F -O -c search_path=pg_catalog -c exit_on
129126

130127

131128
/* path to 'initdb' binary directory */
132-
charbindir[MAXPGPATH];
129+
charbin_path[MAXPGPATH];
133130
charbackend_exec[MAXPGPATH];
134131

135132
staticvoid*xmalloc(size_tsize);
@@ -730,8 +727,8 @@ mkdatadir(char *subdir)
730727
staticvoid
731728
set_input(char**dest,char*filename)
732729
{
733-
*dest=xmalloc(strlen(datadir)+strlen(filename)+2);
734-
sprintf(*dest,"%s/%s",datadir,filename);
730+
*dest=xmalloc(strlen(share_path)+strlen(filename)+2);
731+
sprintf(*dest,"%s/%s",share_path,filename);
735732
}
736733

737734
/*
@@ -1849,7 +1846,7 @@ main(int argc, char *argv[])
18491846
printf(_("Running in noclean mode. Mistakes will not be cleaned up.\n"));
18501847
break;
18511848
case'L':
1852-
datadir=xstrdup(optarg);
1849+
share_path=xstrdup(optarg);
18531850
break;
18541851
case1:
18551852
locale=xstrdup(optarg);
@@ -1951,9 +1948,15 @@ main(int argc, char *argv[])
19511948
}
19521949

19531950
/* store binary directory */
1954-
strcpy(bindir,backend_exec);
1955-
*last_path_separator(bindir)='\0';
1956-
1951+
strcpy(bin_path,backend_exec);
1952+
*last_path_separator(bin_path)='\0';
1953+
1954+
if (!share_path)
1955+
{
1956+
share_path=xmalloc(MAXPGPATH);
1957+
get_share_path(backend_exec,share_path);
1958+
}
1959+
19571960
if ((short_version=get_short_version())==NULL)
19581961
{
19591962
fprintf(stderr,_("%s: could not determine valid short version string\n"),progname);
@@ -1983,13 +1986,13 @@ main(int argc, char *argv[])
19831986
{
19841987
fprintf(stderr,
19851988
"VERSION=%s\n"
1986-
"PGDATA=%s\ndatadir=%s\nPGPATH=%s\n"
1989+
"PGDATA=%s\nshare_path=%s\nPGPATH=%s\n"
19871990
"ENCODING=%s\nENCODINGID=%s\n"
19881991
"POSTGRES_SUPERUSERNAME=%s\nPOSTGRES_BKI=%s\n"
19891992
"POSTGRES_DESCR=%s\nPOSTGRESQL_CONF_SAMPLE=%s\n"
19901993
"PG_HBA_SAMPLE=%s\nPG_IDENT_SAMPLE=%s\n",
19911994
PG_VERSION,
1992-
pg_data,datadir,bindir,
1995+
pg_data,share_path,bin_path,
19931996
encoding,encodingid,
19941997
username,bki_file,
19951998
desc_file,conf_file,
@@ -2182,8 +2185,8 @@ main(int argc, char *argv[])
21822185
" %s%s%s/postmaster -D %s%s%s\n"
21832186
"or\n"
21842187
" %s%s%s/pg_ctl -D %s%s%s -l logfile start\n\n"),
2185-
QUOTE_PATH,bindir,QUOTE_PATH,QUOTE_PATH,pg_data,QUOTE_PATH,
2186-
QUOTE_PATH,bindir,QUOTE_PATH,QUOTE_PATH,pg_data,QUOTE_PATH);
2188+
QUOTE_PATH,bin_path,QUOTE_PATH,QUOTE_PATH,pg_data,QUOTE_PATH,
2189+
QUOTE_PATH,bin_path,QUOTE_PATH,QUOTE_PATH,pg_data,QUOTE_PATH);
21872190

21882191
return0;
21892192
}

‎src/bin/psql/Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
66
# Portions Copyright (c) 1994, Regents of the University of California
77
#
8-
# $PostgreSQL: pgsql/src/bin/psql/Makefile,v 1.43 2004/04/26 17:40:48 momjian Exp $
8+
# $PostgreSQL: pgsql/src/bin/psql/Makefile,v 1.44 2004/05/17 14:35:33 momjian Exp $
99
#
1010
#-------------------------------------------------------------------------
1111

@@ -15,11 +15,12 @@ include $(top_builddir)/src/Makefile.global
1515

1616
REFDOCDIR=$(top_srcdir)/doc/src/sgml/ref
1717

18-
overrideCPPFLAGS := -I$(libpq_srcdir)$(CPPFLAGS) -DFRONTEND -DSYSCONFDIR='"$(sysconfdir)"'
18+
overrideCPPFLAGS := -I$(libpq_srcdir)$(CPPFLAGS) -DFRONTEND
1919

2020
OBJS=command.o common.o help.o input.o stringutils.o mainloop.o copy.o\
2121
startup.o prompt.o variables.o large_obj.o print.o describe.o\
22-
psqlscan.o tab-complete.o mbprint.o
22+
psqlscan.o tab-complete.o mbprint.o\
23+
$(filter exec.o,$(LIBOBJS))
2324

2425
FLEXFLAGS = -Cfe
2526

@@ -29,6 +30,9 @@ all: submake-libpq submake-libpgport psql
2930
psql:$(OBJS)$(libpq_builddir)/libpq.a
3031
$(CC)$(CFLAGS)$(OBJS)$(libpq)$(LDFLAGS)$(LIBS) -o$@$(X)
3132

33+
exec.c:% :$(top_srcdir)/src/port/%
34+
rm -f$@&&$(LN_S)$<.
35+
3236
help.o:$(srcdir)/sql_help.h
3337

3438
ifdefPERL
@@ -60,7 +64,7 @@ uninstall:
6064

6165
# psqlscan.c is in the distribution tarball, so is not cleaned here
6266
cleandistclean:
63-
rm -f psql$(X)$(OBJS)
67+
rm -f psql$(X)$(OBJS) exec.c
6468

6569
maintainer-clean: distclean
6670
rm -f$(srcdir)/sql_help.h$(srcdir)/psqlscan.c

‎src/bin/psql/startup.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.92 2004/05/02 04:25:45 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.93 2004/05/17 14:35:33 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99

@@ -74,7 +74,7 @@ struct adhoc_opts
7474

7575
staticvoidparse_psql_options(intargc,char*argv[],
7676
structadhoc_opts*options);
77-
staticvoidprocess_psqlrc(void);
77+
staticvoidprocess_psqlrc(char*argv0);
7878
staticvoidprocess_psqlrc_file(char*filename);
7979
staticvoidshowVersion(void);
8080

@@ -239,7 +239,7 @@ main(int argc, char *argv[])
239239
if (options.action==ACT_FILE&&strcmp(options.action_string,"-")!=0)
240240
{
241241
if (!options.no_psqlrc)
242-
process_psqlrc();
242+
process_psqlrc(argv[0]);
243243

244244
successResult=process_file(options.action_string);
245245
}
@@ -305,7 +305,7 @@ main(int argc, char *argv[])
305305
SetVariable(pset.vars,"PROMPT3",DEFAULT_PROMPT3);
306306

307307
if (!options.no_psqlrc)
308-
process_psqlrc();
308+
process_psqlrc(argv[0]);
309309
if (!pset.notty)
310310
initializeInput(options.no_readline ?0 :1);
311311
if (options.action_string)/* -f - was used */
@@ -567,22 +567,24 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
567567

568568
}
569569

570-
#ifndefSYSCONFDIR
571-
#error "You must compile this file with SYSCONFDIR defined."
572-
#endif
573-
574570

575571
/*
576572
* Load .psqlrc file, if found.
577573
*/
578574
staticvoid
579-
process_psqlrc(void)
575+
process_psqlrc(char*argv0)
580576
{
581-
char*globalFile=SYSCONFDIR"/"SYSPSQLRC;
582577
char*home;
583578
char*psqlrc;
579+
charglobal_file[MAXPGPATH];
580+
charmy_exec_path[MAXPGPATH];
581+
charetc_path[MAXPGPATH];
582+
583+
find_my_exec(argv0,my_exec_path);
584+
get_etc_path(my_exec_path,etc_path);
584585

585-
process_psqlrc_file(globalFile);
586+
snprintf(global_file,MAXPGPATH,"%s/%s",etc_path,SYSPSQLRC);
587+
process_psqlrc_file(global_file);
586588

587589
if ((home=getenv("HOME"))!=NULL)
588590
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp