MyStartTime = time(NULL);
- /*
- * Fire up essential subsystems: error and memory management
- *
- * If we are running under the postmaster, this is done already.
- */
- if (!IsUnderPostmaster)
- MemoryContextInit();
-
/* Compute paths, if we didn't inherit them from postmaster */
if (my_exec_path[0] == '\0')
{
#include "postmaster/postmaster.h"
#include "tcop/tcopprot.h"
#include "utils/help_config.h"
+#include "utils/memutils.h"
#include "utils/pg_locale.h"
#include "utils/ps_status.h"
pgwin32_install_crashdump_handler();
#endif
+ /*
+ * Fire up essential subsystems: error and memory management
+ *
+ * Code after this point is allowed to use elog/ereport, though
+ * localization of messages may not work right away, and messages won't go
+ * anywhere but stderr until GUC settings get loaded.
+ */
+ MemoryContextInit();
+
/*
* Set up locale information from environment. Note that LC_CTYPE and
* LC_COLLATE will be overridden later from pg_control if we are in an
*/
umask(S_IRWXG | S_IRWXO);
- /*
- * Fire up essential subsystems: memory management
- */
- MemoryContextInit();
-
/*
* By default, palloc() requests in the postmaster will be allocated in
* the PostmasterContext, which is space that can be recycled by backends.
whereToSendOutput = DestNone;
/* Setup essential subsystems (to ensure elog() behaves sanely) */
- MemoryContextInit();
InitializeGUCOptions();
/* Read in the variables file */
MyStartTime = time(NULL);
}
- /*
- * Fire up essential subsystems: error and memory management
- *
- * If we are running under the postmaster, this is done already.
- */
- if (!IsUnderPostmaster)
- MemoryContextInit();
-
SetProcessingMode(InitProcessing);
/* Compute paths, if we didn't inherit them from postmaster */
if (elevel < ERROR && !output_to_server && !output_to_client)
return false;
+ /*
+ * We need to do some actual work. Make sure that memory context
+ * initialization has finished, else we can't do anything useful.
+ */
+ if (ErrorContext == NULL)
+ {
+ /* Ooops, hard crash time; very little we can do safely here */
+ write_stderr("error occurred at %s:%d before error message processing is available\n",
+ filename ? filename : "(unknown file)", lineno);
+ exit(2);
+ }
+
/*
* Okay, crank up a stack entry to store the info in.
*/
{
ErrorData *edata;
+ /* Make sure that memory context initialization has finished */
+ if (ErrorContext == NULL)
+ {
+ /* Ooops, hard crash time; very little we can do safely here */
+ write_stderr("error occurred at %s:%d before error message processing is available\n",
+ filename ? filename : "(unknown file)", lineno);
+ exit(2);
+ }
+
if (++errordata_stack_depth >= ERRORDATA_STACK_SIZE)
{
/*
* In normal multi-backend operation, this is called once during
* postmaster startup, and not at all by individual backend startup
* (since the backends inherit an already-initialized context subsystem
- * by virtue of being forked off the postmaster).
+ * by virtue of being forked off the postmaster). But in an EXEC_BACKEND
+ * build, each process must do this for itself.
*
* In a standalone backend this must be called during backend startup.
*/
* where retained memory in a context is *essential* --- we want to be
* sure ErrorContext still has some memory even if we've run out
* elsewhere!
+ *
+ * This should be the last step in this function, as elog.c assumes memory
+ * management works once ErrorContext is non-null.
*/
ErrorContext = AllocSetContextCreate(TopMemoryContext,
"ErrorContext",