mirror of
https://github.com/postgres/postgres.git
synced 2025-11-12 05:01:15 +03:00
pgindent run before 6.3 release, with Thomas' requested changes.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.74 1998/02/24 15:19:00 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.75 1998/02/26 04:34:43 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
*
|
||||
@@ -88,7 +88,7 @@
|
||||
#include "storage/proc.h"
|
||||
#include "utils/elog.h"
|
||||
#ifndef HAVE_GETHOSTNAME
|
||||
# include "port-protos.h" /* For gethostname() */
|
||||
#include "port-protos.h" /* For gethostname() */
|
||||
#endif
|
||||
#include "storage/fd.h"
|
||||
|
||||
@@ -102,8 +102,8 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define INVALID_SOCK (-1)
|
||||
#define ARGV_SIZE 64
|
||||
#define INVALID_SOCK (-1)
|
||||
#define ARGV_SIZE 64
|
||||
|
||||
/*
|
||||
* Max time in seconds for socket to linger (close() to block) waiting
|
||||
@@ -129,30 +129,35 @@ static Dllist *PortList;
|
||||
|
||||
static short PostPortName = -1;
|
||||
static short ActiveBackends = FALSE;
|
||||
/* This is a boolean indicating that there is at least one backend
|
||||
that is accessing the current shared memory and semaphores.
|
||||
Between the time that we start up, or throw away shared memory
|
||||
segments and start over, and the time we generate the next
|
||||
backend (because we received a connection request), it is false.
|
||||
Other times, it is true.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is a boolean indicating that there is at least one backend that
|
||||
* is accessing the current shared memory and semaphores. Between the
|
||||
* time that we start up, or throw away shared memory segments and start
|
||||
* over, and the time we generate the next backend (because we received a
|
||||
* connection request), it is false. Other times, it is true.
|
||||
*/
|
||||
static short shmem_seq = 0;
|
||||
/* This is a sequence number that indicates how many times we've had
|
||||
to throw away the shared memory and start over because we doubted
|
||||
its integrity. It starts off at zero and is incremented every
|
||||
time we start over. We use this to ensure that we use a new
|
||||
IPC shared memory key for the new shared memory segment in case
|
||||
the old segment isn't entirely gone yet.
|
||||
|
||||
The sequence actually cycles back to 0 after 9, so pathologically
|
||||
there could be an IPC failure if 10 sets of backends are all stuck
|
||||
and won't release IPC resources.
|
||||
*/
|
||||
/*
|
||||
* This is a sequence number that indicates how many times we've had to
|
||||
* throw away the shared memory and start over because we doubted its
|
||||
* integrity. It starts off at zero and is incremented every time we
|
||||
* start over. We use this to ensure that we use a new IPC shared memory
|
||||
* key for the new shared memory segment in case the old segment isn't
|
||||
* entirely gone yet.
|
||||
*
|
||||
* The sequence actually cycles back to 0 after 9, so pathologically there
|
||||
* could be an IPC failure if 10 sets of backends are all stuck and won't
|
||||
* release IPC resources.
|
||||
*/
|
||||
|
||||
static IpcMemoryKey ipc_key;
|
||||
/* This is the base IPC shared memory key. Other keys are generated by
|
||||
adding to this.
|
||||
*/
|
||||
static IpcMemoryKey ipc_key;
|
||||
|
||||
/*
|
||||
* This is the base IPC shared memory key. Other keys are generated by
|
||||
* adding to this.
|
||||
*/
|
||||
|
||||
|
||||
static int NextBackendId = MAXINT; /* XXX why? */
|
||||
@@ -200,11 +205,12 @@ static void usage(const char *);
|
||||
static int ServerLoop(void);
|
||||
static int BackendStartup(Port *port);
|
||||
static void readStartupPacket(char *arg, PacketLen len, char *pkt);
|
||||
static int initMasks(fd_set *rmask, fd_set *wmask);
|
||||
static void RandomSalt(char* salt);
|
||||
static int initMasks(fd_set *rmask, fd_set *wmask);
|
||||
static void RandomSalt(char *salt);
|
||||
|
||||
#ifdef CYR_RECODE
|
||||
void GetCharSetByHost(char *,int,char *);
|
||||
void GetCharSetByHost(char *, int, char *);
|
||||
|
||||
#endif
|
||||
|
||||
extern char *optarg;
|
||||
@@ -516,9 +522,10 @@ usage(const char *progname)
|
||||
static int
|
||||
ServerLoop(void)
|
||||
{
|
||||
fd_set readmask, writemask;
|
||||
int nSockets;
|
||||
Dlelem *curr;
|
||||
fd_set readmask,
|
||||
writemask;
|
||||
int nSockets;
|
||||
Dlelem *curr;
|
||||
|
||||
/*
|
||||
* GH: For !HAVE_SIGPROCMASK (NEXTSTEP), TRH implemented an
|
||||
@@ -542,8 +549,9 @@ ServerLoop(void)
|
||||
#endif
|
||||
for (;;)
|
||||
{
|
||||
Port *port;
|
||||
fd_set rmask, wmask;
|
||||
Port *port;
|
||||
fd_set rmask,
|
||||
wmask;
|
||||
|
||||
#ifdef HAVE_SIGPROCMASK
|
||||
sigprocmask(SIG_SETMASK, &oldsigmask, 0);
|
||||
@@ -554,7 +562,7 @@ ServerLoop(void)
|
||||
memmove((char *) &rmask, (char *) &readmask, sizeof(fd_set));
|
||||
memmove((char *) &wmask, (char *) &writemask, sizeof(fd_set));
|
||||
if (select(nSockets, &rmask, &wmask, (fd_set *) NULL,
|
||||
(struct timeval *) NULL) < 0)
|
||||
(struct timeval *) NULL) < 0)
|
||||
{
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
@@ -578,18 +586,18 @@ ServerLoop(void)
|
||||
/* new connection pending on our well-known port's socket */
|
||||
|
||||
if (ServerSock_UNIX != INVALID_SOCK &&
|
||||
FD_ISSET(ServerSock_UNIX, &rmask) &&
|
||||
(port = ConnCreate(ServerSock_UNIX)) != NULL)
|
||||
FD_ISSET(ServerSock_UNIX, &rmask) &&
|
||||
(port = ConnCreate(ServerSock_UNIX)) != NULL)
|
||||
PacketReceiveSetup(&port->pktInfo,
|
||||
readStartupPacket,
|
||||
(char *)port);
|
||||
readStartupPacket,
|
||||
(char *) port);
|
||||
|
||||
if (ServerSock_INET != INVALID_SOCK &&
|
||||
FD_ISSET(ServerSock_INET, &rmask) &&
|
||||
(port = ConnCreate(ServerSock_INET)) != NULL)
|
||||
FD_ISSET(ServerSock_INET, &rmask) &&
|
||||
(port = ConnCreate(ServerSock_INET)) != NULL)
|
||||
PacketReceiveSetup(&port->pktInfo,
|
||||
readStartupPacket,
|
||||
(char *)port);
|
||||
readStartupPacket,
|
||||
(char *) port);
|
||||
|
||||
/* Build up new masks for select(). */
|
||||
|
||||
@@ -600,8 +608,8 @@ ServerLoop(void)
|
||||
while (curr)
|
||||
{
|
||||
Port *port = (Port *) DLE_VAL(curr);
|
||||
int status = STATUS_OK;
|
||||
Dlelem *next;
|
||||
int status = STATUS_OK;
|
||||
Dlelem *next;
|
||||
|
||||
if (FD_ISSET(port->sock, &rmask))
|
||||
{
|
||||
@@ -628,25 +636,24 @@ ServerLoop(void)
|
||||
next = DLGetSucc(curr);
|
||||
|
||||
/*
|
||||
* If there is no error and no outstanding data transfer
|
||||
* going on, then the authentication handshake must be
|
||||
* complete to the postmaster's satisfaction. So,
|
||||
* start the backend.
|
||||
* If there is no error and no outstanding data transfer going
|
||||
* on, then the authentication handshake must be complete to
|
||||
* the postmaster's satisfaction. So, start the backend.
|
||||
*/
|
||||
|
||||
if (status == STATUS_OK && port->pktInfo.state == Idle)
|
||||
{
|
||||
|
||||
/*
|
||||
* If the backend start fails then keep the
|
||||
* connection open to report it. Otherwise,
|
||||
* pretend there is an error to close the
|
||||
* connection which will now be managed by the
|
||||
* backend.
|
||||
* If the backend start fails then keep the connection
|
||||
* open to report it. Otherwise, pretend there is an
|
||||
* error to close the connection which will now be managed
|
||||
* by the backend.
|
||||
*/
|
||||
|
||||
if (BackendStartup(port) != STATUS_OK)
|
||||
PacketSendError(&port->pktInfo,
|
||||
"Backend startup failed");
|
||||
"Backend startup failed");
|
||||
else
|
||||
status = STATUS_ERROR;
|
||||
}
|
||||
@@ -684,9 +691,10 @@ ServerLoop(void)
|
||||
* we are listening on. Return the number of sockets to listen on.
|
||||
*/
|
||||
|
||||
static int initMasks(fd_set *rmask, fd_set *wmask)
|
||||
static int
|
||||
initMasks(fd_set *rmask, fd_set *wmask)
|
||||
{
|
||||
int nsocks = -1;
|
||||
int nsocks = -1;
|
||||
|
||||
FD_ZERO(rmask);
|
||||
FD_ZERO(wmask);
|
||||
@@ -715,38 +723,39 @@ static int initMasks(fd_set *rmask, fd_set *wmask)
|
||||
* Called when the startup packet has been read.
|
||||
*/
|
||||
|
||||
static void readStartupPacket(char *arg, PacketLen len, char *pkt)
|
||||
static void
|
||||
readStartupPacket(char *arg, PacketLen len, char *pkt)
|
||||
{
|
||||
Port *port;
|
||||
Port *port;
|
||||
StartupPacket *si;
|
||||
|
||||
port = (Port *)arg;
|
||||
si = (StartupPacket *)pkt;
|
||||
port = (Port *) arg;
|
||||
si = (StartupPacket *) pkt;
|
||||
|
||||
/*
|
||||
* Get the parameters from the startup packet as C strings. The packet
|
||||
* destination was cleared first so a short packet has zeros silently
|
||||
* added and a long packet is silently truncated.
|
||||
* Get the parameters from the startup packet as C strings. The
|
||||
* packet destination was cleared first so a short packet has zeros
|
||||
* silently added and a long packet is silently truncated.
|
||||
*/
|
||||
|
||||
StrNCpy(port->database, si->database, sizeof (port->database) - 1);
|
||||
StrNCpy(port->user, si->user, sizeof (port->user) - 1);
|
||||
StrNCpy(port->options, si->options, sizeof (port->options) - 1);
|
||||
StrNCpy(port->tty, si->tty, sizeof (port->tty) - 1);
|
||||
StrNCpy(port->database, si->database, sizeof(port->database) - 1);
|
||||
StrNCpy(port->user, si->user, sizeof(port->user) - 1);
|
||||
StrNCpy(port->options, si->options, sizeof(port->options) - 1);
|
||||
StrNCpy(port->tty, si->tty, sizeof(port->tty) - 1);
|
||||
|
||||
/* The database defaults to the user name. */
|
||||
|
||||
if (port->database[0] == '\0')
|
||||
StrNCpy(port->database, si->user, sizeof (port->database) - 1);
|
||||
StrNCpy(port->database, si->user, sizeof(port->database) - 1);
|
||||
|
||||
/* Check we can handle the protocol the frontend is using. */
|
||||
|
||||
port->proto = ntohl(si->protoVersion);
|
||||
|
||||
if (PG_PROTOCOL_MAJOR(port->proto) < PG_PROTOCOL_MAJOR(PG_PROTOCOL_EARLIEST) ||
|
||||
PG_PROTOCOL_MAJOR(port->proto) > PG_PROTOCOL_MAJOR(PG_PROTOCOL_LATEST) ||
|
||||
(PG_PROTOCOL_MAJOR(port->proto) == PG_PROTOCOL_MAJOR(PG_PROTOCOL_LATEST) &&
|
||||
PG_PROTOCOL_MINOR(port->proto) > PG_PROTOCOL_MINOR(PG_PROTOCOL_LATEST)))
|
||||
PG_PROTOCOL_MAJOR(port->proto) > PG_PROTOCOL_MAJOR(PG_PROTOCOL_LATEST) ||
|
||||
(PG_PROTOCOL_MAJOR(port->proto) == PG_PROTOCOL_MAJOR(PG_PROTOCOL_LATEST) &&
|
||||
PG_PROTOCOL_MINOR(port->proto) > PG_PROTOCOL_MINOR(PG_PROTOCOL_LATEST)))
|
||||
{
|
||||
PacketSendError(&port->pktInfo, "Unsupported frontend protocol.");
|
||||
return;
|
||||
@@ -757,7 +766,7 @@ static void readStartupPacket(char *arg, PacketLen len, char *pkt)
|
||||
if (port->user[0] == '\0')
|
||||
{
|
||||
PacketSendError(&port->pktInfo,
|
||||
"No Postgres username specified in startup packet.");
|
||||
"No Postgres username specified in startup packet.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -805,11 +814,12 @@ ConnCreate(int serverFd)
|
||||
static void
|
||||
reset_shared(short port)
|
||||
{
|
||||
ipc_key = port * 1000 + shmem_seq * 100;
|
||||
CreateSharedMemoryAndSemaphores(ipc_key);
|
||||
ActiveBackends = FALSE;
|
||||
shmem_seq += 1;
|
||||
if (shmem_seq >= 10) shmem_seq -= 10;
|
||||
ipc_key = port * 1000 + shmem_seq * 100;
|
||||
CreateSharedMemoryAndSemaphores(ipc_key);
|
||||
ActiveBackends = FALSE;
|
||||
shmem_seq += 1;
|
||||
if (shmem_seq >= 10)
|
||||
shmem_seq -= 10;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -981,14 +991,15 @@ BackendStartup(Port *port)
|
||||
|
||||
#ifdef CYR_RECODE
|
||||
#define NR_ENVIRONMENT_VBL 6
|
||||
char ChTable[80];
|
||||
char ChTable[80];
|
||||
|
||||
#else
|
||||
#define NR_ENVIRONMENT_VBL 5
|
||||
#endif
|
||||
|
||||
static char envEntry[NR_ENVIRONMENT_VBL][2 * ARGV_SIZE];
|
||||
static char envEntry[NR_ENVIRONMENT_VBL][2 * ARGV_SIZE];
|
||||
|
||||
for (i = 0; i < NR_ENVIRONMENT_VBL; ++i)
|
||||
for (i = 0; i < NR_ENVIRONMENT_VBL; ++i)
|
||||
{
|
||||
MemSet(envEntry[i], 0, 2 * ARGV_SIZE);
|
||||
}
|
||||
@@ -1012,11 +1023,11 @@ char ChTable[80];
|
||||
putenv(envEntry[4]);
|
||||
|
||||
#ifdef CYR_RECODE
|
||||
GetCharSetByHost(ChTable,port->raddr.in.sin_addr.s_addr,DataDir);
|
||||
if(*ChTable != '\0')
|
||||
GetCharSetByHost(ChTable, port->raddr.in.sin_addr.s_addr, DataDir);
|
||||
if (*ChTable != '\0')
|
||||
{
|
||||
sprintf(envEntry[5], "PG_RECODETABLE=%s", ChTable);
|
||||
putenv(envEntry[5]);
|
||||
sprintf(envEntry[5], "PG_RECODETABLE=%s", ChTable);
|
||||
putenv(envEntry[5]);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1238,39 +1249,42 @@ dumpstatus(SIGNAL_ARGS)
|
||||
* CharRemap
|
||||
*/
|
||||
static char
|
||||
CharRemap(long int ch) {
|
||||
CharRemap(long int ch)
|
||||
{
|
||||
|
||||
if (ch < 0)
|
||||
ch = -ch;
|
||||
if (ch < 0)
|
||||
ch = -ch;
|
||||
|
||||
ch = ch % 62;
|
||||
if (ch < 26)
|
||||
return ('A' + ch);
|
||||
ch = ch % 62;
|
||||
if (ch < 26)
|
||||
return ('A' + ch);
|
||||
|
||||
ch -= 26;
|
||||
if (ch < 26)
|
||||
return ('a' + ch);
|
||||
ch -= 26;
|
||||
if (ch < 26)
|
||||
return ('a' + ch);
|
||||
|
||||
ch -= 26;
|
||||
return ('0' + ch);
|
||||
ch -= 26;
|
||||
return ('0' + ch);
|
||||
}
|
||||
|
||||
/*
|
||||
* RandomSalt
|
||||
*/
|
||||
static void
|
||||
RandomSalt(char* salt) {
|
||||
RandomSalt(char *salt)
|
||||
{
|
||||
|
||||
static bool initialized = false;
|
||||
static bool initialized = false;
|
||||
|
||||
if (!initialized) {
|
||||
time_t now;
|
||||
if (!initialized)
|
||||
{
|
||||
time_t now;
|
||||
|
||||
now = time(NULL);
|
||||
srandom((unsigned int)now);
|
||||
initialized = true;
|
||||
}
|
||||
now = time(NULL);
|
||||
srandom((unsigned int) now);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
*salt = CharRemap(random());
|
||||
*(salt + 1) = CharRemap(random());
|
||||
*salt = CharRemap(random());
|
||||
*(salt + 1) = CharRemap(random());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user