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

Commitd90984f

Browse files
committed
Install some simple defenses in postmaster startup to help ensure a useful
error message if the installation directory layout is messed up (or at least,something more useful than the behavior exhibited in bug #4787). Duringpostmaster startup, check that get_pkglib_path resolves as a readabledirectory; and if ParseTzFile() fails to open the expected timezoneabbreviation file, check the possibility that the directory is missing ratherthan just the specified file. In case of either failure, issue a hintsuggesting that the installation is broken. These two checks cover the lib/and share/ trees of a full installation, which should take care of mostscenarios where a sysadmin decides to get cute.
1 parenta16e007 commitd90984f

File tree

2 files changed

+87
-17
lines changed

2 files changed

+87
-17
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 56 additions & 15 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.577 2009/04/05 04:19:58 tgl Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.578 2009/05/02 22:02:37 tgl Exp $
4141
*
4242
* NOTES
4343
*
@@ -315,6 +315,7 @@ extern intoptreset;/* might not be declared by system headers */
315315
/*
316316
* postmaster.c - function prototypes
317317
*/
318+
staticvoidgetInstallationPaths(constchar*argv0);
318319
staticvoidcheckDataDir(void);
319320

320321
#ifdefUSE_BONJOUR
@@ -493,11 +494,8 @@ PostmasterMain(int argc, char *argv[])
493494
ALLOCSET_DEFAULT_MAXSIZE);
494495
MemoryContextSwitchTo(PostmasterContext);
495496

496-
if (find_my_exec(argv[0],my_exec_path)<0)
497-
elog(FATAL,"%s: could not locate my own executable path",
498-
argv[0]);
499-
500-
get_pkglib_path(my_exec_path,pkglib_path);
497+
/* Initialize paths to installation files */
498+
getInstallationPaths(argv[0]);
501499

502500
/*
503501
* Options setup
@@ -690,15 +688,6 @@ PostmasterMain(int argc, char *argv[])
690688
ExitPostmaster(1);
691689
}
692690

693-
#ifdefEXEC_BACKEND
694-
/* Locate executable backend before we change working directory */
695-
if (find_other_exec(argv[0],"postgres",PG_BACKEND_VERSIONSTR,
696-
postgres_exec_path)<0)
697-
ereport(FATAL,
698-
(errmsg("%s: could not locate matching postgres executable",
699-
progname)));
700-
#endif
701-
702691
/*
703692
* Locate the proper configuration files and data directory, and read
704693
* postgresql.conf for the first time.
@@ -1062,6 +1051,58 @@ PostmasterMain(int argc, char *argv[])
10621051
}
10631052

10641053

1054+
/*
1055+
* Compute and check the directory paths to files that are part of the
1056+
* installation (as deduced from the postgres executable's own location)
1057+
*/
1058+
staticvoid
1059+
getInstallationPaths(constchar*argv0)
1060+
{
1061+
DIR*pdir;
1062+
1063+
/* Locate the postgres executable itself */
1064+
if (find_my_exec(argv0,my_exec_path)<0)
1065+
elog(FATAL,"%s: could not locate my own executable path",argv0);
1066+
1067+
#ifdefEXEC_BACKEND
1068+
/* Locate executable backend before we change working directory */
1069+
if (find_other_exec(argv0,"postgres",PG_BACKEND_VERSIONSTR,
1070+
postgres_exec_path)<0)
1071+
ereport(FATAL,
1072+
(errmsg("%s: could not locate matching postgres executable",
1073+
argv0)));
1074+
#endif
1075+
1076+
/*
1077+
* Locate the pkglib directory --- this has to be set early in case we try
1078+
* to load any modules from it in response to postgresql.conf entries.
1079+
*/
1080+
get_pkglib_path(my_exec_path,pkglib_path);
1081+
1082+
/*
1083+
* Verify that there's a readable directory there; otherwise the
1084+
* Postgres installation is incomplete or corrupt. (A typical cause
1085+
* of this failure is that the postgres executable has been moved or
1086+
* hardlinked to some directory that's not a sibling of the installation
1087+
* lib/ directory.)
1088+
*/
1089+
pdir=AllocateDir(pkglib_path);
1090+
if (pdir==NULL)
1091+
ereport(ERROR,
1092+
(errcode_for_file_access(),
1093+
errmsg("could not open directory \"%s\": %m",
1094+
pkglib_path),
1095+
errhint("This may indicate an incomplete PostgreSQL installation, or that the file \"%s\" has been moved away from its proper location.",
1096+
my_exec_path)));
1097+
FreeDir(pdir);
1098+
1099+
/*
1100+
* XXX is it worth similarly checking the share/ directory? If the
1101+
* lib/ directory is there, then share/ probably is too.
1102+
*/
1103+
}
1104+
1105+
10651106
/*
10661107
* Validate the proposed data directory
10671108
*/

‎src/backend/utils/misc/tzparser.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/utils/misc/tzparser.c,v 1.7 2009/01/01 17:23:53 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/utils/misc/tzparser.c,v 1.8 2009/05/02 22:02:37 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -326,12 +326,41 @@ ParseTzFile(const char *filename, int depth,
326326
tzFile=AllocateFile(file_path,"r");
327327
if (!tzFile)
328328
{
329-
/* at level 0, if file doesn't exist, guc.c's complaint is enough */
329+
/*
330+
* Check to see if the problem is not the filename but the directory.
331+
* This is worth troubling over because if the installation share/
332+
* directory is missing or unreadable, this is likely to be the first
333+
* place we notice a problem during postmaster startup.
334+
*/
335+
intsave_errno=errno;
336+
DIR*tzdir;
337+
338+
snprintf(file_path,sizeof(file_path),"%s/timezonesets",
339+
share_path);
340+
tzdir=AllocateDir(file_path);
341+
if (tzdir==NULL)
342+
{
343+
ereport(tz_elevel,
344+
(errcode_for_file_access(),
345+
errmsg("could not open directory \"%s\": %m",
346+
file_path),
347+
errhint("This may indicate an incomplete PostgreSQL installation, or that the file \"%s\" has been moved away from its proper location.",
348+
my_exec_path)));
349+
return-1;
350+
}
351+
FreeDir(tzdir);
352+
errno=save_errno;
353+
354+
/*
355+
* otherwise, if file doesn't exist and it's level 0, guc.c's
356+
* complaint is enough
357+
*/
330358
if (errno!=ENOENT||depth>0)
331359
ereport(tz_elevel,
332360
(errcode_for_file_access(),
333361
errmsg("could not read time zone file \"%s\": %m",
334362
filename)));
363+
335364
return-1;
336365
}
337366

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp