mirror of
https://github.com/postgres/postgres.git
synced 2025-12-19 17:02:53 +03:00
injection_points: Add variant for injection_point_attach()
This new function is able to take in input more data than the existing injection_point_attach(): - A library name. - A function name. - Some private data. This gives more flexibility for tests so as these would not need to reinvent a wrapper for InjectionPointAttach() when attaching a callback from a library other than "injection_points". injection_point_detach() can be used with both versions of injection_point_attach(). Author: Rahila Syed <rahilasyed.90@gmail.com> Reviewed-by: Mihail Nikalayeu <mihailnikalayeu@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/CAH2L28sOG2b_TKkZU51dy+pWJtny1mqDmeFiFoUASGa0X0iiKQ@mail.gmail.com
This commit is contained in:
@@ -391,6 +391,47 @@ injection_points_attach(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/*
|
||||
* SQL function for creating an injection point with library name, function
|
||||
* name and private data.
|
||||
*/
|
||||
PG_FUNCTION_INFO_V1(injection_points_attach_func);
|
||||
Datum
|
||||
injection_points_attach_func(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *name;
|
||||
char *lib_name;
|
||||
char *function;
|
||||
bytea *private_data = NULL;
|
||||
int private_data_size = 0;
|
||||
|
||||
if (PG_ARGISNULL(0))
|
||||
elog(ERROR, "injection point name cannot be NULL");
|
||||
if (PG_ARGISNULL(1))
|
||||
elog(ERROR, "injection point library cannot be NULL");
|
||||
if (PG_ARGISNULL(2))
|
||||
elog(ERROR, "injection point function cannot be NULL");
|
||||
|
||||
name = text_to_cstring(PG_GETARG_TEXT_PP(0));
|
||||
lib_name = text_to_cstring(PG_GETARG_TEXT_PP(1));
|
||||
function = text_to_cstring(PG_GETARG_TEXT_PP(2));
|
||||
|
||||
if (!PG_ARGISNULL(3))
|
||||
{
|
||||
private_data = PG_GETARG_BYTEA_PP(3);
|
||||
private_data_size = VARSIZE_ANY_EXHDR(private_data);
|
||||
}
|
||||
|
||||
pgstat_report_inj_fixed(1, 0, 0, 0, 0);
|
||||
if (private_data != NULL)
|
||||
InjectionPointAttach(name, lib_name, function, VARDATA_ANY(private_data),
|
||||
private_data_size);
|
||||
else
|
||||
InjectionPointAttach(name, lib_name, function, NULL,
|
||||
0);
|
||||
PG_RETURN_VOID();
|
||||
}
|
||||
|
||||
/*
|
||||
* SQL function for loading an injection point.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user