Add InjectionPointList() to retrieve list of injection points · postgres/postgres@7b2eb72 · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Commit 7b2eb72

Browse files
committed
Add InjectionPointList() to retrieve list of injection points
This routine has come as a useful piece to be able to know the list of injection points currently attached in a system. One area would be to use it in a set-returning function, or just let out-of-core code play with it. This hides the internals of the shared memory array lookup holding the information about the injection points (point name, library and function name), allocating the result in a palloc'd List consumable by the caller. Reviewed-by: Jeff Davis <pgsql@j-davis.com> Reviewed-by: Hayato Kuroda <kuroda.hayato@fujitsu.com> Reviewed-by: Rahila Syed <rahilasyed90@gmail.com> Discussion: https://postgr.es/m/Z_xYkA21KyLEHvWR@paquier.xyz Discussion: https://postgr.es/m/aBG2rPwl3GE7m1-Q@paquier.xyz
1 parent fe05430 commit 7b2eb72

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

src/backend/utils/misc/injection_point.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,3 +584,49 @@ IsInjectionPointAttached(const char *name)
584584
return false; /* silence compiler */
585585
#endif
586586
}
587+
588+
/*
589+
* Retrieve a list of all the injection points currently attached.
590+
*
591+
* This list is palloc'd in the current memory context.
592+
*/
593+
List *
594+
InjectionPointList(void)
595+
{
596+
#ifdef USE_INJECTION_POINTS
597+
List *inj_points = NIL;
598+
uint32 max_inuse;
599+
600+
LWLockAcquire(InjectionPointLock, LW_SHARED);
601+
602+
max_inuse = pg_atomic_read_u32(&ActiveInjectionPoints->max_inuse);
603+
604+
for (uint32 idx = 0; idx < max_inuse; idx++)
605+
{
606+
InjectionPointEntry *entry;
607+
InjectionPointData *inj_point;
608+
uint64 generation;
609+
610+
entry = &ActiveInjectionPoints->entries[idx];
611+
generation = pg_atomic_read_u64(&entry->generation);
612+
613+
/* skip free slots */
614+
if (generation % 2 == 0)
615+
continue;
616+
617+
inj_point = (InjectionPointData *) palloc0(sizeof(InjectionPointData));
618+
inj_point->name = pstrdup(entry->name);
619+
inj_point->library = pstrdup(entry->library);
620+
inj_point->function = pstrdup(entry->function);
621+
inj_points = lappend(inj_points, inj_point);
622+
}
623+
624+
LWLockRelease(InjectionPointLock);
625+
626+
return inj_points;
627+
628+
#else
629+
elog(ERROR, "Injection points are not supported by this build");
630+
return NIL; /* keep compiler quiet */
631+
#endif
632+
}

src/include/utils/injection_point.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,19 @@
1111
#ifndef INJECTION_POINT_H
1212
#define INJECTION_POINT_H
1313

14+
#include "nodes/pg_list.h"
15+
16+
/*
17+
* Injection point data, used when retrieving a list of all the attached
18+
* injection points.
19+
*/
20+
typedef struct InjectionPointData
21+
{
22+
const char *name;
23+
const char *library;
24+
const char *function;
25+
} InjectionPointData;
26+
1427
/*
1528
* Injection points require --enable-injection-points.
1629
*/
@@ -47,6 +60,9 @@ extern void InjectionPointCached(const char *name, void *arg);
4760
extern bool IsInjectionPointAttached(const char *name);
4861
extern bool InjectionPointDetach(const char *name);
4962

63+
/* Get the current set of injection points attached */
64+
extern List *InjectionPointList(void);
65+
5066
#ifdef EXEC_BACKEND
5167
extern PGDLLIMPORT struct InjectionPointsCtl *ActiveInjectionPoints;
5268
#endif

src/tools/pgindent/typedefs.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,7 @@ InjectionPointCacheEntry
12911291
InjectionPointCallback
12921292
InjectionPointCondition
12931293
InjectionPointConditionType
1294+
InjectionPointData
12941295
InjectionPointEntry
12951296
InjectionPointSharedState
12961297
InjectionPointsCtl

0 commit comments

Comments
 (0)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.