Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b9e5249

Browse files
committed
Fix using injection points at backend startup in EXEC_BACKEND mode
Commit 86db52a 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
1 parent c95d215 commit b9e5249

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/backend/postmaster/launch_backend.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "utils/builtins.h"
6464
#include "utils/datetime.h"
6565
#include "utils/guc.h"
66+
#include "utils/injection_point.h"
6667
#include "utils/memutils.h"
6768
#include "utils/timestamp.h"
6869

@@ -104,6 +105,9 @@ typedef struct
104105
void *UsedShmemSegAddr;
105106
slock_t *ShmemLock;
106107
struct bkend *ShmemBackendArray;
108+
#ifdef USE_INJECTION_POINTS
109+
struct InjectionPointsCtl *ActiveInjectionPoints;
110+
#endif
107111
#ifndef HAVE_SPINLOCKS
108112
PGSemaphore *SpinlockSemaArray;
109113
#endif
@@ -710,6 +714,10 @@ save_backend_variables(BackendParameters *param, ClientSocket *client_sock,
710714
param->ShmemLock = ShmemLock;
711715
param->ShmemBackendArray = ShmemBackendArray;
712716

717+
#ifdef USE_INJECTION_POINTS
718+
param->ActiveInjectionPoints = ActiveInjectionPoints;
719+
#endif
720+
713721
#ifndef HAVE_SPINLOCKS
714722
param->SpinlockSemaArray = SpinlockSemaArray;
715723
#endif
@@ -969,6 +977,10 @@ restore_backend_variables(BackendParameters *param)
969977
ShmemLock = param->ShmemLock;
970978
ShmemBackendArray = param->ShmemBackendArray;
971979

980+
#ifdef USE_INJECTION_POINTS
981+
ActiveInjectionPoints = param->ActiveInjectionPoints;
982+
#endif
983+
972984
#ifndef HAVE_SPINLOCKS
973985
SpinlockSemaArray = param->SpinlockSemaArray;
974986
#endif

src/backend/utils/misc/injection_point.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ typedef struct InjectionPointsCtl
8585
InjectionPointEntry entries[MAX_INJECTION_POINTS];
8686
} InjectionPointsCtl;
8787

88-
static InjectionPointsCtl *ActiveInjectionPoints;
88+
NON_EXEC_STATIC InjectionPointsCtl *ActiveInjectionPoints;
8989

9090
/*
9191
* Backend local cache of injection callbacks already loaded, stored in

src/include/utils/injection_point.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ extern void InjectionPointRun(const char *name);
4343
extern void InjectionPointCached(const char *name);
4444
extern bool InjectionPointDetach(const char *name);
4545

46+
#ifdef EXEC_BACKEND
47+
extern PGDLLIMPORT struct InjectionPointsCtl *ActiveInjectionPoints;
48+
#endif
49+
4650
#endif /* INJECTION_POINT_H */

0 commit comments

Comments
 (0)