mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-13 20:19:44 +02:00
f06e79525a
Natoli and Bruce Momjian (and some cosmetic fixes from Neil Conway). Changes: - remove duplicate signal definitions from pqsignal.h - replace pqkill() with kill() and redefine kill() in Win32 - use ereport() in place of fprintf() in some error handling in pqsignal.c - export pg_queue_signal() and make use of it where necessary - add a console control handler for Ctrl-C and similar handling on Win32 - do WaitForSingleObjectEx() in CHECK_FOR_INTERRUPTS() on Win32; query cancelling should now work on Win32 - various other fixes and cleanups
86 lines
2.3 KiB
C
86 lines
2.3 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* pmsignal.c
|
|
* routines for signaling the postmaster from its child processes
|
|
*
|
|
*
|
|
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
*
|
|
* IDENTIFICATION
|
|
* $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.13 2004/02/08 22:28:56 neilc Exp $
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
#include "postgres.h"
|
|
|
|
#include <signal.h>
|
|
#include <unistd.h>
|
|
|
|
#include "miscadmin.h"
|
|
#include "storage/pmsignal.h"
|
|
#include "storage/shmem.h"
|
|
|
|
|
|
/*
|
|
* The postmaster is signaled by its children by sending SIGUSR1. The
|
|
* specific reason is communicated via flags in shared memory. We keep
|
|
* a boolean flag for each possible "reason", so that different reasons
|
|
* can be signaled by different backends at the same time. (However,
|
|
* if the same reason is signaled more than once simultaneously, the
|
|
* postmaster will observe it only once.)
|
|
*
|
|
* The flags are actually declared as "volatile sig_atomic_t" for maximum
|
|
* portability. This should ensure that loads and stores of the flag
|
|
* values are atomic, allowing us to dispense with any explicit locking.
|
|
*/
|
|
|
|
static volatile sig_atomic_t *PMSignalFlags;
|
|
|
|
|
|
/*
|
|
* PMSignalInit - initialize during shared-memory creation
|
|
*/
|
|
void
|
|
PMSignalInit(void)
|
|
{
|
|
bool found;
|
|
PMSignalFlags = (sig_atomic_t *)
|
|
ShmemInitStruct("PMSignalFlags",NUM_PMSIGNALS * sizeof(sig_atomic_t),&found);
|
|
|
|
if (!found)
|
|
MemSet(PMSignalFlags, 0, NUM_PMSIGNALS * sizeof(sig_atomic_t));
|
|
}
|
|
|
|
/*
|
|
* SendPostmasterSignal - signal the postmaster from a child process
|
|
*/
|
|
void
|
|
SendPostmasterSignal(PMSignalReason reason)
|
|
{
|
|
/* If called in a standalone backend, do nothing */
|
|
if (!IsUnderPostmaster)
|
|
return;
|
|
/* Atomically set the proper flag */
|
|
PMSignalFlags[reason] = true;
|
|
/* Send signal to postmaster */
|
|
kill(PostmasterPid, SIGUSR1);
|
|
}
|
|
|
|
/*
|
|
* CheckPostmasterSignal - check to see if a particular reason has been
|
|
* signaled, and clear the signal flag. Should be called by postmaster
|
|
* after receiving SIGUSR1.
|
|
*/
|
|
bool
|
|
CheckPostmasterSignal(PMSignalReason reason)
|
|
{
|
|
/* Careful here --- don't clear flag if we haven't seen it set */
|
|
if (PMSignalFlags[reason])
|
|
{
|
|
PMSignalFlags[reason] = false;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|