diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2008-04-16 23:59:40 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2008-04-16 23:59:40 +0000 |
commit | d1cbd26ded664bf2d3ace87036b822dedba28077 (patch) | |
tree | b991c0196d5abe92d4d77e79449b44ced35b7d5f /src/backend/storage/ipc/ipc.c | |
parent | 74be86847c8cdd274a274fc9384988cb81756d87 (diff) | |
download | postgresql-d1cbd26ded664bf2d3ace87036b822dedba28077.tar.gz postgresql-d1cbd26ded664bf2d3ace87036b822dedba28077.zip |
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.
Diffstat (limited to 'src/backend/storage/ipc/ipc.c')
-rw-r--r-- | src/backend/storage/ipc/ipc.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/backend/storage/ipc/ipc.c b/src/backend/storage/ipc/ipc.c index 91fbea2ea4f..ccfa8a27bf2 100644 --- a/src/backend/storage/ipc/ipc.c +++ b/src/backend/storage/ipc/ipc.c @@ -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, @@ -219,6 +219,24 @@ void } /* ---------------------------------------------------------------- + * 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 * * this function clears all on_proc_exit() and on_shmem_exit() |