Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbca6eeb

Browse files
committed
Fix miserable coding in pg_stat_get_activity().
Commitdd1a3bc replaced a test on whether a subroutine returned anull pointer with a test on whether &pointer->backendStatus was null.This accidentally failed to fail, at least on common compilers, becausebackendStatus is the first field in the struct; but it was surely troublewaiting to happen. Commitf91feba then messed things up further,changing the logic tolocal_beentry = pgstat_fetch_stat_local_beentry(curr_backend);if (!local_beentry)continue;beentry = &local_beentry->backendStatus;if (!beentry){where the second "if" is now dead code, so that the intended behavior ofprinting a row with "<backend information not available>" cannot occur.I suspect this is all moot because pgstat_fetch_stat_local_beentrywill never actually return null in this function's usage, but it's stillvery poor coding. Repair back to 9.4 where the original problem wasintroduced.
1 parentf337658 commitbca6eeb

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

‎src/backend/utils/adt/pgstatfuncs.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -577,27 +577,17 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
577577
MemSet(values,0,sizeof(values));
578578
MemSet(nulls,0,sizeof(nulls));
579579

580-
if (pid!=-1)
581-
{
582-
/* Skip any which are not the one we're looking for. */
583-
PgBackendStatus*be=pgstat_fetch_stat_beentry(curr_backend);
584-
585-
if (!be||be->st_procpid!=pid)
586-
continue;
587-
588-
}
589-
590580
/* Get the next one in the list */
591581
local_beentry=pgstat_fetch_stat_local_beentry(curr_backend);
592582
if (!local_beentry)
593-
continue;
594-
595-
beentry=&local_beentry->backendStatus;
596-
if (!beentry)
597583
{
598584
inti;
599585

600-
for (i=0;i<sizeof(nulls) /sizeof(nulls[0]);i++)
586+
/* Ignore missing entries if looking for specific PID */
587+
if (pid!=-1)
588+
continue;
589+
590+
for (i=0;i<lengthof(nulls);i++)
601591
nulls[i]= true;
602592

603593
nulls[5]= false;
@@ -607,6 +597,12 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
607597
continue;
608598
}
609599

600+
beentry=&local_beentry->backendStatus;
601+
602+
/* If looking for specific PID, ignore all the others */
603+
if (pid!=-1&&beentry->st_procpid!=pid)
604+
continue;
605+
610606
/* Values available to all callers */
611607
values[0]=ObjectIdGetDatum(beentry->st_databaseid);
612608
values[1]=Int32GetDatum(beentry->st_procpid);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp