32 #ifdef USE_INJECTION_POINTS
39 static HTAB *InjectionPointHash;
42 #define INJ_NAME_MAXLEN 64
43 #define INJ_LIB_MAXLEN 128
44 #define INJ_FUNC_MAXLEN 128
47 typedef struct InjectionPointEntry
50 char library[INJ_LIB_MAXLEN];
51 char function[INJ_FUNC_MAXLEN];
52 } InjectionPointEntry;
54 #define INJECTION_POINT_HASH_INIT_SIZE 16
55 #define INJECTION_POINT_HASH_MAX_SIZE 128
61 typedef struct InjectionPointCacheEntry
65 } InjectionPointCacheEntry;
67 static HTAB *InjectionPointCache = NULL;
75 injection_point_cache_add(
const char *
name,
78 InjectionPointCacheEntry *entry;
82 if (InjectionPointCache == NULL)
87 hash_ctl.
entrysize =
sizeof(InjectionPointCacheEntry);
90 InjectionPointCache =
hash_create(
"InjectionPoint cache hash",
91 INJECTION_POINT_HASH_MAX_SIZE,
96 entry = (InjectionPointCacheEntry *)
112 injection_point_cache_remove(
const char *
name)
115 if (InjectionPointCache == NULL)
127 injection_point_cache_get(
const char *
name)
130 InjectionPointCacheEntry *entry;
133 if (InjectionPointCache == NULL)
136 entry = (InjectionPointCacheEntry *)
140 return entry->callback;
152 #ifdef USE_INJECTION_POINTS
156 sizeof(InjectionPointEntry)));
169 #ifdef USE_INJECTION_POINTS
174 info.
entrysize =
sizeof(InjectionPointEntry);
176 INJECTION_POINT_HASH_INIT_SIZE,
177 INJECTION_POINT_HASH_MAX_SIZE,
189 const char *
function)
191 #ifdef USE_INJECTION_POINTS
192 InjectionPointEntry *entry_by_name;
196 elog(
ERROR,
"injection point name %s too long (maximum of %u)",
198 if (strlen(library) >= INJ_LIB_MAXLEN)
199 elog(
ERROR,
"injection point library %s too long (maximum of %u)",
200 library, INJ_LIB_MAXLEN);
201 if (strlen(
function) >= INJ_FUNC_MAXLEN)
202 elog(
ERROR,
"injection point function %s too long (maximum of %u)",
203 function, INJ_FUNC_MAXLEN);
210 entry_by_name = (InjectionPointEntry *)
220 strlcpy(entry_by_name->name,
name,
sizeof(entry_by_name->name));
222 strlcpy(entry_by_name->library, library,
sizeof(entry_by_name->library));
223 entry_by_name->library[INJ_LIB_MAXLEN - 1] =
'\0';
224 strlcpy(entry_by_name->function,
function,
sizeof(entry_by_name->function));
225 entry_by_name->function[INJ_FUNC_MAXLEN - 1] =
'\0';
230 elog(
ERROR,
"injection points are not supported by this build");
240 #ifdef USE_INJECTION_POINTS
251 elog(
ERROR,
"Injection points are not supported by this build");
264 #ifdef USE_INJECTION_POINTS
265 InjectionPointEntry *entry_by_name;
270 entry_by_name = (InjectionPointEntry *)
281 injection_point_cache_remove(
name);
289 injection_callback = injection_point_cache_get(
name);
290 if (injection_callback == NULL)
296 entry_by_name->library, DLSUFFIX);
299 elog(
ERROR,
"could not find library \"%s\" for injection point \"%s\"",
305 if (injection_callback == NULL)
306 elog(
ERROR,
"could not find function \"%s\" in library \"%s\" for injection point \"%s\"",
307 entry_by_name->function, path,
name);
310 injection_point_cache_add(
name, injection_callback);
313 injection_callback(
name);
315 elog(
ERROR,
"Injection points are not supported by this build");
#define Assert(condition)
void * load_external_function(const char *filename, const char *funcname, bool signalNotFound, void **filehandle)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Size hash_estimate_size(long num_entries, Size entrysize)
bool pg_file_exists(const char *name)
char pkglib_path[MAXPGPATH]
void InjectionPointShmemInit(void)
Size InjectionPointShmemSize(void)
void InjectionPointRun(const char *name)
void InjectionPointDetach(const char *name)
void InjectionPointAttach(const char *name, const char *library, const char *function)
void(* InjectionPointCallback)(const char *name)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
MemoryContext TopMemoryContext
size_t strlcpy(char *dst, const char *src, size_t siz)
Size add_size(Size s1, Size s2)
HTAB * ShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags)
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)