summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorTom Lane2008-02-17 02:09:32 +0000
committerTom Lane2008-02-17 02:09:32 +0000
commitcd004067742ee16ee63e55abfb4acbd5f09fbaab (patch)
tree62995d45f55faf5f5cdddc791d4d83d3de495b03 /src/bin
parentee7a6770f607e9e7f0e1b29dc25a7b7d63cb7940 (diff)
Replace time_t with pg_time_t (same values, but always int64) in on-disk
data structures and backend internal APIs. This solves problems we've seen recently with inconsistent layout of pg_control between machines that have 32-bit time_t and those that have already migrated to 64-bit time_t. Also, we can get out from under the problem that Windows' Unix-API emulation is not consistent about the width of time_t. There are a few remaining places where local time_t variables are used to hold the current or recent result of time(NULL). I didn't bother changing these since they do not affect any cross-module APIs and surely all platforms will have 64-bit time_t before overflow becomes an actual risk. time_t should be avoided for anything visible to extension modules, however.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/pg_controldata/pg_controldata.c14
-rw-r--r--src/bin/pg_resetxlog/pg_resetxlog.c10
2 files changed, 16 insertions, 8 deletions
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 682a5cf3807..4cb6ada3129 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -6,7 +6,7 @@
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
* licence: BSD
*
- * $PostgreSQL: pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.36 2008/01/21 11:17:46 petere Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.37 2008/02/17 02:09:29 tgl Exp $
*/
#include "postgres.h"
@@ -69,6 +69,7 @@ main(int argc, char *argv[])
char ControlFilePath[MAXPGPATH];
char *DataDir;
pg_crc32 crc;
+ time_t time_tmp;
char pgctime_str[128];
char ckpttime_str[128];
char sysident_str[32];
@@ -134,13 +135,20 @@ main(int argc, char *argv[])
"is expecting. The results below are untrustworthy.\n\n"));
/*
+ * This slightly-chintzy coding will work as long as the control file
+ * timestamps are within the range of time_t; that should be the case
+ * in all foreseeable circumstances, so we don't bother importing the
+ * backend's timezone library into pg_controldata.
+ *
* Use variable for format to suppress overly-anal-retentive gcc warning
* about %c
*/
+ time_tmp = (time_t) ControlFile.time;
strftime(pgctime_str, sizeof(pgctime_str), strftime_fmt,
- localtime(&(ControlFile.time)));
+ localtime(&time_tmp));
+ time_tmp = (time_t) ControlFile.checkPointCopy.time;
strftime(ckpttime_str, sizeof(ckpttime_str), strftime_fmt,
- localtime(&(ControlFile.checkPointCopy.time)));
+ localtime(&time_tmp));
/*
* Format system_identifier separately to keep platform-dependent format
diff --git a/src/bin/pg_resetxlog/pg_resetxlog.c b/src/bin/pg_resetxlog/pg_resetxlog.c
index 83b6b4b1d7a..86c4463a2ce 100644
--- a/src/bin/pg_resetxlog/pg_resetxlog.c
+++ b/src/bin/pg_resetxlog/pg_resetxlog.c
@@ -23,7 +23,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.63 2008/01/01 19:45:55 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_resetxlog/pg_resetxlog.c,v 1.64 2008/02/17 02:09:30 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -471,10 +471,10 @@ GuessControlValues(void)
ControlFile.checkPointCopy.nextOid = FirstBootstrapObjectId;
ControlFile.checkPointCopy.nextMulti = FirstMultiXactId;
ControlFile.checkPointCopy.nextMultiOffset = 0;
- ControlFile.checkPointCopy.time = time(NULL);
+ ControlFile.checkPointCopy.time = (pg_time_t) time(NULL);
ControlFile.state = DB_SHUTDOWNED;
- ControlFile.time = time(NULL);
+ ControlFile.time = (pg_time_t) time(NULL);
ControlFile.checkPoint = ControlFile.checkPointCopy.redo;
ControlFile.maxAlign = MAXIMUM_ALIGNOF;
@@ -603,10 +603,10 @@ RewriteControlFile(void)
ControlFile.checkPointCopy.redo.xlogid = newXlogId;
ControlFile.checkPointCopy.redo.xrecoff =
newXlogSeg * XLogSegSize + SizeOfXLogLongPHD;
- ControlFile.checkPointCopy.time = time(NULL);
+ ControlFile.checkPointCopy.time = (pg_time_t) time(NULL);
ControlFile.state = DB_SHUTDOWNED;
- ControlFile.time = time(NULL);
+ ControlFile.time = (pg_time_t) time(NULL);
ControlFile.checkPoint = ControlFile.checkPointCopy.redo;
ControlFile.prevCheckPoint.xlogid = 0;
ControlFile.prevCheckPoint.xrecoff = 0;