Skip to content

Commit bd19e8f

Browse files
committed
Fix some places that were unportably assuming struct timeval's tv_sec
field is signed. Clean up casting.
1 parent c3086c8 commit bd19e8f

File tree

2 files changed

+37
-33
lines changed

2 files changed

+37
-33
lines changed

src/backend/postmaster/pgstat.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* Copyright (c) 2001, PostgreSQL Global Development Group
1818
*
19-
* $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.30 2002/10/21 19:59:14 tgl Exp $
19+
* $Header: /cvsroot/pgsql/src/backend/postmaster/pgstat.c,v 1.31 2002/10/24 23:19:13 tgl Exp $
2020
* ----------
2121
*/
2222
#include "postgres.h"
@@ -1247,19 +1247,27 @@ pgstat_main(void)
12471247
*/
12481248
if (need_statwrite)
12491249
{
1250-
gettimeofday(&timeout, NULL);
1251-
timeout.tv_usec = next_statwrite.tv_usec - timeout.tv_usec;
1252-
timeout.tv_sec = next_statwrite.tv_sec - timeout.tv_sec;
1253-
if (timeout.tv_usec < 0)
1254-
{
1255-
timeout.tv_sec -= 1;
1256-
timeout.tv_usec += 1000000;
1257-
}
1258-
if (timeout.tv_sec < 0)
1250+
struct timeval now;
1251+
1252+
gettimeofday(&now, NULL);
1253+
/* avoid assuming that tv_sec is signed */
1254+
if (now.tv_sec > next_statwrite.tv_sec ||
1255+
(now.tv_sec == next_statwrite.tv_sec &&
1256+
now.tv_usec >= next_statwrite.tv_usec))
12591257
{
12601258
timeout.tv_sec = 0;
12611259
timeout.tv_usec = 0;
12621260
}
1261+
else
1262+
{
1263+
timeout.tv_sec = next_statwrite.tv_sec - now.tv_sec;
1264+
timeout.tv_usec = next_statwrite.tv_usec - now.tv_usec;
1265+
if (timeout.tv_usec < 0)
1266+
{
1267+
timeout.tv_sec--;
1268+
timeout.tv_usec += 1000000;
1269+
}
1270+
}
12631271
}
12641272

12651273
/*

src/backend/tcop/postgres.c

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.305 2002/10/19 20:15:09 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.306 2002/10/24 23:19:13 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -559,7 +559,6 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
559559
MemoryContext oldcontext;
560560
List *parsetree_list,
561561
*parsetree_item;
562-
struct timezone tz;
563562
struct timeval start_t,
564563
stop_t;
565564
bool save_Log_duration = Log_duration;
@@ -571,7 +570,7 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
571570
* report incorrect time because gettimeofday() wasn't called.
572571
*/
573572
if (save_Log_duration)
574-
gettimeofday(&start_t, &tz);
573+
gettimeofday(&start_t, NULL);
575574

576575
/*
577576
* Start up a transaction command. All queries generated by the
@@ -943,15 +942,15 @@ pg_exec_query_string(StringInfo query_string, /* string to execute */
943942

944943
if (save_Log_duration)
945944
{
946-
gettimeofday(&stop_t, &tz);
945+
gettimeofday(&stop_t, NULL);
947946
if (stop_t.tv_usec < start_t.tv_usec)
948947
{
949948
stop_t.tv_sec--;
950949
stop_t.tv_usec += 1000000;
951950
}
952951
elog(LOG, "duration: %ld.%06ld sec",
953-
(long int) stop_t.tv_sec - start_t.tv_sec,
954-
(long int) stop_t.tv_usec - start_t.tv_usec);
952+
(long) (stop_t.tv_sec - start_t.tv_sec),
953+
(long) (stop_t.tv_usec - start_t.tv_usec));
955954
}
956955

957956
debug_query_string = NULL;
@@ -1783,7 +1782,7 @@ PostgresMain(int argc, char *argv[], const char *username)
17831782
if (!IsUnderPostmaster)
17841783
{
17851784
puts("\nPOSTGRES backend interactive interface ");
1786-
puts("$Revision: 1.305 $ $Date: 2002/10/19 20:15:09 $\n");
1785+
puts("$Revision: 1.306 $ $Date: 2002/10/24 23:19:13 $\n");
17871786
}
17881787

17891788
/*
@@ -2081,12 +2080,10 @@ struct timeval Save_t;
20812080
void
20822081
ResetUsage(void)
20832082
{
2084-
struct timezone tz;
2085-
20862083
getrusage(RUSAGE_SELF, &Save_r);
2087-
gettimeofday(&Save_t, &tz);
2084+
gettimeofday(&Save_t, NULL);
20882085
ResetBufferUsage();
2089-
/* ResetTupleCount(); */
2086+
/* ResetTupleCount(); */
20902087
}
20912088

20922089
void
@@ -2096,12 +2093,11 @@ ShowUsage(const char *title)
20962093
struct timeval user,
20972094
sys;
20982095
struct timeval elapse_t;
2099-
struct timezone tz;
21002096
struct rusage r;
21012097
char *bufusage;
21022098

21032099
getrusage(RUSAGE_SELF, &r);
2104-
gettimeofday(&elapse_t, &tz);
2100+
gettimeofday(&elapse_t, NULL);
21052101
memcpy((char *) &user, (char *) &r.ru_utime, sizeof(user));
21062102
memcpy((char *) &sys, (char *) &r.ru_stime, sizeof(sys));
21072103
if (elapse_t.tv_usec < Save_t.tv_usec)
@@ -2133,18 +2129,18 @@ ShowUsage(const char *title)
21332129
appendStringInfo(&str, "! system usage stats:\n");
21342130
appendStringInfo(&str,
21352131
"!\t%ld.%06ld elapsed %ld.%06ld user %ld.%06ld system sec\n",
2136-
(long int) elapse_t.tv_sec - Save_t.tv_sec,
2137-
(long int) elapse_t.tv_usec - Save_t.tv_usec,
2138-
(long int) r.ru_utime.tv_sec - Save_r.ru_utime.tv_sec,
2139-
(long int) r.ru_utime.tv_usec - Save_r.ru_utime.tv_usec,
2140-
(long int) r.ru_stime.tv_sec - Save_r.ru_stime.tv_sec,
2141-
(long int) r.ru_stime.tv_usec - Save_r.ru_stime.tv_usec);
2132+
(long) (elapse_t.tv_sec - Save_t.tv_sec),
2133+
(long) (elapse_t.tv_usec - Save_t.tv_usec),
2134+
(long) (r.ru_utime.tv_sec - Save_r.ru_utime.tv_sec),
2135+
(long) (r.ru_utime.tv_usec - Save_r.ru_utime.tv_usec),
2136+
(long) (r.ru_stime.tv_sec - Save_r.ru_stime.tv_sec),
2137+
(long) (r.ru_stime.tv_usec - Save_r.ru_stime.tv_usec));
21422138
appendStringInfo(&str,
21432139
"!\t[%ld.%06ld user %ld.%06ld sys total]\n",
2144-
(long int) user.tv_sec,
2145-
(long int) user.tv_usec,
2146-
(long int) sys.tv_sec,
2147-
(long int) sys.tv_usec);
2140+
(long) user.tv_sec,
2141+
(long) user.tv_usec,
2142+
(long) sys.tv_sec,
2143+
(long) sys.tv_usec);
21482144
/* BeOS has rusage but only has some fields, and not these... */
21492145
#if defined(HAVE_GETRUSAGE)
21502146
appendStringInfo(&str,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy