summaryrefslogtreecommitdiff
path: root/src/backend/storage
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-11-05 03:04:53 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-11-05 03:04:53 +0000
commit48052de722a502408275fa3b7aee7de430265fc0 (patch)
tree88e3bb1280caae1ee6f4e83724a8f3aa65d25353 /src/backend/storage
parent95af2633c3e3d64a3cc508409a74ef29de25c852 (diff)
downloadpostgresql-48052de722a502408275fa3b7aee7de430265fc0.tar.gz
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/storage')
-rw-r--r--src/backend/storage/lmgr/lock.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c
index 245b8eeee2..467bde6c1c 100644
--- a/src/backend/storage/lmgr/lock.c
+++ b/src/backend/storage/lmgr/lock.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.158 2005/10/15 02:49:26 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.159 2005/11/05 03:04:52 tgl Exp $
*
* NOTES
* Outside modules can create a lock table and acquire/release
@@ -1049,21 +1049,21 @@ WaitOnLock(LOCKMETHODID lockmethodid, LOCALLOCK *locallock,
ResourceOwner owner)
{
LockMethod lockMethodTable = LockMethods[lockmethodid];
- char *new_status,
- *old_status;
- size_t len;
+ const char *old_status;
+ char *new_status;
+ int len;
Assert(lockmethodid < NumLockMethods);
LOCK_PRINT("WaitOnLock: sleeping on lock",
locallock->lock, locallock->tag.mode);
- old_status = pstrdup(get_ps_display());
- len = strlen(old_status);
+ old_status = get_ps_display(&len);
new_status = (char *) palloc(len + 8 + 1);
memcpy(new_status, old_status, len);
strcpy(new_status + len, " waiting");
set_ps_display(new_status);
+ new_status[len] = '\0'; /* truncate off " waiting" */
awaitedLock = locallock;
awaitedOwner = owner;
@@ -1104,8 +1104,7 @@ WaitOnLock(LOCKMETHODID lockmethodid, LOCALLOCK *locallock,
awaitedLock = NULL;
- set_ps_display(old_status);
- pfree(old_status);
+ set_ps_display(new_status);
pfree(new_status);
LOCK_PRINT("WaitOnLock: wakeup on lock",