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

Commitf69ecb4

Browse files
committed
Reorganize backend code to more cleanly manage executable names and
backend startup.
1 parent261eda5 commitf69ecb4

File tree

10 files changed

+61
-63
lines changed

10 files changed

+61
-63
lines changed

‎src/backend/port/beos/support.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ port_idbeos_dl_port_out = 0;
1616
sem_idbeos_shm_sem;
1717

1818
/* Global var containing the postgres path */
19-
externcharpg_pathname[];
19+
externcharmy_exec_path[];
2020

2121

2222
/* Shared library loading doesn't work after fork in beos. The solution is to use an exact
@@ -50,7 +50,7 @@ beos_dl_open(char *filename)
5050
charCmd[4000];
5151

5252
/* Build arg list */
53-
sprintf(Cmd,"%s -beossupportserver %d %d &",pg_pathname, (int)beos_dl_port_in, (int)beos_dl_port_out);
53+
sprintf(Cmd,"%s -beossupportserver %d %d &",my_exec_path, (int)beos_dl_port_in, (int)beos_dl_port_out);
5454

5555
/* Lauch process */
5656
system(Cmd);

‎src/backend/port/dynloader/bsdi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/port/dynloader/bsdi.c,v 1.23 2003/11/29 19:51:54 pgsql Exp $
14+
* $PostgreSQL: pgsql/src/backend/port/dynloader/bsdi.c,v 1.24 2004/05/13 22:45:02 momjian Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
1818
#include"postgres.h"
1919
#ifndefHAVE_DLOPEN
2020

21-
externcharpg_pathname[];
21+
externcharmy_exec_path[];
2222

