Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4fd8d6b

Browse files
committed
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. Wecan't realistically set log_timezone any earlier than we do now, so the bestbehavior seems to be to use GMT zone if any timestamps are to be logged duringearly 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 itup without reference to any external files.
1 parent0b9d3d4 commit4fd8d6b

File tree

5 files changed

+67
-10
lines changed

5 files changed

+67
-10
lines changed

‎src/backend/utils/error/elog.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*
4343
*
4444
* IDENTIFICATION
45-
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.192 2007/08/0401:26:54 tgl Exp $
45+
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.193 2007/08/0419:29:25 tgl Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -1497,16 +1497,25 @@ log_line_prefix(StringInfo buf)
14971497
{
14981498
structtimevaltv;
14991499
pg_time_tstamp_time;
1500+
pg_tz*tz;
15001501
charstrfbuf[128],
15011502
msbuf[8];
15021503

15031504
gettimeofday(&tv,NULL);
15041505
stamp_time= (pg_time_t)tv.tv_sec;
15051506

1507+
/*
1508+
* Normally we print log timestamps in log_timezone, but
1509+
* during startup we could get here before that's set.
1510+
* If so, fall back to gmt_timezone (which guc.c ensures
1511+
* is set up before Log_line_prefix can become nonempty).
1512+
*/
1513+
tz=log_timezone ?log_timezone :gmt_timezone;
1514+
15061515
pg_strftime(strfbuf,sizeof(strfbuf),
15071516
/* leave room for milliseconds... */
15081517
"%Y-%m-%d %H:%M:%S %Z",
1509-
pg_localtime(&stamp_time,log_timezone));
1518+
pg_localtime(&stamp_time,tz));
15101519

15111520
/* 'paste' milliseconds into place... */
15121521
sprintf(msbuf,".%03d", (int) (tv.tv_usec /1000));
@@ -1518,22 +1527,28 @@ log_line_prefix(StringInfo buf)
15181527
case't':
15191528
{
15201529
pg_time_tstamp_time= (pg_time_t)time(NULL);
1530+
pg_tz*tz;
15211531
charstrfbuf[128];
15221532

1533+
tz=log_timezone ?log_timezone :gmt_timezone;
1534+
15231535
pg_strftime(strfbuf,sizeof(strfbuf),
15241536
"%Y-%m-%d %H:%M:%S %Z",
1525-
pg_localtime(&stamp_time,log_timezone));
1537+
pg_localtime(&stamp_time,tz));
15261538
appendStringInfoString(buf,strfbuf);
15271539
}
15281540
break;
15291541
case's':
15301542
{
15311543
pg_time_tstamp_time= (pg_time_t)MyStartTime;
1544+
pg_tz*tz;
15321545
charstrfbuf[128];
15331546

1547+
tz=log_timezone ?log_timezone :gmt_timezone;
1548+
15341549
pg_strftime(strfbuf,sizeof(strfbuf),
15351550
"%Y-%m-%d %H:%M:%S %Z",
1536-
pg_localtime(&stamp_time,log_timezone));
1551+
pg_localtime(&stamp_time,tz));
15371552
appendStringInfoString(buf,strfbuf);
15381553
}
15391554
break;

‎src/backend/utils/misc/guc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Written by Peter Eisentraut <peter_e@gmx.net>.
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.409 2007/08/0401:26:54 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/misc/guc.c,v 1.410 2007/08/0419:29:25 tgl Exp $
1414
*
1515
*--------------------------------------------------------------------
1616
*/
@@ -2926,6 +2926,12 @@ InitializeGUCOptions(void)
29262926
char*env;
29272927
longstack_rlimit;
29282928

2929+
/*
2930+
* Before log_line_prefix could possibly receive a nonempty setting,
2931+
* make sure that timezone processing is minimally alive (see elog.c).
2932+
*/
2933+
pg_timezone_pre_initialize();
2934+
29292935
/*
29302936
* Build sorted array of all GUC variables.
29312937
*/

‎src/include/pgtime.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/src/include/pgtime.h,v 1.16 2007/08/0401:26:54 tgl Exp $
9+
* $PostgreSQL: pgsql/src/include/pgtime.h,v 1.17 2007/08/0419:29:25 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -52,6 +52,7 @@ extern int pg_next_dst_boundary(const pg_time_t *timep,
5252
externsize_tpg_strftime(char*s,size_tmax,constchar*format,
5353
conststructpg_tm*tm);
5454

55+
externvoidpg_timezone_pre_initialize(void);
5556
externvoidpg_timezone_initialize(void);
5657
externpg_tz*pg_tzset(constchar*tzname);
5758
externbooltz_acceptable(pg_tz*tz);
@@ -64,6 +65,7 @@ extern void pg_tzenumerate_end(pg_tzenum *dir);
6465

6566
externpg_tz*session_timezone;
6667
externpg_tz*log_timezone;
68+
externpg_tz*gmt_timezone;
6769

6870
/* Maximum length of a timezone name (not including trailing null) */
6971
#defineTZ_STRLEN_MAX 255

‎src/timezone/localtime.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* 1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
44
*
55
* IDENTIFICATION
6-
* $PostgreSQL: pgsql/src/timezone/localtime.c,v 1.16 2006/10/18 16:43:14 tgl Exp $
6+
* $PostgreSQL: pgsql/src/timezone/localtime.c,v 1.17 2007/08/04 19:29:25 tgl Exp $
77
*/
88

99
/*
@@ -88,7 +88,6 @@ static void timesub(const pg_time_t *timep, long offset,
8888
conststructstate*sp,structpg_tm*tmp);
8989
staticpg_time_ttranstime(pg_time_tjanfirst,intyear,
9090
conststructrule*rulep,longoffset);
91-
inttzparse(constchar*name,structstate*sp,intlastditch);
9291

9392
/* GMT timezone */
9493
staticstructstategmtmem;
@@ -549,6 +548,12 @@ tzparse(const char *name, struct state * sp, int lastditch)
549548
if (stdlen >=sizeofsp->chars)
550549
stdlen= (sizeofsp->chars)-1;
551550
stdoffset=0;
551+
/*
552+
* Unlike the original zic library, do NOT invoke tzload() here;
553+
* we can't assume pg_open_tzfile() is sane yet, and we don't
554+
* care about leap seconds anyway.
555+
*/
556+
load_result=-1;
552557
}
553558
else
554559
{
@@ -561,8 +566,8 @@ tzparse(const char *name, struct state * sp, int lastditch)
561566
name=getoffset(name,&stdoffset);
562567
if (name==NULL)
563568
return-1;
569+
load_result=tzload(TZDEFRULES,NULL,sp);
564570
}
565-
load_result=tzload(TZDEFRULES,NULL,sp);
566571
if (load_result!=0)
567572
sp->leapcnt=0;/* so, we're off a little */
568573
if (*name!='\0')

‎src/timezone/pgtz.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
77
*
88
* IDENTIFICATION
9-
* $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.52 2007/08/0401:26:54 tgl Exp $
9+
* $PostgreSQL: pgsql/src/timezone/pgtz.c,v 1.53 2007/08/0419:29:25 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -33,6 +33,10 @@ pg_tz *session_timezone = NULL;
3333
/* Current log timezone (controlled by log_timezone GUC) */
3434
pg_tz*log_timezone=NULL;
3535

36+
/* Fallback GMT timezone for last-ditch error message formatting */
37+
pg_tz*gmt_timezone=NULL;
38+
staticpg_tzgmt_timezone_data;
39+
3640

3741
staticchartzdir[MAXPGPATH];
3842
staticbooldone_tzdir= false;
@@ -1251,6 +1255,31 @@ select_default_timezone(void)
12511255
returnNULL;/* keep compiler quiet */
12521256
}
12531257

1258+
1259+
/*
1260+
* Pre-initialize timezone library
1261+
*
1262+
* This is called before GUC variable initialization begins. Its purpose
1263+
* is to ensure that elog.c has a pgtz variable available to format timestamps
1264+
* with, in case log_line_prefix is set to a value requiring that. We cannot
1265+
* set log_timezone yet.
1266+
*/
1267+
void
1268+
pg_timezone_pre_initialize(void)
1269+
{
1270+
/*
1271+
* We can't use tzload() because we may not know where PGSHAREDIR
1272+
* is (in particular this is true in an EXEC_BACKEND subprocess).
1273+
* Since this timezone variable will only be used for emergency
1274+
* fallback purposes, it seems OK to just use the "lastditch" case
1275+
* provided by tzparse().
1276+
*/
1277+
if (tzparse("GMT",&gmt_timezone_data.state, TRUE)!=0)
1278+
elog(FATAL,"could not initialize GMT timezone");
1279+
strcpy(gmt_timezone_data.TZname,"GMT");
1280+
gmt_timezone=&gmt_timezone_data;
1281+
}
1282+
12541283
/*
12551284
* Initialize timezone library
12561285
*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp