1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-03 20:02:46 +03:00

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).  During
postmaster startup, check that get_pkglib_path resolves as a readable
directory; and if ParseTzFile() fails to open the expected timezone
abbreviation file, check the possibility that the directory is missing rather
than just the specified file.  In case of either failure, issue a hint
suggesting that the installation is broken.  These two checks cover the lib/
and share/ trees of a full installation, which should take care of most
scenarios where a sysadmin decides to get cute.
This commit is contained in:
Tom Lane
2009-05-02 22:02:37 +00:00
parent a16e007c92
commit d90984f4f6
2 changed files with 87 additions and 17 deletions

View File

@ -13,7 +13,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/misc/tzparser.c,v 1.7 2009/01/01 17:23:53 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/misc/tzparser.c,v 1.8 2009/05/02 22:02:37 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -326,12 +326,41 @@ ParseTzFile(const char *filename, int depth,
tzFile = AllocateFile(file_path, "r");
if (!tzFile)
{
/* at level 0, if file doesn't exist, guc.c's complaint is enough */
/*
* Check to see if the problem is not the filename but the directory.
* This is worth troubling over because if the installation share/
* directory is missing or unreadable, this is likely to be the first
* place we notice a problem during postmaster startup.
*/
int save_errno = errno;
DIR *tzdir;
snprintf(file_path, sizeof(file_path), "%s/timezonesets",
share_path);
tzdir = AllocateDir(file_path);
if (tzdir == NULL)
{
ereport(tz_elevel,
(errcode_for_file_access(),
errmsg("could not open directory \"%s\": %m",
file_path),
errhint("This may indicate an incomplete PostgreSQL installation, or that the file \"%s\" has been moved away from its proper location.",
my_exec_path)));
return -1;
}
FreeDir(tzdir);
errno = save_errno;
/*
* otherwise, if file doesn't exist and it's level 0, guc.c's
* complaint is enough
*/
if (errno != ENOENT || depth > 0)
ereport(tz_elevel,
(errcode_for_file_access(),
errmsg("could not read time zone file \"%s\": %m",
filename)));
return -1;
}