postgresql/src
Tom Lane 3f721588ae Fix possible crashes due to using elog/ereport too early in startup.
Per reports from Andres Freund and Luke Campbell, a server failure during
set_pglocale_pgservice results in a segfault rather than a useful error
message, because the infrastructure needed to use ereport hasn't been
initialized; specifically, MemoryContextInit hasn't been called.
One known cause of this is starting the server in a directory it
doesn't have permission to read.

We could try to prevent set_pglocale_pgservice from using anything that
depends on palloc or elog, but that would be messy, and the odds of future
breakage seem high.  Moreover there are other things being called in main.c
that look likely to use palloc or elog too --- perhaps those things
shouldn't be there, but they are there today.  The best solution seems to
be to move the call of MemoryContextInit to very early in the backend's
real main() function.  I've verified that an elog or ereport occurring
immediately after that is now capable of sending something useful to
stderr.

I also added code to elog.c to print something intelligible rather than
just crashing if MemoryContextInit hasn't created the ErrorContext.
This could happen if MemoryContextInit itself fails (due to malloc
failure), and provides some future-proofing against someone trying to
sneak in new code even earlier in server startup.

Back-patch to all supported branches.  Since we've only heard reports of
this type of failure recently, it may be that some recent change has made
it more likely to see a crash of this kind; but it sure looks like it's
broken all the way back.
2014-01-11 16:35:37 -05:00
..
backend Fix possible crashes due to using elog/ereport too early in startup. 2014-01-11 16:35:37 -05:00
bin Don't attempt to limit target database for pg_restore. 2013-12-29 15:19:04 -06:00
include Stamp 9.1.11. 2013-12-02 16:02:21 -05:00
interfaces Fix descriptor output in ECPG. 2014-01-09 15:51:11 +01:00
makefiles Revert "Backpatch pgxs vpath build and installation fixes (v2)" 2013-10-07 22:39:30 -04:00
pl Translation updates 2013-12-02 00:06:28 -05:00
port Add "SHIFT_JIS" as an accepted encoding name for locale checking. 2013-12-15 11:10:56 +09:00
template Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
test Fix "cannot accept a set" error when only some arms of a CASE return a set. 2014-01-08 20:18:17 -05:00
timezone Update time zone data files to tzdata release 2013h. 2013-12-01 14:12:08 -05:00
tools Properly zero-pad the day-of-year part of the win32 build number 2013-01-31 15:08:05 +01:00
tutorial Modernize string literal syntax in tutorial example. 2013-01-19 17:21:08 -05:00
.gitignore Convert cvsignore to gitignore, and add .gitignore for build targets. 2010-09-22 12:57:04 +02:00
bcc32.mak Remove useless whitespace at end of lines 2010-11-23 22:34:55 +02:00
DEVELOPERS Replace a couple of references to files that no longer exist in the source 2009-05-04 08:08:47 +00:00
Makefile Fix some oversights in distprep and maintainer-clean targets. 2011-03-10 00:04:05 -05:00
Makefile.global.in Revert "Backpatch pgxs vpath build and installation fixes (v2)" 2013-10-07 22:39:30 -04:00
Makefile.shlib Use single quotes in preference to double quotes for protecting pathnames. 2011-06-15 21:45:50 -04:00
nls-global.mk Fix makefile logic to not break the build when xgettext is missing 2010-10-14 23:16:46 +03:00
win32.mak Remove useless whitespace at end of lines 2010-11-23 22:34:55 +02:00