diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2024-07-26 14:55:04 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2024-07-26 15:12:12 +0300 |
commit | f19beba3e3acfd804d678af3f768bee069038486 (patch) | |
tree | e751294fe470e4bc080f2458eb04d3a347518b08 /src | |
parent | f06a632a77ed27aab087d62bd76bc52be3a2ac6f (diff) | |
download | postgresql-f19beba3e3acfd804d678af3f768bee069038486.tar.gz postgresql-f19beba3e3acfd804d678af3f768bee069038486.zip |
Fix using injection points at backend startup in EXEC_BACKEND mode
Commit 86db52a506 changed the locking of injection points to use only
atomic ops and spinlocks, to make it possible to define injection
points in processes that don't have a PGPROC entry (yet). However, it
didn't work in EXEC_BACKEND mode, because the pointer to shared memory
area was not initialized until the process "attaches" to all the
shared memory structs. To fix, pass the pointer to the child process
along with other global variables that need to be set up early.
Backpatch-through: 17
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/postmaster/launch_backend.c | 12 | ||||
-rw-r--r-- | src/backend/utils/misc/injection_point.c | 2 | ||||
-rw-r--r-- | src/include/utils/injection_point.h | 4 |
3 files changed, 17 insertions, 1 deletions
diff --git a/src/backend/postmaster/launch_backend.c b/src/backend/postmaster/launch_backend.c index d6c63896a65..bdf490c31d0 100644 --- a/src/backend/postmaster/launch_backend.c +++ b/src/backend/postmaster/launch_backend.c @@ -63,6 +63,7 @@ #include "utils/builtins.h" #include "utils/datetime.h" #include "utils/guc.h" +#include "utils/injection_point.h" #include "utils/memutils.h" #include "utils/timestamp.h" @@ -104,6 +105,9 @@ typedef struct void *UsedShmemSegAddr; slock_t *ShmemLock; struct bkend *ShmemBackendArray; +#ifdef USE_INJECTION_POINTS + struct InjectionPointsCtl *ActiveInjectionPoints; +#endif #ifndef HAVE_SPINLOCKS PGSemaphore *SpinlockSemaArray; #endif @@ -722,6 +726,10 @@ save_backend_variables(BackendParameters *param, ClientSocket *client_sock, param->ShmemLock = ShmemLock; param->ShmemBackendArray = ShmemBackendArray; +#ifdef USE_INJECTION_POINTS + param->ActiveInjectionPoints = ActiveInjectionPoints; +#endif + #ifndef HAVE_SPINLOCKS param->SpinlockSemaArray = SpinlockSemaArray; #endif @@ -981,6 +989,10 @@ restore_backend_variables(BackendParameters *param) ShmemLock = param->ShmemLock; ShmemBackendArray = param->ShmemBackendArray; +#ifdef USE_INJECTION_POINTS + ActiveInjectionPoints = param->ActiveInjectionPoints; +#endif + #ifndef HAVE_SPINLOCKS SpinlockSemaArray = param->SpinlockSemaArray; #endif diff --git a/src/backend/utils/misc/injection_point.c b/src/backend/utils/misc/injection_point.c index 3c63a8ace86..ab327779902 100644 --- a/src/backend/utils/misc/injection_point.c +++ b/src/backend/utils/misc/injection_point.c @@ -85,7 +85,7 @@ typedef struct InjectionPointsCtl InjectionPointEntry entries[MAX_INJECTION_POINTS]; } InjectionPointsCtl; -static InjectionPointsCtl *ActiveInjectionPoints; +NON_EXEC_STATIC InjectionPointsCtl *ActiveInjectionPoints; /* * Backend local cache of injection callbacks already loaded, stored in diff --git a/src/include/utils/injection_point.h b/src/include/utils/injection_point.h index a61d5d44391..6e417cedc60 100644 --- a/src/include/utils/injection_point.h +++ b/src/include/utils/injection_point.h @@ -37,4 +37,8 @@ extern void InjectionPointAttach(const char *name, extern void InjectionPointRun(const char *name); extern bool InjectionPointDetach(const char *name); +#ifdef EXEC_BACKEND +extern PGDLLIMPORT struct InjectionPointsCtl *ActiveInjectionPoints; +#endif + #endif /* INJECTION_POINT_H */ |