summaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
authorTom Lane2007-08-04 19:29:25 +0000
committerTom Lane2007-08-04 19:29:25 +0000
commit4fd8d6b3e77eb00cfd7bb8d3d130b147ba0d60f3 (patch)
treee8fa7630964d3439c12aa3667ace88e318de074b /src/backend/utils
parent0b9d3d4dcd0561fbf674e09af1160f087eda535b (diff)
Fix crash caused by log_timezone patch if we attempt to emit any elog messages
between the setting of log_line_prefix and the setting of log_timezone. We can't realistically set log_timezone any earlier than we do now, so the best behavior seems to be to use GMT zone if any timestamps are to be logged during early startup. Create a dummy zone variable with a minimal definition of GMT (in particular it will never know about leap seconds), so that we can set it up without reference to any external files.
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/error/elog.c23
-rw-r--r--src/backend/utils/misc/guc.c8
2 files changed, 26 insertions, 5 deletions
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index d51dd0bf1af..44d02752080 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -42,7 +42,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.192 2007/08/04 01:26:54 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.193 2007/08/04 19:29:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1497,16 +1497,25 @@ log_line_prefix(StringInfo buf)
{
struct timeval tv;
pg_time_t stamp_time;
+ pg_tz *tz;
char strfbuf[128],
msbuf[8];
gettimeofday(&tv, NULL);
stamp_time = (pg_time_t) tv.tv_sec;
+ /*
+ * Normally we print log timestamps in log_timezone, but
+ * during startup we could get here before that's set.
+ * If so, fall back to gmt_timezone (which guc.c ensures
+ * is set up before Log_line_prefix can become nonempty).
+ */
+ tz = log_timezone ? log_timezone : gmt_timezone;
+
pg_strftime(strfbuf, sizeof(strfbuf),
/* leave room for milliseconds... */
"%Y-%m-%d %H:%M:%S %Z",
- pg_localtime(&stamp_time, log_timezone));
+ pg_localtime(&stamp_time, tz));
/* 'paste' milliseconds into place... */
sprintf(msbuf, ".%03d", (int) (tv.tv_usec / 1000));
@@ -1518,22 +1527,28 @@ log_line_prefix(StringInfo buf)
case 't':
{
pg_time_t stamp_time = (pg_time_t) time(NULL);
+ pg_tz *tz;
char strfbuf[128];
+ tz = log_timezone ? log_timezone : gmt_timezone;
+
pg_strftime(strfbuf, sizeof(strfbuf),
"%Y-%m-%d %H:%M:%S %Z",
- pg_localtime(&stamp_time, log_timezone));
+ pg_localtime(&stamp_time, tz));
appendStringInfoString(buf, strfbuf);
}
break;
case 's':
{
pg_time_t stamp_time = (pg_time_t) MyStartTime;
+ pg_tz *tz;
char strfbuf[128];
+ tz = log_timezone ? log_timezone : gmt_timezone;
+
pg_strftime(strfbuf, sizeof(strfbuf),
"%Y-%m-%d %H:%M:%S %Z",
- pg_localtime(&stamp_time, log_timezone));
+ pg_localtime(&stamp_time, tz));
appendStringInfoString(buf, strfbuf);
}
break;
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index fc35b14cf3f..45fef6d7a31 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -10,7 +10,7 @@
* Written by Peter Eisentraut <peter_e@gmx.net>.
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.409 2007/08/04 01:26:54 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.410 2007/08/04 19:29:25 tgl Exp $
*
*--------------------------------------------------------------------
*/
@@ -2927,6 +2927,12 @@ InitializeGUCOptions(void)
long stack_rlimit;
/*
+ * Before log_line_prefix could possibly receive a nonempty setting,
+ * make sure that timezone processing is minimally alive (see elog.c).
+ */
+ pg_timezone_pre_initialize();
+
+ /*
* Build sorted array of all GUC variables.
*/
build_guc_variables();