Skip to content

Commit f69ecb4

Browse files
committed
Reorganize backend code to more cleanly manage executable names and
backend startup.
1 parent 261eda5 commit f69ecb4

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_id beos_dl_port_out = 0;
1616
sem_id beos_shm_sem;
1717

1818
/* Global var containing the postgres path */
19-
extern char pg_pathname[];
19+
extern char my_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
char Cmd[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
#ifndef HAVE_DLOPEN
2020

21-
extern char pg_pathname[];
21+
extern char my_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
return NULL;
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
return NULL;
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-
extern char pg_pathname[];
20+
extern char my_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
return NULL;
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
#ifdef WIN32
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 int ListenSocket[MAXLISTEN];
181181
/* Used to reduce macros tests */
182182
#ifdef EXEC_BACKEND
183183
const bool ExecBackend = true;
184-
185184
#else
186185
const bool ExecBackend = false;
187186
#endif
@@ -286,7 +285,7 @@ static long PostmasterRandom(void);
286285
static void RandomSalt(char *cryptSalt, char *md5Salt);
287286
static void SignalChildren(int signal);
288287
static int CountChildren(void);
289-
static bool CreateOptsFile(int argc, char *argv[]);
288+
static bool CreateOptsFile(int argc, char *argv[], char *fullprogname);
290289
NON_EXEC_STATIC void SSDataBaseInit(int xlop);
291290
static pid_t SSDataBase(int xlop);
292291
static void
@@ -295,6 +294,9 @@ postmaster_error(const char *fmt,...)
295294
__attribute__((format(printf, 1, 2)));
296295

297296
#ifdef EXEC_BACKEND
297+
298+
static char postgres_exec_path[MAXPGPATH];
299+
298300
#ifdef WIN32
299301
pid_t win32_forkexec(const char* path, char *argv[]);
300302

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

326-
327328
static void
328329
checkDataDir(const char *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 locate postgres executable",
698+
(errmsg("%s: could not locate my own executable path",
698699
progname)));
699700

701+
#ifdef EXEC_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
#ifdef WIN32
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
#ifdef EXEC_BACKEND
31173125
/* EXEC_BACKEND case; fork/exec here */
31183126
#ifdef WIN32
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
static bool
3218-
CreateOptsFile(int argc, char *argv[])
3226+
CreateOptsFile(int argc, char *argv[], char *fullprogname)
32193227
{
3220-
char fullprogname[MAXPGPATH];
32213228
char filename[MAXPGPATH];
32223229
FILE *fp;
32233230
int i;
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
char OutputFileName[MAXPGPATH];
4747

48-
char pg_pathname[MAXPGPATH]; /* full path to postgres
49-
* executable */
48+
char my_exec_path[MAXPGPATH]; /* full path to postgres executable */
5049

5150
BackendId MyBackendId;
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
extern void ClosePostmasterPorts(bool pgstat_too);
126126

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

142144
extern char OutputFileName[];
143-
extern char pg_pathname[];
145+
extern char my_exec_path[];
144146

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy