mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +03:00
Repair two places where SIGTERM exit could leave shared memory state
corrupted. (Neither is very important if SIGTERM is used to shut down the whole database cluster together, but there's a problem if someone tries to SIGTERM individual backends.) To do this, introduce new infrastructure macros PG_ENSURE_ERROR_CLEANUP/PG_END_ENSURE_ERROR_CLEANUP that take care of transiently pushing an on_shmem_exit cleanup hook. Also use this method for createdb cleanup --- that wasn't a shared-memory-corruption problem, but SIGTERM abort of createdb could leave orphaned files lying around. Backpatch as far as 8.2. The shmem corruption cases don't exist in 8.1, and the createdb usage doesn't seem important enough to risk backpatching further.
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/storage/ipc/ipc.c,v 1.100 2008/01/01 19:45:51 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/storage/ipc/ipc.c,v 1.101 2008/04/16 23:59:40 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -56,7 +56,7 @@ bool proc_exit_inprogress = false;
|
||||
|
||||
static struct ONEXIT
|
||||
{
|
||||
void (*function) (int code, Datum arg);
|
||||
pg_on_exit_callback function;
|
||||
Datum arg;
|
||||
} on_proc_exit_list[MAX_ON_EXITS], on_shmem_exit_list[MAX_ON_EXITS];
|
||||
|
||||
@@ -184,7 +184,7 @@ shmem_exit(int code)
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
on_proc_exit(void (*function) (int code, Datum arg), Datum arg)
|
||||
on_proc_exit(pg_on_exit_callback function, Datum arg)
|
||||
{
|
||||
if (on_proc_exit_index >= MAX_ON_EXITS)
|
||||
ereport(FATAL,
|
||||
@@ -205,7 +205,7 @@ void
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
on_shmem_exit(void (*function) (int code, Datum arg), Datum arg)
|
||||
on_shmem_exit(pg_on_exit_callback function, Datum arg)
|
||||
{
|
||||
if (on_shmem_exit_index >= MAX_ON_EXITS)
|
||||
ereport(FATAL,
|
||||
@@ -218,6 +218,24 @@ void
|
||||
++on_shmem_exit_index;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* cancel_shmem_exit
|
||||
*
|
||||
* this function removes an entry, if present, from the list of
|
||||
* functions to be invoked by shmem_exit(). For simplicity,
|
||||
* only the latest entry can be removed. (We could work harder
|
||||
* but there is no need for current uses.)
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
void
|
||||
cancel_shmem_exit(pg_on_exit_callback function, Datum arg)
|
||||
{
|
||||
if (on_shmem_exit_index > 0 &&
|
||||
on_shmem_exit_list[on_shmem_exit_index - 1].function == function &&
|
||||
on_shmem_exit_list[on_shmem_exit_index - 1].arg == arg)
|
||||
--on_shmem_exit_index;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* on_exit_reset
|
||||
*
|
||||
|
Reference in New Issue
Block a user