aboutsummaryrefslogtreecommitdiff
path: root/src/backend/postmaster/pgstat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/postmaster/pgstat.c')
-rw-r--r--src/backend/postmaster/pgstat.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index d7da6177d05..17c11682cf9 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -16,7 +16,7 @@
*
* Copyright (c) 2001, PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.30 2002/10/21 19:59:14 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.31 2002/10/24 23:19:13 tgl Exp $
* ----------
*/
#include "postgres.h"
@@ -1247,19 +1247,27 @@ pgstat_main(void)
*/
if (need_statwrite)
{
- gettimeofday(&timeout, NULL);
- timeout.tv_usec = next_statwrite.tv_usec - timeout.tv_usec;
- timeout.tv_sec = next_statwrite.tv_sec - timeout.tv_sec;
- if (timeout.tv_usec < 0)
- {
- timeout.tv_sec -= 1;
- timeout.tv_usec += 1000000;
- }
- if (timeout.tv_sec < 0)
+ struct timeval now;
+
+ gettimeofday(&now, NULL);
+ /* avoid assuming that tv_sec is signed */
+ if (now.tv_sec > next_statwrite.tv_sec ||
+ (now.tv_sec == next_statwrite.tv_sec &&
+ now.tv_usec >= next_statwrite.tv_usec))
{
timeout.tv_sec = 0;
timeout.tv_usec = 0;
}
+ else
+ {
+ timeout.tv_sec = next_statwrite.tv_sec - now.tv_sec;
+ timeout.tv_usec = next_statwrite.tv_usec - now.tv_usec;
+ if (timeout.tv_usec < 0)
+ {
+ timeout.tv_sec--;
+ timeout.tv_usec += 1000000;
+ }
+ }
}
/*