Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b5aad11

Browse files
author
Neil Conway
committed
Code cleanup for log_disconnections(). Patch from Qingqing Zhou,
fixes by Neil Conway.
1 parent 8c6f345 commit b5aad11

File tree

1 file changed

+14
-42
lines changed

1 file changed

+14
-42
lines changed

src/backend/tcop/postgres.c

+14-42
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.463 2005/09/26 15:51:12 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.464 2005/10/05 23:46:06 neilc Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -3526,29 +3526,13 @@ ShowUsage(const char *title)
35263526
static void
35273527
log_disconnections(int code, Datum arg)
35283528
{
3529-
Port *port = MyProcPort;
3530-
struct timeval end;
3531-
int hours,
3532-
minutes,
3533-
seconds;
3534-
3535-
char session_time[20];
3536-
char uname[6 + NAMEDATALEN];
3537-
char dbname[10 + NAMEDATALEN];
3538-
char remote_host[7 + NI_MAXHOST];
3539-
char remote_port[7 + NI_MAXSERV];
3540-
3541-
snprintf(uname, sizeof(uname), " user=%s", port->user_name);
3542-
snprintf(dbname, sizeof(dbname), " database=%s", port->database_name);
3543-
snprintf(remote_host, sizeof(remote_host), " host=%s",
3544-
port->remote_host);
3545-
if (port->remote_port[0])
3546-
snprintf(remote_port, sizeof(remote_port), " port=%s", port->remote_port);
3547-
else
3548-
remote_port[0] = '\0';
3549-
3550-
gettimeofday(&end, NULL);
3529+
Port *port = MyProcPort;
3530+
struct timeval end;
3531+
int hours,
3532+
minutes,
3533+
seconds;
35513534

3535+
gettimeofday(&end, NULL);
35523536
if (end.tv_usec < port->session_start.tv_usec)
35533537
{
35543538
end.tv_sec--;
@@ -3557,28 +3541,16 @@ log_disconnections(int code, Datum arg)
35573541
end.tv_sec -= port->session_start.tv_sec;
35583542
end.tv_usec -= port->session_start.tv_usec;
35593543

3544+
/* for stricter accuracy here we could round - this is close enough */
35603545
hours = end.tv_sec / SECS_PER_HOUR;
35613546
end.tv_sec %= SECS_PER_HOUR;
35623547
minutes = end.tv_sec / SECS_PER_MINUTE;
35633548
seconds = end.tv_sec % SECS_PER_MINUTE;
35643549

3565-
/* if time has gone backwards for some reason say so, or print time */
3566-
3567-
if (end.tv_sec < 0)
3568-
snprintf(session_time, sizeof(session_time), "negative!");
3569-
else
3570-
3571-
/*
3572-
* for stricter accuracy here we could round - this is close
3573-
* enough
3574-
*/
3575-
snprintf(session_time, sizeof(session_time),
3576-
"%d:%02d:%02d.%02d",
3577-
hours, minutes, seconds, (int) (end.tv_usec / 10000));
3578-
3579-
ereport(
3580-
LOG,
3581-
(errmsg("disconnection: session time: %s%s%s%s%s",
3582-
session_time, uname, dbname, remote_host, remote_port)));
3583-
3550+
ereport(LOG,
3551+
(errmsg("disconnection: session time: %d:%02d:%02d.%02d "
3552+
"user=%s database=%s host=%s%s%s",
3553+
hours, minutes, seconds, (int) (end.tv_usec / 10000),
3554+
port->user_name, port->database_name, port->remote_host,
3555+
port->remote_port[0] ? " port=" : "", port->remote_port)));
35843556
}

0 commit comments

Comments
 (0)