Fix some places that were unportably assuming struct timeval's tv_sec

field is signed.  Clean up casting.
This commit is contained in:
Tom Lane 2002-10-24 23:19:13 +00:00
parent c3086c8f53
commit bd19e8f604
2 changed files with 37 additions and 33 deletions

View File

@ -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;
}
}
}
/*

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.305 2002/10/19 20:15:09 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.306 2002/10/24 23:19:13 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@ -559,7 +559,6 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
MemoryContext oldcontext;
List *parsetree_list,
*parsetree_item;
struct timezone tz;
struct timeval start_t,
stop_t;
bool save_Log_duration = Log_duration;
@ -571,7 +570,7 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
* report incorrect time because gettimeofday() wasn't called.
*/
if (save_Log_duration)
gettimeofday(&start_t, &tz);
gettimeofday(&start_t, NULL);
/*
* Start up a transaction command. All queries generated by the
@ -943,15 +942,15 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
if (save_Log_duration)
{
gettimeofday(&stop_t, &tz);
gettimeofday(&stop_t, NULL);
if (stop_t.tv_usec < start_t.tv_usec)
{
stop_t.tv_sec--;
stop_t.tv_usec += 1000000;
}
elog(LOG, "duration: %ld.%06ld sec",
(long int) stop_t.tv_sec - start_t.tv_sec,
(long int) stop_t.tv_usec - start_t.tv_usec);
(long) (stop_t.tv_sec - start_t.tv_sec),
(long) (stop_t.tv_usec - start_t.tv_usec));
}
debug_query_string = NULL;
@ -1783,7 +1782,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.305 $ $Date: 2002/10/19 20:15:09 $\n");
puts("$Revision: 1.306 $ $Date: 2002/10/24 23:19:13 $\n");
}
/*
@ -2081,12 +2080,10 @@ struct timeval Save_t;
void
ResetUsage(void)
{
struct timezone tz;
getrusage(RUSAGE_SELF, &Save_r);
gettimeofday(&Save_t, &tz);
gettimeofday(&Save_t, NULL);
ResetBufferUsage();
/* ResetTupleCount(); */
/* ResetTupleCount(); */
}
void
@ -2096,12 +2093,11 @@ ShowUsage(const char *title)
struct timeval user,
sys;
struct timeval elapse_t;
struct timezone tz;
struct rusage r;
char *bufusage;
getrusage(RUSAGE_SELF, &r);
gettimeofday(&elapse_t, &tz);
gettimeofday(&elapse_t, NULL);
memcpy((char *) &user, (char *) &r.ru_utime, sizeof(user));
memcpy((char *) &sys, (char *) &r.ru_stime, sizeof(sys));
if (elapse_t.tv_usec < Save_t.tv_usec)
@ -2133,18 +2129,18 @@ ShowUsage(const char *title)
appendStringInfo(&str, "! system usage stats:\n");
appendStringInfo(&str,
"!\t%ld.%06ld elapsed %ld.%06ld user %ld.%06ld system sec\n",
(long int) elapse_t.tv_sec - Save_t.tv_sec,
(long int) elapse_t.tv_usec - Save_t.tv_usec,
(long int) r.ru_utime.tv_sec - Save_r.ru_utime.tv_sec,
(long int) r.ru_utime.tv_usec - Save_r.ru_utime.tv_usec,
(long int) r.ru_stime.tv_sec - Save_r.ru_stime.tv_sec,
(long int) r.ru_stime.tv_usec - Save_r.ru_stime.tv_usec);
(long) (elapse_t.tv_sec - Save_t.tv_sec),
(long) (elapse_t.tv_usec - Save_t.tv_usec),
(long) (r.ru_utime.tv_sec - Save_r.ru_utime.tv_sec),
(long) (r.ru_utime.tv_usec - Save_r.ru_utime.tv_usec),
(long) (r.ru_stime.tv_sec - Save_r.ru_stime.tv_sec),
(long) (r.ru_stime.tv_usec - Save_r.ru_stime.tv_usec));
appendStringInfo(&str,
"!\t[%ld.%06ld user %ld.%06ld sys total]\n",
(long int) user.tv_sec,
(long int) user.tv_usec,
(long int) sys.tv_sec,
(long int) sys.tv_usec);
(long) user.tv_sec,
(long) user.tv_usec,
(long) sys.tv_sec,
(long) sys.tv_usec);
/* BeOS has rusage but only has some fields, and not these... */
#if defined(HAVE_GETRUSAGE)
appendStringInfo(&str,