aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/misc/ps_status.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-11-05 03:05:05 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-11-05 03:05:05 +0000
commit39edcf59a2534d0f59b29ebe0c6b94a3600d8c4b (patch)
treec9a3a61c82432bb902e5c185c28d2e5510dd50bd /src/backend/utils/misc/ps_status.c
parent56f68ed9070794344a37f6c9414d421c4a04b898 (diff)
downloadpostgresql-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/misc/ps_status.c')
-rw-r--r--src/backend/utils/misc/ps_status.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c
index 4cecf446ae2..8d34d235815 100644
--- a/src/backend/utils/misc/ps_status.c
+++ b/src/backend/utils/misc/ps_status.c
@@ -5,7 +5,7 @@
* to contain some useful information. Mechanism differs wildly across
* platforms.
*
- * $PostgreSQL: pgsql/src/backend/utils/misc/ps_status.c,v 1.23 2005/01/01 05:43:08 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/misc/ps_status.c,v 1.23.4.1 2005/11/05 03:05:05 tgl Exp $
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
* various details abducted from various places
@@ -308,10 +308,6 @@ init_ps_display(const char *username, const char *dbname,
void
set_ps_display(const char *activity)
{
- /* save tag for possible use by elog.c */
- if (MyProcPort)
- MyProcPort->commandTag = activity;
-
#ifndef PS_USE_NONE
/* no ps display for stand-alone backend */
if (!IsUnderPostmaster)
@@ -367,15 +363,31 @@ set_ps_display(const char *activity)
/*
* Returns what's currently in the ps display, in case someone needs
- * it. Note that only the activity part is returned.
+ * it. Note that only the activity part is returned. On some platforms
+ * the string will not be null-terminated, so return the effective
+ * length into *displen.
*/
const char *
-get_ps_display(void)
+get_ps_display(int *displen)
{
#ifdef PS_USE_CLOBBER_ARGV
+ size_t offset;
+
/* If ps_buffer is a pointer, it might still be null */
if (!ps_buffer)
+ {
+ *displen = 0;
return "";
+ }
+
+ /* Remove any trailing spaces to offset the effect of PS_PADDING */
+ offset = ps_buffer_size;
+ while (offset > ps_buffer_fixed_size && ps_buffer[offset-1] == PS_PADDING)
+ offset--;
+
+ *displen = offset - ps_buffer_fixed_size;
+#else
+ *displen = strlen(ps_buffer + ps_buffer_fixed_size);
#endif
return ps_buffer + ps_buffer_fixed_size;