diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/access/transam/xlog.c | 26 | ||||
-rw-r--r-- | src/backend/postmaster/bgwriter.c | 22 | ||||
-rw-r--r-- | src/backend/postmaster/syslogger.c | 4 | ||||
-rw-r--r-- | src/backend/utils/adt/date.c | 11 | ||||
-rw-r--r-- | src/backend/utils/adt/datetime.c | 10 | ||||
-rw-r--r-- | src/backend/utils/adt/nabstime.c | 11 | ||||
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 22 | ||||
-rw-r--r-- | src/backend/utils/init/globals.c | 4 |
8 files changed, 60 insertions, 50 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index d2075018d96..f61af0ab4d5 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * 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 { XLogwrtResult LogwrtResult; /* current value of LogwrtResult */ 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; /* @@ -1553,7 +1553,7 @@ XLogWrite(XLogwrtRqst WriteRqst, bool flexible, bool xlog_switch) if (XLogArchivingActive()) 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 @@ -4217,7 +4217,7 @@ BootStrapXLOG(void) checkPoint.nextOid = FirstBootstrapObjectId; checkPoint.nextMulti = FirstMultiXactId; checkPoint.nextMultiOffset = 0; - checkPoint.time = time(NULL); + checkPoint.time = (pg_time_t) time(NULL); ShmemVariableCache->nextXid = checkPoint.nextXid; ShmemVariableCache->nextOid = checkPoint.nextOid; @@ -4972,7 +4972,7 @@ StartupXLOG(void) ControlFile->checkPointCopy = checkPoint; if (minRecoveryLoc.xlogid != 0 || minRecoveryLoc.xrecoff != 0) ControlFile->minRecoveryPoint = minRecoveryLoc; - ControlFile->time = time(NULL); + ControlFile->time = (pg_time_t) time(NULL); UpdateControlFile(); /* @@ -5277,7 +5277,7 @@ StartupXLOG(void) InRecovery = false; ControlFile->state = DB_IN_PRODUCTION; - ControlFile->time = time(NULL); + ControlFile->time = (pg_time_t) time(NULL); UpdateControlFile(); /* start the archive_timeout timer running */ @@ -5496,10 +5496,10 @@ GetInsertRecPtr(void) /* * Get the time of the last xlog segment switch */ -time_t +pg_time_t GetLastSegSwitchTime(void) { - time_t result; + pg_time_t result; /* Need WALWriteLock, but shared lock is sufficient */ LWLockAcquire(WALWriteLock, LW_SHARED); @@ -5676,7 +5676,7 @@ CreateCheckPoint(int flags) if (shutdown) { ControlFile->state = DB_SHUTDOWNING; - ControlFile->time = time(NULL); + ControlFile->time = (pg_time_t) time(NULL); UpdateControlFile(); } @@ -5690,7 +5690,7 @@ CreateCheckPoint(int flags) /* Begin filling in the checkpoint WAL record */ MemSet(&checkPoint, 0, sizeof(checkPoint)); checkPoint.ThisTimeLineID = ThisTimeLineID; - checkPoint.time = time(NULL); + checkPoint.time = (pg_time_t) time(NULL); /* * We must hold WALInsertLock while examining insert state to determine @@ -5891,7 +5891,7 @@ CreateCheckPoint(int flags) ControlFile->prevCheckPoint = ControlFile->checkPoint; ControlFile->checkPoint = ProcLastRecPtr; ControlFile->checkPointCopy = checkPoint; - ControlFile->time = time(NULL); + ControlFile->time = (pg_time_t) time(NULL); UpdateControlFile(); LWLockRelease(ControlFileLock); @@ -5992,7 +5992,7 @@ RecoveryRestartPoint(const CheckPoint *checkPoint) * Checking true elapsed time keeps us from doing restartpoints too often * 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) return; @@ -6028,7 +6028,7 @@ RecoveryRestartPoint(const CheckPoint *checkPoint) ControlFile->prevCheckPoint = ControlFile->checkPoint; ControlFile->checkPoint = ReadRecPtr; ControlFile->checkPointCopy = *checkPoint; - ControlFile->time = time(NULL); + ControlFile->time = (pg_time_t) time(NULL); UpdateControlFile(); ereport((recoveryLogRestartpoints ? LOG : DEBUG2), diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c index 10586b8fad2..5dce3fa6989 100644 --- a/src/backend/postmaster/bgwriter.c +++ b/src/backend/postmaster/bgwriter.c @@ -37,7 +37,7 @@ * * * 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; static bool ckpt_active = false; /* 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 double ckpt_cached_elapsed; -static time_t last_checkpoint_time; -static time_t last_xlog_switch_time; +static pg_time_t last_checkpoint_time; +static pg_time_t last_xlog_switch_time; /* Prototypes for private functions */ @@ -250,7 +250,7 @@ BackgroundWriterMain(void) /* * 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 @@ -361,7 +361,7 @@ BackgroundWriterMain(void) { bool do_checkpoint = false; int flags = 0; - time_t now; + pg_time_t now; int elapsed_secs; /* @@ -407,7 +407,7 @@ BackgroundWriterMain(void) * occurs without an external request, but we set the CAUSE_TIME flag * bit even if there is also an external request. */ - now = time(NULL); + now = (pg_time_t) time(NULL); elapsed_secs = now - last_checkpoint_time; if (elapsed_secs >= CheckPointTimeout) { @@ -504,13 +504,13 @@ BackgroundWriterMain(void) static void CheckArchiveTimeout(void) { - time_t now; - time_t last_time; + pg_time_t now; + pg_time_t last_time; if (XLogArchiveTimeout <= 0) return; - now = time(NULL); + now = (pg_time_t) time(NULL); /* First we do a quick check using possibly-stale local state. */ if ((int) (now - last_xlog_switch_time) < XLogArchiveTimeout) @@ -730,7 +730,7 @@ IsCheckpointOnSchedule(double progress) * Check progress against time elapsed and checkpoint_timeout. */ 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; if (progress < elapsed_time) diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c index aa5d34ef5b2..91bf56225a1 100644 --- a/src/backend/postmaster/syslogger.c +++ b/src/backend/postmaster/syslogger.c @@ -18,7 +18,7 @@ * * * 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[]) if (!rotation_requested && Log_RotationAge > 0) { /* 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) rotation_requested = time_based_rotation = true; diff --git a/src/backend/utils/adt/date.c b/src/backend/utils/adt/date.c index bec5e373964..70f60c94622 100644 --- a/src/backend/utils/adt/date.c +++ b/src/backend/utils/adt/date.c @@ -8,7 +8,7 @@ * * * 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) /* time2tm() * 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 time2tm(TimeADT time, struct pg_tm * tm, fsec_t *fsec) @@ -2466,10 +2468,9 @@ timetz_zone(PG_FUNCTION_ARGS) if (tzp) { /* 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; - now = time(NULL); tm = pg_localtime(&now, tzp); tz = -tm->tm_gmtoff; } diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c index ed411cf21af..0bfdd0ec2d6 100644 --- a/src/backend/utils/adt/datetime.c +++ b/src/backend/utils/adt/datetime.c @@ -8,7 +8,7 @@ * * * 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, * "20011225T040506.789-07" * * Use the system-provided functions to get the current time zone - * 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 not specified in the input string. + * + * 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 DecodeDateTime(char **field, int *ftype, int nf, diff --git a/src/backend/utils/adt/nabstime.c b/src/backend/utils/adt/nabstime.c index a2e9fc26433..2265b7d903e 100644 --- a/src/backend/utils/adt/nabstime.c +++ b/src/backend/utils/adt/nabstime.c @@ -10,7 +10,7 @@ * * * 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, * GetCurrentAbsoluteTime() * * Get the current system time (relative to Unix epoch). + * + * NB: this will overflow in 2038; it should be gone long before that. */ AbsoluteTime GetCurrentAbsoluteTime(void) @@ -1029,12 +1031,7 @@ tintervalrel(PG_FUNCTION_ARGS) Datum timenow(PG_FUNCTION_ARGS) { - time_t sec; - - if (time(&sec) < 0) - PG_RETURN_ABSOLUTETIME(INVALID_ABSTIME); - - PG_RETURN_ABSOLUTETIME((AbsoluteTime) sec); + PG_RETURN_ABSOLUTETIME(GetCurrentAbsoluteTime()); } /* diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 1277562b794..f450922f26e 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -8,7 +8,7 @@ * * * 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, * * 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. + * + * 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 -time_t_to_timestamptz(time_t tm) +time_t_to_timestamptz(pg_time_t tm) { TimestampTz result; @@ -1284,17 +1289,22 @@ time_t_to_timestamptz(time_t tm) * Convert a TimestampTz to time_t. * * 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) { - time_t result; + pg_time_t result; #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)); #else - result = (time_t) (t + + result = (pg_time_t) (t + ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY)); #endif diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c index 3cc443b6297..d0ce929d7d0 100644 --- a/src/backend/utils/init/globals.c +++ b/src/backend/utils/init/globals.c @@ -8,7 +8,7 @@ * * * 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 * Globals used all over the place should be declared here and not @@ -33,7 +33,7 @@ volatile uint32 InterruptHoldoffCount = 0; volatile uint32 CritSectionCount = 0; int MyProcPid; -time_t MyStartTime; +pg_time_t MyStartTime; struct Port *MyProcPort; long MyCancelKey; |