diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2009-05-02 22:02:37 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2009-05-02 22:02:37 +0000 |
commit | d90984f4f6f35cf77e05d76ad8ac63c30d9c0041 (patch) | |
tree | d6478c10aa605abbce682f431081a6f5b5443e25 /src/backend/utils/misc/tzparser.c | |
parent | a16e007c92b34c7f358689dbb8eb751026a51d60 (diff) | |
download | postgresql-d90984f4f6f35cf77e05d76ad8ac63c30d9c0041.tar.gz postgresql-d90984f4f6f35cf77e05d76ad8ac63c30d9c0041.zip |
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.
Diffstat (limited to 'src/backend/utils/misc/tzparser.c')
-rw-r--r-- | src/backend/utils/misc/tzparser.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/backend/utils/misc/tzparser.c b/src/backend/utils/misc/tzparser.c index f7d6c84514e..cc688dcaba1 100644 --- a/src/backend/utils/misc/tzparser.c +++ b/src/backend/utils/misc/tzparser.c @@ -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; } |