Commit cd004067 authored by Tom Lane's avatar Tom Lane

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.
parent ee7a6770
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.27 2007/11/15 21:14:31 momjian Exp $ * $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.28 2008/02/17 02:09:26 tgl Exp $
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -649,7 +649,8 @@ system_reseed(void) ...@@ -649,7 +649,8 @@ system_reseed(void)
skip = 1; skip = 1;
else if ((t - seed_time) > SYSTEM_RESEED_MAX) else if ((t - seed_time) > SYSTEM_RESEED_MAX)
skip = 0; skip = 0;
else if (!check_time || (t - check_time) > SYSTEM_RESEED_CHECK_TIME) else if (check_time == 0 ||
(t - check_time) > SYSTEM_RESEED_CHECK_TIME)
{ {
check_time = t; check_time = t;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.292 2008/01/21 11:17:46 petere Exp $ * $PostgreSQL: pgsql/src/backend/access/transam/xlog.c,v 1.293 2008/02/17 02:09:27 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -271,7 +271,7 @@ typedef struct XLogCtlWrite ...@@ -271,7 +271,7 @@ typedef struct XLogCtlWrite
{ {
XLogwrtResult LogwrtResult; /* current value of LogwrtResult */ XLogwrtResult LogwrtResult; /* current value of LogwrtResult */
int curridx; /* cache index of next block to write */ int curridx; /* cache index of next block to write */
time_t lastSegSwitchTime; /* time of last xlog segment switch */ pg_time_t lastSegSwitchTime; /* time of last xlog segment switch */
} XLogCtlWrite; } XLogCtlWrite;
/* /*
...@@ -1553,7 +1553,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch) ...@@ -1553,7 +1553,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch)
if (XLogArchivingActive()) if (XLogArchivingActive())
XLogArchiveNotifySeg(openLogId, openLogSeg); XLogArchiveNotifySeg(openLogId, openLogSeg);
Write->lastSegSwitchTime = time(NULL); Write->lastSegSwitchTime = (pg_time_t) time(NULL);
/* /*
* Signal bgwriter to start a checkpoint if we've consumed too * Signal bgwriter to start a checkpoint if we've consumed too
...@@ -4217,7 +4217,7 @@ BootStrapXLOG(void) ...@@ -4217,7 +4217,7 @@ BootStrapXLOG(void)
checkPoint.nextOid = FirstBootstrapObjectId; checkPoint.nextOid = FirstBootstrapObjectId;
checkPoint.nextMulti = FirstMultiXactId; checkPoint.nextMulti = FirstMultiXactId;
checkPoint.nextMultiOffset = 0; checkPoint.nextMultiOffset = 0;
checkPoint.time = time(NULL); checkPoint.time = (pg_time_t) time(NULL);
ShmemVariableCache->nextXid = checkPoint.nextXid; ShmemVariableCache->nextXid = checkPoint.nextXid;
ShmemVariableCache->nextOid = checkPoint.nextOid; ShmemVariableCache->nextOid = checkPoint.nextOid;
...@@ -4972,7 +4972,7 @@ StartupXLOG(void) ...@@ -4972,7 +4972,7 @@ StartupXLOG(void)
ControlFile->checkPointCopy = checkPoint; ControlFile->checkPointCopy = checkPoint;
if (minRecoveryLoc.xlogid != 0 || minRecoveryLoc.xrecoff != 0) if (minRecoveryLoc.xlogid != 0 || minRecoveryLoc.xrecoff != 0)
ControlFile->minRecoveryPoint = minRecoveryLoc; ControlFile->minRecoveryPoint = minRecoveryLoc;
ControlFile->time = time(NULL); ControlFile->time = (pg_time_t) time(NULL);
UpdateControlFile(); UpdateControlFile();
/* /*
...@@ -5277,7 +5277,7 @@ StartupXLOG(void) ...@@ -5277,7 +5277,7 @@ StartupXLOG(void)
InRecovery = false; InRecovery = false;
ControlFile->state = DB_IN_PRODUCTION; ControlFile->state = DB_IN_PRODUCTION;
ControlFile->time = time(NULL); ControlFile->time = (pg_time_t) time(NULL);
UpdateControlFile(); UpdateControlFile();
/* start the archive_timeout timer running */ /* start the archive_timeout timer running */
...@@ -5496,10 +5496,10 @@ GetInsertRecPtr(void) ...@@ -5496,10 +5496,10 @@ GetInsertRecPtr(void)
/* /*
* Get the time of the last xlog segment switch * Get the time of the last xlog segment switch
*/ */
time_t pg_time_t
GetLastSegSwitchTime(void) GetLastSegSwitchTime(void)
{ {
time_t result; pg_time_t result;
/* Need WALWriteLock, but shared lock is sufficient */ /* Need WALWriteLock, but shared lock is sufficient */
LWLockAcquire(WALWriteLock, LW_SHARED); LWLockAcquire(WALWriteLock, LW_SHARED);
...@@ -5676,7 +5676,7 @@ CreateCheckPoint(int flags) ...@@ -5676,7 +5676,7 @@ CreateCheckPoint(int flags)
if (shutdown) if (shutdown)
{ {
ControlFile->state = DB_SHUTDOWNING; ControlFile->state = DB_SHUTDOWNING;
ControlFile->time = time(NULL); ControlFile->time = (pg_time_t) time(NULL);
UpdateControlFile(); UpdateControlFile();
} }
...@@ -5690,7 +5690,7 @@ CreateCheckPoint(int flags) ...@@ -5690,7 +5690,7 @@ CreateCheckPoint(int flags)
/* Begin filling in the checkpoint WAL record */ /* Begin filling in the checkpoint WAL record */
MemSet(&checkPoint, 0, sizeof(checkPoint)); MemSet(&checkPoint, 0, sizeof(checkPoint));
checkPoint.ThisTimeLineID = ThisTimeLineID; checkPoint.ThisTimeLineID = ThisTimeLineID;
checkPoint.time = time(NULL); checkPoint.time = (pg_time_t) time(NULL);
/* /*
* We must hold WALInsertLock while examining insert state to determine * We must hold WALInsertLock while examining insert state to determine
...@@ -5891,7 +5891,7 @@ CreateCheckPoint(int flags) ...@@ -5891,7 +5891,7 @@ CreateCheckPoint(int flags)
ControlFile->prevCheckPoint = ControlFile->checkPoint; ControlFile->prevCheckPoint = ControlFile->checkPoint;
ControlFile->checkPoint = ProcLastRecPtr; ControlFile->checkPoint = ProcLastRecPtr;
ControlFile->checkPointCopy = checkPoint; ControlFile->checkPointCopy = checkPoint;
ControlFile->time = time(NULL); ControlFile->time = (pg_time_t) time(NULL);
UpdateControlFile(); UpdateControlFile();
LWLockRelease(ControlFileLock); LWLockRelease(ControlFileLock);
...@@ -5992,7 +5992,7 @@ RecoveryRestartPoint(const CheckPoint *checkPoint) ...@@ -5992,7 +5992,7 @@ RecoveryRestartPoint(const CheckPoint *checkPoint)
* Checking true elapsed time keeps us from doing restartpoints too often * Checking true elapsed time keeps us from doing restartpoints too often
* while rapidly scanning large amounts of WAL. * while rapidly scanning large amounts of WAL.
*/ */
elapsed_secs = time(NULL) - ControlFile->time; elapsed_secs = (pg_time_t) time(NULL) - ControlFile->time;
if (elapsed_secs < CheckPointTimeout / 2) if (elapsed_secs < CheckPointTimeout / 2)
return; return;
...@@ -6028,7 +6028,7 @@ RecoveryRestartPoint(const CheckPoint *checkPoint) ...@@ -6028,7 +6028,7 @@ RecoveryRestartPoint(const CheckPoint *checkPoint)
ControlFile->prevCheckPoint = ControlFile->checkPoint; ControlFile->prevCheckPoint = ControlFile->checkPoint;
ControlFile->checkPoint = ReadRecPtr; ControlFile->checkPoint = ReadRecPtr;
ControlFile->checkPointCopy = *checkPoint; ControlFile->checkPointCopy = *checkPoint;
ControlFile->time = time(NULL); ControlFile->time = (pg_time_t) time(NULL);
UpdateControlFile(); UpdateControlFile();
ereport((recoveryLogRestartpoints ? LOG : DEBUG2), ereport((recoveryLogRestartpoints ? LOG : DEBUG2),
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.48 2008/01/01 19:45:51 momjian Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.49 2008/02/17 02:09:27 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -163,12 +163,12 @@ static bool am_bg_writer = false; ...@@ -163,12 +163,12 @@ static bool am_bg_writer = false;
static bool ckpt_active = false; static bool ckpt_active = false;
/* these values are valid when ckpt_active is true: */ /* these values are valid when ckpt_active is true: */
static time_t ckpt_start_time; static pg_time_t ckpt_start_time;
static XLogRecPtr ckpt_start_recptr; static XLogRecPtr ckpt_start_recptr;
static double ckpt_cached_elapsed; static double ckpt_cached_elapsed;
static time_t last_checkpoint_time; static pg_time_t last_checkpoint_time;
static time_t last_xlog_switch_time; static pg_time_t last_xlog_switch_time;
/* Prototypes for private functions */ /* Prototypes for private functions */
...@@ -250,7 +250,7 @@ BackgroundWriterMain(void) ...@@ -250,7 +250,7 @@ BackgroundWriterMain(void)
/* /*
* Initialize so that first time-driven event happens at the correct time. * Initialize so that first time-driven event happens at the correct time.
*/ */
last_checkpoint_time = last_xlog_switch_time = time(NULL); last_checkpoint_time = last_xlog_switch_time = (pg_time_t) time(NULL);
/* /*
* Create a resource owner to keep track of our resources (currently only * Create a resource owner to keep track of our resources (currently only
...@@ -361,7 +361,7 @@ BackgroundWriterMain(void) ...@@ -361,7 +361,7 @@ BackgroundWriterMain(void)
{ {
bool do_checkpoint = false; bool do_checkpoint = false;
int flags = 0; int flags = 0;
time_t now; pg_time_t now;
int elapsed_secs; int elapsed_secs;
/* /*
...@@ -407,7 +407,7 @@ BackgroundWriterMain(void) ...@@ -407,7 +407,7 @@ BackgroundWriterMain(void)
* occurs without an external request, but we set the CAUSE_TIME flag * occurs without an external request, but we set the CAUSE_TIME flag
* bit even if there is also an external request. * bit even if there is also an external request.
*/ */
now = time(NULL); now = (pg_time_t) time(NULL);
elapsed_secs = now - last_checkpoint_time; elapsed_secs = now - last_checkpoint_time;
if (elapsed_secs >= CheckPointTimeout) if (elapsed_secs >= CheckPointTimeout)
{ {
...@@ -504,13 +504,13 @@ BackgroundWriterMain(void) ...@@ -504,13 +504,13 @@ BackgroundWriterMain(void)
static void static void
CheckArchiveTimeout(void) CheckArchiveTimeout(void)
{ {
time_t now; pg_time_t now;
time_t last_time; pg_time_t last_time;
if (XLogArchiveTimeout <= 0) if (XLogArchiveTimeout <= 0)
return; return;
now = time(NULL); now = (pg_time_t) time(NULL);
/* First we do a quick check using possibly-stale local state. */ /* First we do a quick check using possibly-stale local state. */
if ((int) (now - last_xlog_switch_time) < XLogArchiveTimeout) if ((int) (now - last_xlog_switch_time) < XLogArchiveTimeout)
...@@ -730,7 +730,7 @@ IsCheckpointOnSchedule(double progress) ...@@ -730,7 +730,7 @@ IsCheckpointOnSchedule(double progress)
* Check progress against time elapsed and checkpoint_timeout. * Check progress against time elapsed and checkpoint_timeout.
*/ */
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
elapsed_time = ((double) (now.tv_sec - ckpt_start_time) + elapsed_time = ((double) ((pg_time_t) now.tv_sec - ckpt_start_time) +
now.tv_usec / 1000000.0) / CheckPointTimeout; now.tv_usec / 1000000.0) / CheckPointTimeout;
if (progress < elapsed_time) if (progress < elapsed_time)
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.44 2008/01/25 20:42:10 tgl Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.45 2008/02/17 02:09:27 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -331,7 +331,7 @@ SysLoggerMain(int argc, char *argv[]) ...@@ -331,7 +331,7 @@ SysLoggerMain(int argc, char *argv[])
if (!rotation_requested && Log_RotationAge > 0) if (!rotation_requested && Log_RotationAge > 0)
{ {
/* Do a logfile rotation if it's time */ /* Do a logfile rotation if it's time */
pg_time_t now = time(NULL); pg_time_t now = (pg_time_t) time(NULL);
if (now >= next_rotation_time) if (now >= next_rotation_time)
rotation_requested = time_based_rotation = true; rotation_requested = time_based_rotation = true;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.138 2008/01/01 19:45:52 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/date.c,v 1.139 2008/02/17 02:09:28 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -945,8 +945,10 @@ tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result) ...@@ -945,8 +945,10 @@ tm2time(struct pg_tm * tm, fsec_t fsec, TimeADT *result)
/* time2tm() /* time2tm()
* Convert time data type to POSIX time structure. * Convert time data type to POSIX time structure.
* For dates within the system-supported time_t range, convert to the *
* local time zone. If out of this range, leave as GMT. - tgl 97/05/27 * For dates within the range of pg_time_t, convert to the local time zone.
* If out of this range, leave as UTC (in practice that could only happen
* if pg_time_t is just 32 bits) - thomas 97/05/27
*/ */
static int static int
time2tm(TimeADT time, struct pg_tm * tm, fsec_t *fsec) time2tm(TimeADT time, struct pg_tm * tm, fsec_t *fsec)
...@@ -2466,10 +2468,9 @@ timetz_zone(PG_FUNCTION_ARGS) ...@@ -2466,10 +2468,9 @@ timetz_zone(PG_FUNCTION_ARGS)
if (tzp) if (tzp)
{ {
/* Get the offset-from-GMT that is valid today for the selected zone */ /* Get the offset-from-GMT that is valid today for the selected zone */
pg_time_t now; pg_time_t now = (pg_time_t) time(NULL);
struct pg_tm *tm; struct pg_tm *tm;
now = time(NULL);
tm = pg_localtime(&now, tzp); tm = pg_localtime(&now, tzp);
tz = -tm->tm_gmtoff; tz = -tm->tm_gmtoff;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.184 2008/01/01 19:45:52 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.185 2008/02/17 02:09:28 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -650,9 +650,11 @@ ParseDateTime(const char *timestr, char *workbuf, size_t buflen, ...@@ -650,9 +650,11 @@ ParseDateTime(const char *timestr, char *workbuf, size_t buflen,
* "20011225T040506.789-07" * "20011225T040506.789-07"
* *
* Use the system-provided functions to get the current time zone * Use the system-provided functions to get the current time zone
* if not specified in the input string. * if not specified in the input string.
* If the date is outside the time_t system-supported time range, *
* then assume UTC time zone. - thomas 1997-05-27 * If the date is outside the range of pg_time_t (in practice that could only
* happen if pg_time_t is just 32 bits), then assume UTC time zone - thomas
* 1997-05-27
*/ */
int int
DecodeDateTime(char **field, int *ftype, int nf, DecodeDateTime(char **field, int *ftype, int nf,
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.152 2008/01/01 19:45:52 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.153 2008/02/17 02:09:28 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -86,6 +86,8 @@ static void parsetinterval(char *i_string, ...@@ -86,6 +86,8 @@ static void parsetinterval(char *i_string,
* GetCurrentAbsoluteTime() * GetCurrentAbsoluteTime()
* *
* Get the current system time (relative to Unix epoch). * Get the current system time (relative to Unix epoch).
*
* NB: this will overflow in 2038; it should be gone long before that.
*/ */
AbsoluteTime AbsoluteTime
GetCurrentAbsoluteTime(void) GetCurrentAbsoluteTime(void)
...@@ -1029,12 +1031,7 @@ tintervalrel(PG_FUNCTION_ARGS) ...@@ -1029,12 +1031,7 @@ tintervalrel(PG_FUNCTION_ARGS)
Datum Datum
timenow(PG_FUNCTION_ARGS) timenow(PG_FUNCTION_ARGS)
{ {
time_t sec; PG_RETURN_ABSOLUTETIME(GetCurrentAbsoluteTime());
if (time(&sec) < 0)
PG_RETURN_ABSOLUTETIME(INVALID_ABSTIME);
PG_RETURN_ABSOLUTETIME((AbsoluteTime) sec);
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.184 2008/01/01 19:45:52 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.185 2008/02/17 02:09:28 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1264,9 +1264,14 @@ TimestampDifferenceExceeds(TimestampTz start_time, ...@@ -1264,9 +1264,14 @@ TimestampDifferenceExceeds(TimestampTz start_time,
* *
* We do not use time_t internally in Postgres, but this is provided for use * We do not use time_t internally in Postgres, but this is provided for use
* by functions that need to interpret, say, a stat(2) result. * by functions that need to interpret, say, a stat(2) result.
*
* To avoid having the function's ABI vary depending on the width of time_t,
* we declare the argument as pg_time_t, which is cast-compatible with
* time_t but always 64 bits wide (unless the platform has no 64-bit type).
* This detail should be invisible to callers, at least at source code level.
*/ */
TimestampTz TimestampTz
time_t_to_timestamptz(time_t tm) time_t_to_timestamptz(pg_time_t tm)
{ {
TimestampTz result; TimestampTz result;
...@@ -1284,17 +1289,22 @@ time_t_to_timestamptz(time_t tm) ...@@ -1284,17 +1289,22 @@ time_t_to_timestamptz(time_t tm)
* Convert a TimestampTz to time_t. * Convert a TimestampTz to time_t.
* *
* This too is just marginally useful, but some places need it. * This too is just marginally useful, but some places need it.
*
* To avoid having the function's ABI vary depending on the width of time_t,
* we declare the result as pg_time_t, which is cast-compatible with
* time_t but always 64 bits wide (unless the platform has no 64-bit type).
* This detail should be invisible to callers, at least at source code level.
*/ */
time_t pg_time_t
timestamptz_to_time_t(TimestampTz t) timestamptz_to_time_t(TimestampTz t)
{ {
time_t result; pg_time_t result;
#ifdef HAVE_INT64_TIMESTAMP #ifdef HAVE_INT64_TIMESTAMP
result = (time_t) (t / USECS_PER_SEC + result = (pg_time_t) (t / USECS_PER_SEC +
((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY)); ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY));
#else #else
result = (time_t) (t + result = (pg_time_t) (t +
((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY)); ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY));
#endif #endif
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.104 2008/01/01 19:45:53 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.105 2008/02/17 02:09:29 tgl Exp $
* *
* NOTES * NOTES
* Globals used all over the place should be declared here and not * Globals used all over the place should be declared here and not
...@@ -33,7 +33,7 @@ volatile uint32 InterruptHoldoffCount = 0; ...@@ -33,7 +33,7 @@ volatile uint32 InterruptHoldoffCount = 0;
volatile uint32 CritSectionCount = 0; volatile uint32 CritSectionCount = 0;
int MyProcPid; int MyProcPid;
time_t MyStartTime; pg_time_t MyStartTime;
struct Port *MyProcPort; struct Port *MyProcPort;
long MyCancelKey; long MyCancelKey;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001; * copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
* licence: BSD * 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" #include "postgres.h"
...@@ -69,6 +69,7 @@ main(int argc, char *argv[]) ...@@ -69,6 +69,7 @@ main(int argc, char *argv[])
char ControlFilePath[MAXPGPATH]; char ControlFilePath[MAXPGPATH];
char *DataDir; char *DataDir;
pg_crc32 crc; pg_crc32 crc;
time_t time_tmp;
char pgctime_str[128]; char pgctime_str[128];
char ckpttime_str[128]; char ckpttime_str[128];
char sysident_str[32]; char sysident_str[32];
...@@ -134,13 +135,20 @@ main(int argc, char *argv[]) ...@@ -134,13 +135,20 @@ main(int argc, char *argv[])
"is expecting. The results below are untrustworthy.\n\n")); "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 * Use variable for format to suppress overly-anal-retentive gcc warning
* about %c * about %c
*/ */
time_tmp = (time_t) ControlFile.time;
strftime(pgctime_str, sizeof(pgctime_str), strftime_fmt, 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, strftime(ckpttime_str, sizeof(ckpttime_str), strftime_fmt,
localtime(&(ControlFile.checkPointCopy.time))); localtime(&time_tmp));
/* /*
* Format system_identifier separately to keep platform-dependent format * Format system_identifier separately to keep platform-dependent format
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * 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) ...@@ -471,10 +471,10 @@ GuessControlValues(void)
ControlFile.checkPointCopy.nextOid = FirstBootstrapObjectId; ControlFile.checkPointCopy.nextOid = FirstBootstrapObjectId;
ControlFile.checkPointCopy.nextMulti = FirstMultiXactId; ControlFile.checkPointCopy.nextMulti = FirstMultiXactId;
ControlFile.checkPointCopy.nextMultiOffset = 0; ControlFile.checkPointCopy.nextMultiOffset = 0;
ControlFile.checkPointCopy.time = time(NULL); ControlFile.checkPointCopy.time = (pg_time_t) time(NULL);
ControlFile.state = DB_SHUTDOWNED; ControlFile.state = DB_SHUTDOWNED;
ControlFile.time = time(NULL); ControlFile.time = (pg_time_t) time(NULL);
ControlFile.checkPoint = ControlFile.checkPointCopy.redo; ControlFile.checkPoint = ControlFile.checkPointCopy.redo;
ControlFile.maxAlign = MAXIMUM_ALIGNOF; ControlFile.maxAlign = MAXIMUM_ALIGNOF;
...@@ -603,10 +603,10 @@ RewriteControlFile(void) ...@@ -603,10 +603,10 @@ RewriteControlFile(void)
ControlFile.checkPointCopy.redo.xlogid = newXlogId; ControlFile.checkPointCopy.redo.xlogid = newXlogId;
ControlFile.checkPointCopy.redo.xrecoff = ControlFile.checkPointCopy.redo.xrecoff =
newXlogSeg * XLogSegSize + SizeOfXLogLongPHD; newXlogSeg * XLogSegSize + SizeOfXLogLongPHD;
ControlFile.checkPointCopy.time = time(NULL); ControlFile.checkPointCopy.time = (pg_time_t) time(NULL);
ControlFile.state = DB_SHUTDOWNED; ControlFile.state = DB_SHUTDOWNED;
ControlFile.time = time(NULL); ControlFile.time = (pg_time_t) time(NULL);
ControlFile.checkPoint = ControlFile.checkPointCopy.redo; ControlFile.checkPoint = ControlFile.checkPointCopy.redo;
ControlFile.prevCheckPoint.xlogid = 0; ControlFile.prevCheckPoint.xlogid = 0;
ControlFile.prevCheckPoint.xrecoff = 0; ControlFile.prevCheckPoint.xrecoff = 0;
......
...@@ -11,15 +11,14 @@ ...@@ -11,15 +11,14 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/access/xlog_internal.h,v 1.22 2008/01/01 19:45:56 momjian Exp $ * $PostgreSQL: pgsql/src/include/access/xlog_internal.h,v 1.23 2008/02/17 02:09:30 tgl Exp $
*/ */
#ifndef XLOG_INTERNAL_H #ifndef XLOG_INTERNAL_H
#define XLOG_INTERNAL_H #define XLOG_INTERNAL_H
#include <time.h>
#include "access/xlog.h" #include "access/xlog.h"
#include "fmgr.h" #include "fmgr.h"
#include "pgtime.h"
#include "storage/block.h" #include "storage/block.h"
#include "storage/relfilenode.h" #include "storage/relfilenode.h"
...@@ -71,7 +70,7 @@ typedef struct XLogContRecord ...@@ -71,7 +70,7 @@ typedef struct XLogContRecord
/* /*
* Each page of XLOG file has a header like this: * Each page of XLOG file has a header like this:
*/ */
#define XLOG_PAGE_MAGIC 0xD062 /* can be used as WAL version indicator */ #define XLOG_PAGE_MAGIC 0xD063 /* can be used as WAL version indicator */
typedef struct XLogPageHeaderData typedef struct XLogPageHeaderData
{ {
...@@ -242,7 +241,7 @@ extern const RmgrData RmgrTable[]; ...@@ -242,7 +241,7 @@ extern const RmgrData RmgrTable[];
/* /*
* Exported to support xlog switching from bgwriter * Exported to support xlog switching from bgwriter
*/ */
extern time_t GetLastSegSwitchTime(void); extern pg_time_t GetLastSegSwitchTime(void);
extern XLogRecPtr RequestXLogSwitch(void); extern XLogRecPtr RequestXLogSwitch(void);
/* /*
......
...@@ -8,21 +8,20 @@ ...@@ -8,21 +8,20 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/catalog/pg_control.h,v 1.39 2008/01/01 19:45:56 momjian Exp $ * $PostgreSQL: pgsql/src/include/catalog/pg_control.h,v 1.40 2008/02/17 02:09:30 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#ifndef PG_CONTROL_H #ifndef PG_CONTROL_H
#define PG_CONTROL_H #define PG_CONTROL_H
#include <time.h>
#include "access/xlogdefs.h" #include "access/xlogdefs.h"
#include "pgtime.h" /* for pg_time_t */
#include "utils/pg_crc.h" #include "utils/pg_crc.h"
/* Version identifier for this pg_control format */ /* Version identifier for this pg_control format */
#define PG_CONTROL_VERSION 833 #define PG_CONTROL_VERSION 841
/* /*
* Body of CheckPoint XLOG records. This is declared here because we keep * Body of CheckPoint XLOG records. This is declared here because we keep
...@@ -38,7 +37,7 @@ typedef struct CheckPoint ...@@ -38,7 +37,7 @@ typedef struct CheckPoint
Oid nextOid; /* next free OID */ Oid nextOid; /* next free OID */
MultiXactId nextMulti; /* next free MultiXactId */ MultiXactId nextMulti; /* next free MultiXactId */
MultiXactOffset nextMultiOffset; /* next free MultiXact offset */ MultiXactOffset nextMultiOffset; /* next free MultiXact offset */
time_t time; /* time stamp of checkpoint */ pg_time_t time; /* time stamp of checkpoint */
} CheckPoint; } CheckPoint;
/* XLOG info values for XLOG rmgr */ /* XLOG info values for XLOG rmgr */
...@@ -99,7 +98,7 @@ typedef struct ControlFileData ...@@ -99,7 +98,7 @@ typedef struct ControlFileData
* System status data * System status data
*/ */
DBState state; /* see enum above */ DBState state; /* see enum above */
time_t time; /* time stamp of last pg_control update */ pg_time_t time; /* time stamp of last pg_control update */
XLogRecPtr checkPoint; /* last check point record ptr */ XLogRecPtr checkPoint; /* last check point record ptr */
XLogRecPtr prevCheckPoint; /* previous check point record ptr */ XLogRecPtr prevCheckPoint; /* previous check point record ptr */
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.199 2008/01/03 21:23:15 tgl Exp $ * $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.200 2008/02/17 02:09:31 tgl Exp $
* *
* NOTES * NOTES
* some of the information in this file should be moved to other files. * some of the information in this file should be moved to other files.
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#ifndef MISCADMIN_H #ifndef MISCADMIN_H
#define MISCADMIN_H #define MISCADMIN_H
#include <time.h> /* for time_t */ #include "pgtime.h" /* for pg_time_t */
#define PG_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n" #define PG_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
...@@ -134,7 +134,7 @@ extern int MaxBackends; ...@@ -134,7 +134,7 @@ extern int MaxBackends;
extern int MaxConnections; extern int MaxConnections;
extern PGDLLIMPORT int MyProcPid; extern PGDLLIMPORT int MyProcPid;
extern PGDLLIMPORT time_t MyStartTime; extern PGDLLIMPORT pg_time_t MyStartTime;
extern PGDLLIMPORT struct Port *MyProcPort; extern PGDLLIMPORT struct Port *MyProcPort;
extern long MyCancelKey; extern long MyCancelKey;
......
/* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.83 2008/01/09 09:16:43 mha Exp $ */ /* $PostgreSQL: pgsql/src/include/port/win32.h,v 1.84 2008/02/17 02:09:31 tgl Exp $ */
#if defined(_MSC_VER) || defined(__BORLANDC__) #if defined(_MSC_VER) || defined(__BORLANDC__)
#define WIN32_ONLY_COMPILER #define WIN32_ONLY_COMPILER
...@@ -45,17 +45,6 @@ ...@@ -45,17 +45,6 @@
#define USES_WINSOCK #define USES_WINSOCK
/*
* Ensure that anyone building an extension is using a 32 bit time_t.
* On Mingw/Msys, that should always be the case, but MSVC++ defaults
* to 64 bits. We set that for our own build in the project files
*/
#if defined(WIN32_ONLY_COMPILER) && !defined(FRONTEND)
#ifndef _USE_32BIT_TIME_T
#error "Postgres uses 32 bit time_t - add #define _USE_32BIT_TIME_T on Windows"
#endif
#endif
/* defines for dynamic linking on Win32 platform */ /* defines for dynamic linking on Win32 platform */
#if defined(WIN32) || defined(__CYGWIN__) #if defined(WIN32) || defined(__CYGWIN__)
...@@ -198,6 +187,7 @@ struct itimerval ...@@ -198,6 +187,7 @@ struct itimerval
struct timeval it_interval; struct timeval it_interval;
struct timeval it_value; struct timeval it_value;
}; };
int setitimer(int which, const struct itimerval * value, struct itimerval * ovalue); int setitimer(int which, const struct itimerval * value, struct itimerval * ovalue);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.74 2008/01/23 21:26:13 tgl Exp $ * $PostgreSQL: pgsql/src/include/utils/timestamp.h,v 1.75 2008/02/17 02:09:31 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -310,8 +310,8 @@ extern bool TimestampDifferenceExceeds(TimestampTz start_time, ...@@ -310,8 +310,8 @@ extern bool TimestampDifferenceExceeds(TimestampTz start_time,
TimestampTz stop_time, TimestampTz stop_time,
int msec); int msec);
extern TimestampTz time_t_to_timestamptz(time_t tm); extern TimestampTz time_t_to_timestamptz(pg_time_t tm);
extern time_t timestamptz_to_time_t(TimestampTz t); extern pg_time_t timestamptz_to_time_t(TimestampTz t);
extern const char *timestamptz_to_str(TimestampTz t); extern const char *timestamptz_to_str(TimestampTz t);
......
...@@ -3,7 +3,7 @@ package Project; ...@@ -3,7 +3,7 @@ package Project;
# #
# Package that encapsulates a Visual C++ project file generation # Package that encapsulates a Visual C++ project file generation
# #
# $PostgreSQL: pgsql/src/tools/msvc/Project.pm,v 1.16 2008/02/05 14:17:23 mha Exp $ # $PostgreSQL: pgsql/src/tools/msvc/Project.pm,v 1.17 2008/02/17 02:09:32 tgl Exp $
# #
use Carp; use Carp;
use strict; use strict;
...@@ -494,7 +494,7 @@ sub WriteConfiguration ...@@ -494,7 +494,7 @@ sub WriteConfiguration
ConfigurationType="$cfgtype" UseOfMFC="0" ATLMinimizesCRunTimeLibraryUsage="FALSE" CharacterSet="2" WholeProgramOptimization="$p->{wholeopt}"> ConfigurationType="$cfgtype" UseOfMFC="0" ATLMinimizesCRunTimeLibraryUsage="FALSE" CharacterSet="2" WholeProgramOptimization="$p->{wholeopt}">
<Tool Name="VCCLCompilerTool" Optimization="$p->{opt}" <Tool Name="VCCLCompilerTool" Optimization="$p->{opt}"
AdditionalIncludeDirectories="$self->{prefixincludes}src/include;src/include/port/win32;src/include/port/win32_msvc;$self->{includes}" AdditionalIncludeDirectories="$self->{prefixincludes}src/include;src/include/port/win32;src/include/port/win32_msvc;$self->{includes}"
PreprocessorDefinitions="WIN32;_WINDOWS;__WINDOWS__;__WIN32__;EXEC_BACKEND;WIN32_STACK_RLIMIT=4194304;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;_USE_32BIT_TIME_T$self->{defines}$p->{defs}" PreprocessorDefinitions="WIN32;_WINDOWS;__WINDOWS__;__WIN32__;EXEC_BACKEND;WIN32_STACK_RLIMIT=4194304;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE$self->{defines}$p->{defs}"
StringPooling="$p->{strpool}" StringPooling="$p->{strpool}"
RuntimeLibrary="$p->{runtime}" DisableSpecificWarnings="$self->{disablewarnings}" RuntimeLibrary="$p->{runtime}" DisableSpecificWarnings="$self->{disablewarnings}"
EOF EOF
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment