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

Commit7a142b6

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 parentc3656c9 commit7a142b6

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
@@ -688,27 +688,17 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
688688
MemSet(values,0,sizeof(values));
689689
MemSet(nulls,0,sizeof(nulls));
690690

691-
if (pid!=-1)
692-
{
693-
/* Skip any which are not the one we're looking for. */
694-
PgBackendStatus*be=pgstat_fetch_stat_beentry(curr_backend);
695-
696-
if (!be||be->st_procpid!=pid)
697-
continue;
698-
699-
}
700-
701691
/* Get the next one in the list */
702692
local_beentry=pgstat_fetch_stat_local_beentry(curr_backend);
703693
if (!local_beentry)
704-
continue;
705-
706-
beentry=&local_beentry->backendStatus;
707-
if (!beentry)
708694
{
709695
inti;
710696

711-
for (i=0;i<sizeof(nulls) /sizeof(nulls[0]);i++)
697+
/* Ignore missing entries if looking for specific PID */
698+
if (pid!=-1)
699+
continue;
700+
701+
for (i=0;i<lengthof(nulls);i++)
712702
nulls[i]= true;
713703

714704
nulls[5]= false;
@@ -718,6 +708,12 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
718708
continue;
719709
}
720710

711+
beentry=&local_beentry->backendStatus;
712+
713+
/* If looking for specific PID, ignore all the others */
714+
if (pid!=-1&&beentry->st_procpid!=pid)
715+
continue;
716+
721717
/* Values available to all callers */
722718
values[0]=ObjectIdGetDatum(beentry->st_databaseid);
723719
values[1]=Int32GetDatum(beentry->st_procpid);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp