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

Commit6ec5eaa

Browse files
committed
Fix FindExec() for case where executable is found via a relative path
in .:/home/postgres/testversion/bin:/opt/perl5.6.1/bin:/home/postgres/bin:/usr/local/bin:/usr/bin:/opt/ansic/bin:/usr/ccs/bin:/usr/contrib/bin:/opt/nettladm/bin:/opt/pd/bin:/usr/bin/X11:/usr/contrib/bin/X11:/opt/upgrade/bin:/opt/CC/bin:/opt/langtools/bin:/opt/graphics/phigs/bin:/opt/java/bin:/bin:/opt/imake/bin:/opt/hparray/bin:/opt/aCC/bin:/opt/lrom/bin:/usr/local/nmh/bin:. (I suppose the only common case for this is '.').
1 parentb2e92a7 commit6ec5eaa

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

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

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.22 2001/05/09 19:28:31 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.23 2001/10/21 03:43:54 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
14+
#include"postgres.h"
15+
1416
#include<grp.h>
1517
#include<pwd.h>
1618
#include<sys/types.h>
1719
#include<sys/stat.h>
1820
#include<unistd.h>
1921

20-
#include"postgres.h"
2122
#include"miscadmin.h"
2223

2324
#ifndefS_IRUSR/* XXX [TRH] should be in a header */
@@ -32,7 +33,6 @@
3233
#defineS_IXOTH ((S_IXUSR)>>6)
3334
#endif
3435

35-
staticintValidateBinary(char*path);
3636

3737
/*
3838
* ValidateBinary -- validate "path" as a POSTMASTER/POSTGRES executable file
@@ -59,14 +59,6 @@ ValidateBinary(char *path)
5959
* XXX if you have a broken system where stat() looks at the symlink
6060
* instead of the underlying file, you lose.
6161
*/
62-
if (strlen(path) >=MAXPGPATH)
63-
{
64-
if (DebugLvl>1)
65-
fprintf(stderr,"ValidateBinary: pathname \"%s\" is too long\n",
66-
path);
67-
return-1;
68-
}
69-
7062
if (stat(path,&buf)<0)
7163
{
7264
if (DebugLvl>1)
@@ -75,7 +67,6 @@ ValidateBinary(char *path)
7567
return-1;
7668
}
7769

78-
7970
if ((buf.st_mode&S_IFMT)!=S_IFREG)
8071
{
8172
if (DebugLvl>1)
@@ -145,9 +136,9 @@ ValidateBinary(char *path)
145136
* FindExec -- find an absolute path to a valid backend executable
146137
*
147138
* The reason we have to work so hard to find an absolute path is that
148-
*we need to feed the binary the location of its actual executable file,
149-
*otherwise, we can't do dynamic loading.It needsa fullpathname because
150-
*we change directories to the /data directory.
139+
*on some platforms we can't do dynamic loading unless we know the
140+
*executable's location.Also, we needa fullpath not a relative
141+
*path because we will later change working directory.
151142
*/
152143
int
153144
FindExec(char*full_path,constchar*argv0,constchar*binary_name)
@@ -157,7 +148,6 @@ FindExec(char *full_path, const char *argv0, const char *binary_name)
157148
char*path,
158149
*startp,
159150
*endp;
160-
intpathlen;
161151

162152
/*
163153
* for the postmaster: First try: use the binary that's located in the
@@ -183,7 +173,7 @@ FindExec(char *full_path, const char *argv0, const char *binary_name)
183173
strcat(buf,argv0);
184174
p=strrchr(buf,'/');
185175
strcpy(++p,binary_name);
186-
if (!ValidateBinary(buf))
176+
if (ValidateBinary(buf)==0)
187177
{
188178
strncpy(full_path,buf,MAXPGPATH);
189179
if (DebugLvl)
@@ -204,9 +194,7 @@ FindExec(char *full_path, const char *argv0, const char *binary_name)
204194
{
205195
if (DebugLvl)
206196
fprintf(stderr,"FindExec: searching PATH ...\n");
207-
pathlen=strlen(p);
208-
path=malloc(pathlen+1);
209-
strcpy(path,p);
197+
path=strdup(p);/* make a modifiable copy */
210198
for (startp=path,endp=strchr(path,':');
211199
startp&&*startp;
212200
startp=endp+1,endp=strchr(startp,':'))
@@ -217,6 +205,8 @@ FindExec(char *full_path, const char *argv0, const char *binary_name)
217205
*endp='\0';
218206
if (*startp=='/'|| !getcwd(buf,MAXPGPATH))
219207
buf[0]='\0';
208+
else
209+
strcat(buf,"/");
220210
strcat(buf,startp);
221211
strcat(buf,"/");
222212
strcat(buf,binary_name);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp