aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNeil Conway <neilc@samurai.com>2005-10-05 23:46:06 +0000
committerNeil Conway <neilc@samurai.com>2005-10-05 23:46:06 +0000
commitb5aad11a1b253bbd45405dc926f1ebef90f8f28c (patch)
tree146aa7a1e0dc4be0f37632bf71f015ae9aaa34a7 /src
parent8c6f345005fd93155886ffcba0671c4d3df5bf0d (diff)
downloadpostgresql-b5aad11a1b253bbd45405dc926f1ebef90f8f28c.tar.gz
postgresql-b5aad11a1b253bbd45405dc926f1ebef90f8f28c.zip
Code cleanup for log_disconnections(). Patch from Qingqing Zhou,
fixes by Neil Conway.
Diffstat (limited to 'src')
-rw-r--r--src/backend/tcop/postgres.c56
1 files changed, 14 insertions, 42 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 4e3b5387d89..44d799c9864 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.463 2005/09/26 15:51:12 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.464 2005/10/05 23:46:06 neilc Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@@ -3526,29 +3526,13 @@ ShowUsage(const char *title)
static void
log_disconnections(int code, Datum arg)
{
- Port *port = MyProcPort;
- struct timeval end;
- int hours,
- minutes,
- seconds;
-
- char session_time[20];
- char uname[6 + NAMEDATALEN];
- char dbname[10 + NAMEDATALEN];
- char remote_host[7 + NI_MAXHOST];
- char remote_port[7 + NI_MAXSERV];
-
- snprintf(uname, sizeof(uname), " user=%s", port->user_name);
- snprintf(dbname, sizeof(dbname), " database=%s", port->database_name);
- snprintf(remote_host, sizeof(remote_host), " host=%s",
- port->remote_host);
- if (port->remote_port[0])
- snprintf(remote_port, sizeof(remote_port), " port=%s", port->remote_port);
- else
- remote_port[0] = '\0';
-
- gettimeofday(&end, NULL);
+ Port *port = MyProcPort;
+ struct timeval end;
+ int hours,
+ minutes,
+ seconds;
+ gettimeofday(&end, NULL);
if (end.tv_usec < port->session_start.tv_usec)
{
end.tv_sec--;
@@ -3557,28 +3541,16 @@ log_disconnections(int code, Datum arg)
end.tv_sec -= port->session_start.tv_sec;
end.tv_usec -= port->session_start.tv_usec;
+ /* for stricter accuracy here we could round - this is close enough */
hours = end.tv_sec / SECS_PER_HOUR;
end.tv_sec %= SECS_PER_HOUR;
minutes = end.tv_sec / SECS_PER_MINUTE;
seconds = end.tv_sec % SECS_PER_MINUTE;
- /* if time has gone backwards for some reason say so, or print time */
-
- if (end.tv_sec < 0)
- snprintf(session_time, sizeof(session_time), "negative!");
- else
-
- /*
- * for stricter accuracy here we could round - this is close
- * enough
- */
- snprintf(session_time, sizeof(session_time),
- "%d:%02d:%02d.%02d",
- hours, minutes, seconds, (int) (end.tv_usec / 10000));
-
- ereport(
- LOG,
- (errmsg("disconnection: session time: %s%s%s%s%s",
- session_time, uname, dbname, remote_host, remote_port)));
-
+ ereport(LOG,
+ (errmsg("disconnection: session time: %d:%02d:%02d.%02d "
+ "user=%s database=%s host=%s%s%s",
+ hours, minutes, seconds, (int) (end.tv_usec / 10000),
+ port->user_name, port->database_name, port->remote_host,
+ port->remote_port[0] ? " port=" : "", port->remote_port)));
}