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

Commit f19beba

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 f06a632 commit f19beba

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
@@ -722,6 +726,10 @@ save_backend_variables(BackendParameters *param, ClientSocket *client_sock,
722726
param->ShmemLock = ShmemLock;
723727
param->ShmemBackendArray = ShmemBackendArray;
724728

729+
#ifdef USE_INJECTION_POINTS
730+
param->ActiveInjectionPoints = ActiveInjectionPoints;
731+
#endif
732+
725733
#ifndef HAVE_SPINLOCKS
726734
param->SpinlockSemaArray = SpinlockSemaArray;
727735
#endif
@@ -981,6 +989,10 @@ restore_backend_variables(BackendParameters *param)
981989
ShmemLock = param->ShmemLock;
982990
ShmemBackendArray = param->ShmemBackendArray;
983991

992+
#ifdef USE_INJECTION_POINTS
993+
ActiveInjectionPoints = param->ActiveInjectionPoints;
994+
#endif
995+
984996
#ifndef HAVE_SPINLOCKS
985997
SpinlockSemaArray = param->SpinlockSemaArray;
986998
#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
@@ -37,4 +37,8 @@ extern void InjectionPointAttach(const char *name,
3737
extern void InjectionPointRun(const char *name);
3838
extern bool InjectionPointDetach(const char *name);
3939

40+
#ifdef EXEC_BACKEND
41+
extern PGDLLIMPORT struct InjectionPointsCtl *ActiveInjectionPoints;
42+
#endif
43+
4044
#endif /* INJECTION_POINT_H */

0 commit comments

Comments
 (0)