summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorHeikki Linnakangas2024-07-29 12:37:48 +0000
committerHeikki Linnakangas2024-07-29 12:37:48 +0000
commit9d9b9d46f3c509c722ebbf2a1e7dc6296a6c711d (patch)
tree450cf30fdaca9dd1b5336179f2bb590e397fb9f0 /src/include
parent19de089cdc23373e2f36916017a1e23e8ff4c2f8 (diff)
Move cancel key generation to after forking the backend
Move responsibility of generating the cancel key to the backend process. The cancel key is now generated after forking, and the backend advertises it in the ProcSignal array. When a cancel request arrives, the backend handling it scans the ProcSignal array to find the target pid and cancel key. This is similar to how this previously worked in the EXEC_BACKEND case with the ShmemBackendArray, just reusing the ProcSignal array. One notable change is that we no longer generate cancellation keys for non-backend processes. We generated them before just to prevent a malicious user from canceling them; the keys for non-backend processes were never actually given to anyone. There is now an explicit flag indicating whether a process has a valid key or not. I wrote this originally in preparation for supporting longer cancel keys, but it's a nice cleanup on its own. Reviewed-by: Jelte Fennema-Nio Discussion: https://www.postgresql.org/message-id/508d0505-8b7a-4864-a681-e7e5edfe32aa@iki.fi
Diffstat (limited to 'src/include')
-rw-r--r--src/include/miscadmin.h1
-rw-r--r--src/include/postmaster/postmaster.h9
-rw-r--r--src/include/storage/procsignal.h10
3 files changed, 10 insertions, 10 deletions
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index 90f9b21b258..ac16233b71f 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -191,6 +191,7 @@ extern PGDLLIMPORT pg_time_t MyStartTime;
extern PGDLLIMPORT TimestampTz MyStartTimestamp;
extern PGDLLIMPORT struct Port *MyProcPort;
extern PGDLLIMPORT struct Latch *MyLatch;
+extern PGDLLIMPORT bool MyCancelKeyValid;
extern PGDLLIMPORT int32 MyCancelKey;
extern PGDLLIMPORT int MyPMChildSlot;
diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h
index d19e103937d..4cc59a662ee 100644
--- a/src/include/postmaster/postmaster.h
+++ b/src/include/postmaster/postmaster.h
@@ -36,10 +36,6 @@ extern PGDLLIMPORT bool remove_temp_files_after_crash;
extern PGDLLIMPORT bool send_abort_for_crash;
extern PGDLLIMPORT bool send_abort_for_kill;
-#ifdef EXEC_BACKEND
-extern struct bkend *ShmemBackendArray;
-#endif
-
#ifdef WIN32
extern PGDLLIMPORT HANDLE PostmasterHandle;
#else
@@ -69,14 +65,9 @@ extern bool PostmasterMarkPIDForWorkerNotify(int);
extern void processCancelRequest(int backendPID, int32 cancelAuthCode);
-#ifdef EXEC_BACKEND
-extern Size ShmemBackendArraySize(void);
-extern void ShmemBackendArrayAllocation(void);
-
#ifdef WIN32
extern void pgwin32_register_deadchild_callback(HANDLE procHandle, DWORD procId);
#endif
-#endif
/* defined in globals.c */
extern PGDLLIMPORT struct ClientSocket *MyClientSocket;
diff --git a/src/include/storage/procsignal.h b/src/include/storage/procsignal.h
index 7d290ea7d05..2516869465d 100644
--- a/src/include/storage/procsignal.h
+++ b/src/include/storage/procsignal.h
@@ -62,9 +62,10 @@ typedef enum
extern Size ProcSignalShmemSize(void);
extern void ProcSignalShmemInit(void);
-extern void ProcSignalInit(void);
+extern void ProcSignalInit(bool cancel_key_valid, int32 cancel_key);
extern int SendProcSignal(pid_t pid, ProcSignalReason reason,
ProcNumber procNumber);
+extern void SendCancelRequest(int backendPID, int32 cancelAuthCode);
extern uint64 EmitProcSignalBarrier(ProcSignalBarrierType type);
extern void WaitForProcSignalBarrier(uint64 generation);
@@ -72,4 +73,11 @@ extern void ProcessProcSignalBarrier(void);
extern void procsignal_sigusr1_handler(SIGNAL_ARGS);
+/* ProcSignalHeader is an opaque struct, details known only within procsignal.c */
+typedef struct ProcSignalHeader ProcSignalHeader;
+
+#ifdef EXEC_BACKEND
+extern ProcSignalHeader *ProcSignal;
+#endif
+
#endif /* PROCSIGNAL_H */