pgsql: Move cancel key generation to after forking the backend - Mailing list pgsql-committers

From Heikki Linnakangas
Subject pgsql: Move cancel key generation to after forking the backend
Date
Msg-id E1sYQGU-001kL9-BT@gemulon.postgresql.org
Whole thread Raw
Responses Re: pgsql: Move cancel key generation to after forking the backend
List pgsql-committers
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

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/9d9b9d46f3c509c722ebbf2a1e7dc6296a6c711d

Modified Files
--------------
src/backend/postmaster/auxprocess.c     |   2 +-
src/backend/postmaster/launch_backend.c |  10 +-
src/backend/postmaster/postmaster.c     | 196 +-------------------------------
src/backend/storage/ipc/ipci.c          |  11 --
src/backend/storage/ipc/procsignal.c    | 185 +++++++++++++++++++++++-------
src/backend/tcop/backend_startup.c      |   9 +-
src/backend/tcop/postgres.c             |  17 +++
src/backend/utils/init/globals.c        |   3 +-
src/backend/utils/init/postinit.c       |   2 +-
src/include/miscadmin.h                 |   1 +
src/include/postmaster/postmaster.h     |   9 --
src/include/storage/procsignal.h        |  10 +-
12 files changed, 193 insertions(+), 262 deletions(-)


pgsql-committers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: pgsql: Fix outdated comment in smgrtruncate()
Next
From: Daniel Gustafsson
Date:
Subject: Re: pgsql: Move cancel key generation to after forking the backend