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

Commita608637

Browse files
committed
Another for for exec() removal and finding binaries.
1 parentcb8539f commita608637

File tree

4 files changed

+38
-36
lines changed

4 files changed

+38
-36
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.85 1998/06/0904:06:12 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.86 1998/06/0917:13:03 momjian Exp $
1414
*
1515
* NOTES
1616
*
@@ -324,7 +324,7 @@ PostmasterMain(int argc, char *argv[])
324324
new_argv[i]="";
325325
new_argv[4]=NULL;
326326

327-
if (!Execfile[0]&&FindExec(Execfile,argv[0])<0)
327+
if (!Execfile[0]&&FindExec(Execfile,argv[0],"postmaster")<0)
328328
{
329329
fprintf(stderr,"%s: could not find postmaster to execute...\n",
330330
argv[0]);
@@ -385,7 +385,7 @@ PostmasterMain(int argc, char *argv[])
385385
break;
386386
case'b':
387387
/* Set the backend executable file to use. */
388-
if (!ValidateBackend(optarg))
388+
if (!ValidateBinary(optarg))
389389
strcpy(Execfile,optarg);
390390
else
391391
{
@@ -479,7 +479,7 @@ PostmasterMain(int argc, char *argv[])
479479
exit(2);
480480
}
481481

482-
if (!Execfile[0]&&FindExec(Execfile,argv[0])<0)
482+
if (!Execfile[0]&&FindExec(Execfile,argv[0],"postgres")<0)
483483
{
484484
fprintf(stderr,"%s: could not find backend to execute...\n",
485485
argv[0]);

‎src/backend/tcop/postgres.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.74 1998/06/08 22:28:27 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.75 1998/06/09 17:13:04 momjian Exp $
1111
*
1212
* NOTES
1313
* this is the "main" module of the postgres backend and
@@ -1167,7 +1167,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
11671167
SetCharSet();
11681168
#endif
11691169

1170-
if (FindExec(pg_pathname,argv[0])<0)
1170+
if (FindExec(pg_pathname,argv[0],"postgres")<0)
11711171
elog(FATAL,"%s: could not locate executable, bailing out...",
11721172
argv[0]);
11731173

@@ -1314,7 +1314,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
13141314
if (!IsUnderPostmaster)
13151315
{
13161316
puts("\nPOSTGRES backend interactive interface");
1317-
puts("$Revision: 1.74 $ $Date: 1998/06/08 22:28:27 $");
1317+
puts("$Revision: 1.75 $ $Date: 1998/06/09 17:13:04 $");
13181318
}
13191319

13201320
/* ----------------

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

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.8 1998/06/08 22:28:28 momjian Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.9 1998/06/09 17:13:05 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -34,14 +34,14 @@
3434
#endif
3535

3636
/*
37-
*ValidateBackend -- validate "path" as a POSTGRES executable file
37+
*ValidateBinary -- validate "path" as aPOSTMASTER/POSTGRES executable file
3838
*
3939
* returns 0 if the file is found and no error is encountered.
4040
* -1 if the regular file "path" does not exist or cannot be executed.
4141
* -2 if the file is otherwise valid but cannot be read.
4242
*/
4343
int
44-
ValidateBackend(char*path)
44+
ValidateBinary(char*path)
4545
{
4646
structstatbuf;
4747
uid_teuid;
@@ -61,22 +61,22 @@ ValidateBackend(char *path)
6161
if (strlen(path) >=MAXPGPATH)
6262
{
6363
if (DebugLvl>1)
64-
fprintf(stderr,"ValidateBackend: pathname \"%s\" is too long\n",
64+
fprintf(stderr,"ValidateBinary: pathname \"%s\" is too long\n",
6565
path);
6666
return (-1);
6767
}
6868

6969
if (stat(path,&buf)<0)
7070
{
7171
if (DebugLvl>1)
72-
fprintf(stderr,"ValidateBackend: can't stat \"%s\"\n",
72+
fprintf(stderr,"ValidateBinary: can't stat \"%s\"\n",
7373
path);
7474
return (-1);
7575
}
7676
if (!(buf.st_mode&S_IFREG))
7777
{
7878
if (DebugLvl>1)
79-
fprintf(stderr,"ValidateBackend: \"%s\" is not a regular file\n",
79+
fprintf(stderr,"ValidateBinary: \"%s\" is not a regular file\n",
8080
path);
8181
return (-1);
8282
}
@@ -85,7 +85,7 @@ ValidateBackend(char *path)
8585
* Ensure that we are using an authorized backend.
8686
*
8787
* XXX I'm open to suggestions here. I would like to enforce ownership
88-
* ofbackends by user "postgres" but people seem to like to run as
88+
* ofbinaries by user "postgres" but people seem to like to run as
8989
* users other than "postgres"...
9090
*/
9191

@@ -102,7 +102,7 @@ ValidateBackend(char *path)
102102
is_r=buf.st_mode&S_IRUSR;
103103
is_x=buf.st_mode&S_IXUSR;
104104
if (DebugLvl>1&& !(is_r&&is_x))
105-
fprintf(stderr,"ValidateBackend: \"%s\" is not user read/execute\n",
105+
fprintf(stderr,"ValidateBinary: \"%s\" is not user read/execute\n",
106106
path);
107107
return (is_x ? (is_r ?0 :-2) :-1);
108108
}
@@ -130,15 +130,15 @@ ValidateBackend(char *path)
130130
is_r=buf.st_mode&S_IRGRP;
131131
is_x=buf.st_mode&S_IXGRP;
132132
if (DebugLvl>1&& !(is_r&&is_x))
133-
fprintf(stderr,"ValidateBackend: \"%s\" is not group read/execute\n",
133+
fprintf(stderr,"ValidateBinary: \"%s\" is not group read/execute\n",
134134
path);
135135
return (is_x ? (is_r ?0 :-2) :-1);
136136
}
137137
}
138138
is_r=buf.st_mode&S_IROTH;
139139
is_x=buf.st_mode&S_IXOTH;
140140
if (DebugLvl>1&& !(is_r&&is_x))
141-
fprintf(stderr,"ValidateBackend: \"%s\" is not other read/execute\n",
141+
fprintf(stderr,"ValidateBinary: \"%s\" is not other read/execute\n",
142142
path);
143143
return (is_x ? (is_r ?0 :-2) :-1);
144144
}
@@ -147,11 +147,12 @@ ValidateBackend(char *path)
147147
* FindExec -- find an absolute path to a valid backend executable
148148
*
149149
* The reason we have to work so hard to find an absolute path is that
150-
* we need to feed the backend server the location of its actual
151-
* executable file -- otherwise, we can't do dynamic loading.
150+
* we need to feed the binary the location of its actual executable file,
151+
* otherwise, we can't do dynamic loading. It needs a full pathname because
152+
* we change directories to the /data directory.
152153
*/
153154
int
154-
FindExec(char*backend,char*argv0)
155+
FindExec(char*full_path,char*argv0,char*binary_name)
155156
{
156157
charbuf[MAXPGPATH+2];
157158
char*p;
@@ -161,7 +162,7 @@ FindExec(char *backend, char *argv0)
161162
intpathlen;
162163

163164
/*
164-
* for the postmaster: First try: use thebackend that's located in
165+
* for the postmaster: First try: use thebinary that's located in
165166
* the same directory as the postmaster, if it was invoked with an
166167
* explicit path. Presumably the user used an explicit path because it
167168
* wasn't in PATH, and we don't want to use incompatible executables.
@@ -171,7 +172,7 @@ FindExec(char *backend, char *argv0)
171172
* trees (obj/post{master,gres}) because they all put the two binaries
172173
* in the same place.
173174
*
174-
* for thebackend server: First try: if we're given some kind of path,
175+
* for thebinary: First try: if we're given some kind of path,
175176
* use it (making sure that a relative path is made absolute before
176177
* returning it).
177178
*/
@@ -183,16 +184,16 @@ FindExec(char *backend, char *argv0)
183184
strcat(buf,"/");
184185
strcat(buf,argv0);
185186
p=strrchr(buf,'/');
186-
strcpy(++p,"postgres");
187-
if (!ValidateBackend(buf))
187+
strcpy(++p,binary_name);
188+
if (!ValidateBinary(buf))
188189
{
189-
strncpy(backend,buf,MAXPGPATH);
190+
strncpy(full_path,buf,MAXPGPATH);
190191
if (DebugLvl)
191192
fprintf(stderr,"FindExec: found \"%s\" using argv[0]\n",
192-
backend);
193+
full_path);
193194
return (0);
194195
}
195-
fprintf(stderr,"FindExec: invalidbackend \"%s\"\n",
196+
fprintf(stderr,"FindExec: invalidbinary \"%s\"\n",
196197
buf);
197198
return (-1);
198199
}
@@ -219,20 +220,21 @@ FindExec(char *backend, char *argv0)
219220
if (*startp=='/'|| !getcwd(buf,MAXPGPATH))
220221
buf[0]='\0';
221222
strcat(buf,startp);
222-
strcat(buf,"/postgres");
223-
switch (ValidateBackend(buf))
223+
strcat(buf,"/");
224+
strcat(buf,binary_name);
225+
switch (ValidateBinary(buf))
224226
{
225227
case0:/* found ok */
226-
strncpy(backend,buf,MAXPGPATH);
228+
strncpy(full_path,buf,MAXPGPATH);
227229
if (DebugLvl)
228230
fprintf(stderr,"FindExec: found \"%s\" using PATH\n",
229-
backend);
231+
full_path);
230232
free(path);
231233
return (0);
232234
case-1:/* wasn't even a candidate, keep looking */
233235
break;
234236
case-2:/* found but disqualified */
235-
fprintf(stderr,"FindExec: could not readbackend \"%s\"\n",
237+
fprintf(stderr,"FindExec: could not readbinary \"%s\"\n",
236238
buf);
237239
free(path);
238240
return (-1);
@@ -243,6 +245,6 @@ FindExec(char *backend, char *argv0)
243245
free(path);
244246
}
245247

246-
fprintf(stderr,"FindExec: could not find abackend to execute...\n");
248+
fprintf(stderr,"FindExec: could not find a%s to execute...\n",binary_name);
247249
return (-1);
248250
}

‎src/include/miscadmin.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* Copyright (c) 1994, Regents of the University of California
1313
*
14-
* $Id: miscadmin.h,v 1.25 1998/06/08 22:28:30 momjian Exp $
14+
* $Id: miscadmin.h,v 1.26 1998/06/09 17:13:06 momjian Exp $
1515
*
1616
* NOTES
1717
* some of the information in this file will be moved to
@@ -125,8 +125,8 @@ extern char *getpgusername(void);
125125
externvoidSetPgUserName(void);
126126
externOidGetUserId(void);
127127
externvoidSetUserId(void);
128-
externintValidateBackend(char*path);
129-
externintFindExec(char*backend,char*argv0);
128+
externintValidateBinary(char*path);
129+
externintFindExec(char*backend,char*argv0,char*binary_name);
130130
externintCheckPathAccess(char*path,char*name,intopen_mode);
131131

132132
/* lower case version for case-insensitive SQL referenced in pg_proc.h */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp