mirror of https://github.com/postgres/postgres
so that only one signal number is used not three. Flags in shared memory tell the reason(s) for the current signal. This method is extensible to handle more signal reasons without chewing up even more signal numbers, but the immediate reason is to keep pg_pwd reloads separate from SIGHUP processing in the postmaster. Also clean up some problems in the postmaster with delayed response to checkpoint status changes --- basically, it wouldn't schedule a checkpoint if it wasn't getting connection requests on a regular basis.REL7_2_STABLE
parent
5f067722bf
commit
fb5f1b2c13
@ -0,0 +1,86 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* pmsignal.c |
||||
* routines for signaling the postmaster from its child processes |
||||
* |
||||
* |
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group |
||||
* Portions Copyright (c) 1994, Regents of the University of California |
||||
* |
||||
* IDENTIFICATION |
||||
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/pmsignal.c,v 1.1 2001/11/04 19:55:31 tgl 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) |
||||
{ |
||||
/* Should be called only once */ |
||||
Assert(!PMSignalFlags); |
||||
|
||||
PMSignalFlags = (sig_atomic_t *) |
||||
ShmemAlloc(NUM_PMSIGNALS * sizeof(sig_atomic_t)); |
||||
|
||||
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 (assume it is our direct parent) */ |
||||
kill(getppid(), 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; |
||||
} |
||||
@ -0,0 +1,39 @@ |
||||
/*-------------------------------------------------------------------------
|
||||
* |
||||
* pmsignal.h |
||||
* routines for signaling the postmaster from its child processes |
||||
* |
||||
* |
||||
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group |
||||
* Portions Copyright (c) 1994, Regents of the University of California |
||||
* |
||||
* $Id: pmsignal.h,v 1.1 2001/11/04 19:55:31 tgl Exp $ |
||||
* |
||||
*------------------------------------------------------------------------- |
||||
*/ |
||||
#ifndef PMSIGNAL_H |
||||
#define PMSIGNAL_H |
||||
|
||||
/*
|
||||
* Reasons for signaling the postmaster. We can cope with simultaneous |
||||
* signals for different reasons. If the same reason is signaled multiple |
||||
* times in quick succession, however, the postmaster is likely to observe |
||||
* only one notification of it. This is okay for the present uses. |
||||
*/ |
||||
typedef enum |
||||
{ |
||||
PMSIGNAL_DO_CHECKPOINT, /* request to start a checkpoint */ |
||||
PMSIGNAL_PASSWORD_CHANGE, /* pg_pwd file has changed */ |
||||
PMSIGNAL_WAKEN_CHILDREN, /* send a NOTIFY signal to all backends */ |
||||
|
||||
NUM_PMSIGNALS /* Must be last value of enum! */ |
||||
} PMSignalReason; |
||||
|
||||
/*
|
||||
* prototypes for functions in pmsignal.c |
||||
*/ |
||||
extern void PMSignalInit(void); |
||||
extern void SendPostmasterSignal(PMSignalReason reason); |
||||
extern bool CheckPostmasterSignal(PMSignalReason reason); |
||||
|
||||
#endif /* PMSIGNAL_H */ |
||||
Loading…
Reference in new issue