Skip to content

[pull] master from postgres:master #1014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/backend/utils/misc/injection_point.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,49 @@ IsInjectionPointAttached(const char *name)
return false; /* silence compiler */
#endif
}

/*
* Retrieve a list of all the injection points currently attached.
*
* This list is palloc'd in the current memory context.
*/
List *
InjectionPointList(void)
{
#ifdef USE_INJECTION_POINTS
List *inj_points = NIL;
uint32 max_inuse;

LWLockAcquire(InjectionPointLock, LW_SHARED);

max_inuse = pg_atomic_read_u32(&ActiveInjectionPoints->max_inuse);

for (uint32 idx = 0; idx < max_inuse; idx++)
{
InjectionPointEntry *entry;
InjectionPointData *inj_point;
uint64 generation;

entry = &ActiveInjectionPoints->entries[idx];
generation = pg_atomic_read_u64(&entry->generation);

/* skip free slots */
if (generation % 2 == 0)
continue;

inj_point = (InjectionPointData *) palloc0(sizeof(InjectionPointData));
inj_point->name = pstrdup(entry->name);
inj_point->library = pstrdup(entry->library);
inj_point->function = pstrdup(entry->function);
inj_points = lappend(inj_points, inj_point);
}

LWLockRelease(InjectionPointLock);

return inj_points;

#else
elog(ERROR, "Injection points are not supported by this build");
return NIL; /* keep compiler quiet */
#endif
}
16 changes: 16 additions & 0 deletions src/include/utils/injection_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
#ifndef INJECTION_POINT_H
#define INJECTION_POINT_H

#include "nodes/pg_list.h"

/*
* Injection point data, used when retrieving a list of all the attached
* injection points.
*/
typedef struct InjectionPointData
{
const char *name;
const char *library;
const char *function;
} InjectionPointData;

/*
* Injection points require --enable-injection-points.
*/
Expand Down Expand Up @@ -47,6 +60,9 @@ extern void InjectionPointCached(const char *name, void *arg);
extern bool IsInjectionPointAttached(const char *name);
extern bool InjectionPointDetach(const char *name);

/* Get the current set of injection points attached */
extern List *InjectionPointList(void);

#ifdef EXEC_BACKEND
extern PGDLLIMPORT struct InjectionPointsCtl *ActiveInjectionPoints;
#endif
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/libpq/fe-cancel.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ PQcancelCreate(PGconn *conn)
goto oom_error;

originalHost = conn->connhost[conn->whichhost];
cancelConn->connhost[0].type = originalHost.type;
if (originalHost.host)
{
cancelConn->connhost[0].host = strdup(originalHost.host);
Expand Down
1 change: 1 addition & 0 deletions src/tools/pgindent/typedefs.list
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,7 @@ InjectionPointCacheEntry
InjectionPointCallback
InjectionPointCondition
InjectionPointConditionType
InjectionPointData
InjectionPointEntry
InjectionPointSharedState
InjectionPointsCtl
Expand Down