v2-0001-Overload-the-injection_points_attach-sql-function.patch
application/octet-stream
Filename: v2-0001-Overload-the-injection_points_attach-sql-function.patch
Type: application/octet-stream
Part: 0
From d692ed3dde2b5c6dbeb9a3a3cdb9c9e86c746937 Mon Sep 17 00:00:00 2001
From: Rahila Syed <rahilasyed.90@gmail.com>
Date: Wed, 29 Oct 2025 16:38:38 +0530
Subject: [PATCH] Overload the injection_points_attach sql function
Add a new sql function to assign C functions to injection
points. This function has same name but different arguments
as injection_points_attach. It takes as input module name and
function name in addition to injection point name.
---
.../injection_points--1.0.sql | 11 ++++++
.../injection_points/injection_points.c | 37 +++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/src/test/modules/injection_points/injection_points--1.0.sql b/src/test/modules/injection_points/injection_points--1.0.sql
index a7b61fbdfe6..5bff4ca6539 100644
--- a/src/test/modules/injection_points/injection_points--1.0.sql
+++ b/src/test/modules/injection_points/injection_points--1.0.sql
@@ -14,6 +14,17 @@ RETURNS void
AS 'MODULE_PATHNAME', 'injection_points_attach'
LANGUAGE C STRICT PARALLEL UNSAFE;
+--
+-- injection_points_attach()
+--
+-- Attaches a function to the given injection point.
+--
+CREATE FUNCTION injection_points_attach(IN point_name TEXT,
+ IN library_name TEXT, IN function_name TEXT)
+RETURNS void
+AS 'MODULE_PATHNAME', 'injection_points_attach_func'
+LANGUAGE C STRICT PARALLEL UNSAFE;
+
--
-- injection_points_load()
--
diff --git a/src/test/modules/injection_points/injection_points.c b/src/test/modules/injection_points/injection_points.c
index 31138301117..ebc0d8835f2 100644
--- a/src/test/modules/injection_points/injection_points.c
+++ b/src/test/modules/injection_points/injection_points.c
@@ -391,6 +391,43 @@ injection_points_attach(PG_FUNCTION_ARGS)
PG_RETURN_VOID();
}
+/*
+ * SQL function for creating an injection point.
+ */
+PG_FUNCTION_INFO_V1(injection_points_attach_func);
+Datum
+injection_points_attach_func(PG_FUNCTION_ARGS)
+{
+ char *name = text_to_cstring(PG_GETARG_TEXT_PP(0));
+ char *lib_name = text_to_cstring(PG_GETARG_TEXT_PP(1));
+ char *function = text_to_cstring(PG_GETARG_TEXT_PP(2));
+ InjectionPointCondition condition = {0};
+
+ if (injection_point_local)
+ {
+ condition.type = INJ_CONDITION_PID;
+ condition.pid = MyProcPid;
+ }
+
+ pgstat_report_inj_fixed(1, 0, 0, 0, 0);
+ InjectionPointAttach(name, lib_name, function, &condition,
+ sizeof(InjectionPointCondition));
+ if (injection_point_local)
+ {
+ MemoryContext oldctx;
+
+ /* Local injection point, so track it for automated cleanup */
+ oldctx = MemoryContextSwitchTo(TopMemoryContext);
+ inj_list_local = lappend(inj_list_local, makeString(pstrdup(name)));
+ MemoryContextSwitchTo(oldctx);
+ }
+
+ /* Add entry for stats */
+ pgstat_create_inj(name);
+
+ PG_RETURN_VOID();
+
+}
/*
* SQL function for loading an injection point.
*/
--
2.34.1