|
5 | 5 | * to contain some useful information. Mechanism differs wildly across
|
6 | 6 | * platforms.
|
7 | 7 | *
|
8 |
| - * $PostgreSQL: pgsql/src/backend/utils/misc/ps_status.c,v 1.25 2005/10/15 02:49:36 momjian Exp $ |
| 8 | + * $PostgreSQL: pgsql/src/backend/utils/misc/ps_status.c,v 1.26 2005/11/05 03:04:52 tgl Exp $ |
9 | 9 | *
|
10 | 10 | * Copyright (c) 2000-2005, PostgreSQL Global Development Group
|
11 | 11 | * various details abducted from various places
|
@@ -307,10 +307,6 @@ init_ps_display(const char *username, const char *dbname,
|
307 | 307 | void
|
308 | 308 | set_ps_display(const char *activity)
|
309 | 309 | {
|
310 |
| - /* save tag for possible use by elog.c */ |
311 |
| - if (MyProcPort) |
312 |
| - MyProcPort->commandTag = activity; |
313 |
| - |
314 | 310 | #ifndef PS_USE_NONE
|
315 | 311 | /* no ps display for stand-alone backend */
|
316 | 312 | if (!IsUnderPostmaster)
|
@@ -365,15 +361,31 @@ set_ps_display(const char *activity)
|
365 | 361 |
|
366 | 362 | /*
|
367 | 363 | * Returns what's currently in the ps display, in case someone needs
|
368 |
| - * it. Note that only the activity part is returned. |
| 364 | + * it. Note that only the activity part is returned. On some platforms |
| 365 | + * the string will not be null-terminated, so return the effective |
| 366 | + * length into *displen. |
369 | 367 | */
|
370 | 368 | const char *
|
371 |
| -get_ps_display(void) |
| 369 | +get_ps_display(int *displen) |
372 | 370 | {
|
373 | 371 | #ifdef PS_USE_CLOBBER_ARGV
|
| 372 | + size_t offset; |
| 373 | + |
374 | 374 | /* If ps_buffer is a pointer, it might still be null */
|
375 | 375 | if (!ps_buffer)
|
| 376 | + { |
| 377 | + *displen = 0; |
376 | 378 | return "";
|
| 379 | + } |
| 380 | + |
| 381 | + /* Remove any trailing spaces to offset the effect of PS_PADDING */ |
| 382 | + offset = ps_buffer_size; |
| 383 | + while (offset > ps_buffer_fixed_size && ps_buffer[offset-1] == PS_PADDING) |
| 384 | + offset--; |
| 385 | + |
| 386 | + *displen = offset - ps_buffer_fixed_size; |
| 387 | +#else |
| 388 | + *displen = strlen(ps_buffer + ps_buffer_fixed_size); |
377 | 389 | #endif
|
378 | 390 |
|
379 | 391 | return ps_buffer + ps_buffer_fixed_size;
|
|
0 commit comments