diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-11-05 03:05:05 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-11-05 03:05:05 +0000 |
commit | 39edcf59a2534d0f59b29ebe0c6b94a3600d8c4b (patch) | |
tree | c9a3a61c82432bb902e5c185c28d2e5510dd50bd /src/backend/utils/error/elog.c | |
parent | 56f68ed9070794344a37f6c9414d421c4a04b898 (diff) | |
download | postgresql-39edcf59a2534d0f59b29ebe0c6b94a3600d8c4b.tar.gz postgresql-39edcf59a2534d0f59b29ebe0c6b94a3600d8c4b.zip |
Repair an error introduced by log_line_prefix patch: it is not acceptable
to assume that the string pointer passed to set_ps_display is good forever.
There's no need to anyway since ps_status.c itself saves the string, and
we already had an API (get_ps_display) to return it.
I believe this explains Jim Nasby's report of intermittent crashes in
elog.c when %i format code is in use in log_line_prefix.
While at it, repair a previously unnoticed problem: on some platforms such as
Darwin, the string returned by get_ps_display was blank-padded to the maximum
length, meaning that lock.c's attempt to append " waiting" to it never worked.
Diffstat (limited to 'src/backend/utils/error/elog.c')
-rw-r--r-- | src/backend/utils/error/elog.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index c919f7c2c65..358bd982b34 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -42,7 +42,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.155.4.3 2005/10/14 16:41:13 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.155.4.4 2005/11/05 03:05:05 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -67,6 +67,7 @@ #include "tcop/tcopprot.h" #include "utils/memutils.h" #include "utils/guc.h" +#include "utils/ps_status.h" /* Global variables */ @@ -1461,13 +1462,20 @@ log_line_prefix(StringInfo buf) break; case 'i': if (MyProcPort) - appendStringInfo(buf, "%s", MyProcPort->commandTag); + { + const char *psdisp; + int displen; + + psdisp = get_ps_display(&displen); + appendStringInfo(buf, "%.*s", displen, psdisp); + } break; case 'r': - if (MyProcPort) + if (MyProcPort && MyProcPort->remote_host) { appendStringInfo(buf, "%s", MyProcPort->remote_host); - if (strlen(MyProcPort->remote_port) > 0) + if (MyProcPort->remote_port && + MyProcPort->remote_port[0] != '\0') appendStringInfo(buf, "(%s)", MyProcPort->remote_port); } |