2323
void*
2424
pg_dlopen(char*filename)
@@ -31,7 +31,7 @@ pg_dlopen(char *filename)
3131
*/
3232
if (!dl_initialized)
3333
{
34-
if (dld_init(dld_find_executable(pg_pathname)))
34+
if (dld_init(dld_find_executable(my_exec_path)))
3535
returnNULL;
3636

3737
/*

‎src/backend/port/dynloader/linux.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $PostgreSQL: pgsql/src/backend/port/dynloader/linux.c,v 1.27 2003/11/29 19:51:54 pgsql Exp $
14+
* $PostgreSQL: pgsql/src/backend/port/dynloader/linux.c,v 1.28 2004/05/13 22:45:02 momjian Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -43,7 +43,7 @@ pg_dlopen(char *filename)
4343
*/
4444
if (!dl_initialized)
4545
{
46-
if (dld_init(dld_find_executable(pg_pathname)))
46+
if (dld_init(dld_find_executable(my_exec_path)))
4747
returnNULL;
4848

4949
/*

‎src/backend/port/dynloader/ultrix4.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/port/dynloader/ultrix4.c,v 1.19 2003/11/29 19:51:54 pgsql Exp $
11+
* $PostgreSQL: pgsql/src/backend/port/dynloader/ultrix4.c,v 1.20 2004/05/13 22:45:02 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -17,7 +17,7 @@
1717
#include"dl.h"
1818
#include"utils/dynamic_loader.h"
1919

20-
externcharpg_pathname[];
20+
externcharmy_exec_path[];
2121

2222
void*
2323
pg_dlopen(char*filename)
@@ -31,7 +31,7 @@ pg_dlopen(char *filename)
3131
*/
3232
if (!dl_initialized)
3333
{
34-
if (!dl_init(pg_pathname))
34+
if (!dl_init(my_exec_path))
3535
returnNULL;
3636

3737
/*

‎src/backend/postmaster/pgstat.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*Copyright (c) 2001-2003, PostgreSQL Global Development Group
1515
*
16-
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.68 2004/05/06 19:23:25 momjian Exp $
16+
*$PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.69 2004/05/13 22:45:02 momjian Exp $
1717
* ----------
1818
*/
1919
#include"postgres.h"
@@ -487,7 +487,7 @@ pgstat_forkexec(STATS_PROCESS_TYPE procType)
487487
/* + the pstat file names, and postgres pathname */
488488
snprintf(pgstatBuf[bufc++],MAXPGPATH,"\"%s\"",pgStat_tmpfname);
489489
snprintf(pgstatBuf[bufc++],MAXPGPATH,"\"%s\"",pgStat_fname);
490-
snprintf(pgstatBuf[bufc++],MAXPGPATH,"\"%s\"",pg_pathname);
490+
snprintf(pgstatBuf[bufc++],MAXPGPATH,"\"%s\"",my_exec_path);/* used? */
491491
snprintf(pgstatBuf[bufc++],MAXPGPATH,"\"%s\"",DataDir);
492492

493493
/* Add to the arg list */
@@ -500,9 +500,9 @@ pgstat_forkexec(STATS_PROCESS_TYPE procType)
500500

501501
/* Fire off execv in child */
502502
#ifdefWIN32
503-
pid=win32_forkexec(pg_pathname,av);
503+
pid=win32_forkexec(my_exec_path,av);
504504
#else
505-
if ((pid=fork())==0&& (execv(pg_pathname,av)==-1))
505+
if ((pid=fork())==0&& (execv(my_exec_path,av)==-1))
506506
/* FIXME: [fork/exec] suggestions for what to do here? Can't call elog... */
507507
abort();
508508
#endif
@@ -530,9 +530,9 @@ pgstat_parseArgs(PGSTAT_FORK_ARGS)
530530
pgStatPipe[0]=atoi(argv[argc++]);
531531
pgStatPipe[1]=atoi(argv[argc++]);
532532
MaxBackends=atoi(argv[argc++]);
533-
strncpy(pgStat_tmpfname,argv[argc++],MAXPGPATH);
534-
strncpy(pgStat_fname,argv[argc++],MAXPGPATH);
535-
strncpy(pg_pathname,argv[argc++],MAXPGPATH);
533+
StrNCpy(pgStat_tmpfname,argv[argc++],MAXPGPATH);
534+
StrNCpy(pgStat_fname,argv[argc++],MAXPGPATH);
535+
StrNCpy(my_exec_path,argv[argc++],MAXPGPATH);
536536
DataDir=strdup(argv[argc++]);
537537

538538
read_nondefault_variables();

‎src/backend/postmaster/postmaster.c

Lines changed: 21 additions & 20 deletions
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.385 2004/05/12 13:38:39 momjian Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.386 2004/05/13 22:45:02 momjian Exp $
4141
*
4242
* NOTES
4343
*
@@ -181,7 +181,6 @@ static intListenSocket[MAXLISTEN];
181181
/* Used to reduce macros tests */
182182
#ifdefEXEC_BACKEND
183183
constboolExecBackend= true;
184-
185184
#else
186185
constboolExecBackend= false;
187186
#endif
@@ -286,7 +285,7 @@ static long PostmasterRandom(void);
286285
staticvoidRandomSalt(char*cryptSalt,char*md5Salt);
287286
staticvoidSignalChildren(intsignal);
288287
staticintCountChildren(void);
289-
staticboolCreateOptsFile(intargc,char*argv[]);
288+
staticboolCreateOptsFile(intargc,char*argv[],char*fullprogname);
290289
NON_EXEC_STATICvoidSSDataBaseInit(intxlop);
291290
staticpid_tSSDataBase(intxlop);
292291
staticvoid
@@ -295,6 +294,9 @@ postmaster_error(const char *fmt,...)
295294
__attribute__((format(printf,1,2)));
296295

297296
#ifdefEXEC_BACKEND
297+
298+
staticcharpostgres_exec_path[MAXPGPATH];
299+
298300
#ifdefWIN32
299301
pid_twin32_forkexec(constchar*path,char*argv[]);
300302

@@ -323,7 +325,6 @@ static void ShmemBackendArrayRemove(pid_t pid);
323325
#defineStartBackgroundWriter()SSDataBase(BS_XLOG_BGWRITER)
324326
#defineShutdownDataBase()SSDataBase(BS_XLOG_SHUTDOWN)
325327

326-
327328
staticvoid
328329
checkDataDir(constchar*checkdir)
329330
{
@@ -692,11 +693,18 @@ PostmasterMain(int argc, char *argv[])
692693
/*
693694
* On some systems our dynloader code needs the executable's pathname.
694695
*/
695-
if (find_my_exec(pg_pathname,argv[0])<0)
696+
if (find_my_exec(my_exec_path,argv[0])<0)
696697
ereport(FATAL,
697-
(errmsg("%s: could not locatepostgresexecutable",
698+
(errmsg("%s: could not locatemy ownexecutable path",
698699
progname)));
699700

701+
#ifdefEXEC_BACKEND
702+
if (find_other_exec(postgres_exec_path,argv[0],"postgres",PG_VERSIONSTR)<0)
703+
ereport(FATAL,
704+
(errmsg("%s: could not locate postgres executable or non-matching version",
705+
progname)));
706+
#endif
707+
700708
/*
701709
* Initialize SSL library, if specified.
702710
*/
@@ -852,7 +860,7 @@ PostmasterMain(int argc, char *argv[])
852860
* recording bogus options (eg, NBuffers too high for available
853861
* memory).
854862
*/
855-
if (!CreateOptsFile(argc,argv))
863+
if (!CreateOptsFile(argc,argv,my_exec_path))
856864
ExitPostmaster(1);
857865

858866
/*
@@ -2754,10 +2762,10 @@ Backend_forkexec(Port *port)
27542762
Assert(ac <=lengthof(av));
27552763

27562764
#ifdefWIN32
2757-
pid=win32_forkexec(pg_pathname,av);/* logs on error */
2765+
pid=win32_forkexec(postgres_exec_path,av);/* logs on error */
27582766
#else
27592767
/* Fire off execv in child */
2760-
if ((pid=fork())==0&& (execv(pg_pathname,av)==-1))
2768+
if ((pid=fork())==0&& (execv(postgres_exec_path,av)==-1))
27612769
/*
27622770
* FIXME: [fork/exec] suggestions for what to do here?
27632771
* Probably OK to issue error (unlike pgstat case)
@@ -3116,12 +3124,12 @@ SSDataBase(int xlop)
31163124
#ifdefEXEC_BACKEND
31173125
/* EXEC_BACKEND case; fork/exec here */
31183126
#ifdefWIN32
3119-
pid=win32_forkexec(pg_pathname,av);/* logs on error */
3127+
pid=win32_forkexec(postgres_exec_path,av);/* logs on error */
31203128
#else
3121-
if ((pid=fork())==0&& (execv(pg_pathname,av)==-1))
3129+
if ((pid=fork())==0&& (execv(postgres_exec_path,av)==-1))
31223130
{
31233131
/* in child */
3124-
elog(ERROR,"unable to execv in SSDataBase: %m");
3132+
elog(ERROR,"unable to execv in SSDataBase: %m");
31253133
exit(0);
31263134
}
31273135
#endif
@@ -3215,19 +3223,12 @@ SSDataBase(int xlop)
32153223
* Create the opts file
32163224
*/
32173225
staticbool
3218-
CreateOptsFile(intargc,char*argv[])
3226+
CreateOptsFile(intargc,char*argv[],char*fullprogname)
32193227
{
3220-
charfullprogname[MAXPGPATH];
32213228
charfilename[MAXPGPATH];
32223229
FILE*fp;
32233230
inti;
32243231

3225-
if (find_my_exec(fullprogname,argv[0])<0)
3226-
{
3227-
elog(LOG,"could not locate postmaster");
3228-
return false;
3229-
}
3230-
32313232
snprintf(filename,sizeof(filename),"%s/postmaster.opts",DataDir);
32323233

32333234
if ((fp=fopen(filename,"w"))==NULL)

‎src/backend/tcop/postgres.c

Lines changed: 4 additions & 6 deletions
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.404 2004/05/12 13:38:40 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.405 2004/05/13 22:45:03 momjian Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -2159,7 +2159,7 @@ PostgresMain(int argc, char *argv[], const char *username)
21592159
}
21602160
if (strcmp(argv[1],"--version")==0||strcmp(argv[1],"-V")==0)
21612161
{
2162-
puts("postgres (PostgreSQL) "PG_VERSION);
2162+
puts(PG_VERSIONSTR);
21632163
exit(0);
21642164
}
21652165
}
@@ -2646,14 +2646,12 @@ PostgresMain(int argc, char *argv[], const char *username)
26462646
}
26472647

26482648
/*
2649-
* On some systems our dynloader code needs the executable's
2650-
* pathname. (If under postmaster, this was done already.)
2649+
* On some systems our dynloader code needs the executable's pathname.
26512650
*/
2652-
if (find_my_exec(pg_pathname,argv[0])<0)
2651+
if (strlen(my_exec_path)==0&&find_my_exec(my_exec_path,argv[0])<0)
26532652
ereport(FATAL,
26542653
(errmsg("%s: could not locate postgres executable",
26552654
argv[0])));
2656-
26572655
/*
26582656
* Validate we have been given a reasonable-looking DataDir (if
26592657
* under postmaster, assume postmaster did this already).

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

Lines changed: 2 additions & 3 deletions
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.84 2004/02/10 03:42:45 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.85 2004/05/13 22:45:03 momjian Exp $
1212
*
1313
* NOTES
1414
* Globals used all over the place should be declared here and not
@@ -45,8 +45,7 @@ char *DataDir = NULL;
4545

4646
charOutputFileName[MAXPGPATH];
4747

48-
charpg_pathname[MAXPGPATH];/* full path to postgres
49-
* executable */
48+
charmy_exec_path[MAXPGPATH];/* full path to postgres executable */
5049

5150
BackendIdMyBackendId;
5251

‎src/include/miscadmin.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
16-
* $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.157 2004/05/11 21:57:15 momjian Exp $
16+
* $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.158 2004/05/13 22:45:04 momjian Exp $
1717
*
1818
* NOTES
1919
* some of the information in this file should be moved to
@@ -124,6 +124,8 @@ extern void SubPostmasterMain(int argc, char* argv[]);
124124
#endif
125125
externvoidClosePostmasterPorts(boolpgstat_too);
126126

127+
#definePG_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
128+
127129
/*
128130
* from utils/init/globals.c
129131
*/
@@ -140,7 +142,7 @@ extern struct Port *MyProcPort;
140142
externlongMyCancelKey;
141143

142144
externcharOutputFileName[];
143-
externcharpg_pathname[];
145+
externcharmy_exec_path[];
144146

145147
/*
146148
* done in storage/backendid.h for now.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp