Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 612f1b0

Browse files
committed
Check for SIGHUP and process config file updates just after waiting
for input, not just before.
1 parent 4cafef5 commit 612f1b0

File tree

2 files changed

+46
-47
lines changed

2 files changed

+46
-47
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.173 2000/10/21 15:43:26 vadim Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.174 2000/10/24 21:33:52 tgl Exp $
1515
*
1616
* NOTES
1717
*
@@ -803,32 +803,32 @@ ServerLoop(void)
803803
Port *port;
804804
fd_set rmask,
805805
wmask;
806-
807806
#ifdef USE_SSL
808-
int no_select = 0;
809-
807+
bool no_select = false;
810808
#endif
811809

812-
memmove((char *) &rmask, (char *) &readmask, sizeof(fd_set));
813-
memmove((char *) &wmask, (char *) &writemask, sizeof(fd_set));
810+
/*
811+
* Wait for something to happen.
812+
*/
813+
memcpy((char *) &rmask, (char *) &readmask, sizeof(fd_set));
814+
memcpy((char *) &wmask, (char *) &writemask, sizeof(fd_set));
814815

815816
#ifdef USE_SSL
816817
for (curr = DLGetHead(PortList); curr; curr = DLGetSucc(curr))
817818
{
818819
if (((Port *) DLE_VAL(curr))->ssl &&
819820
SSL_pending(((Port *) DLE_VAL(curr))->ssl) > 0)
820821
{
821-
no_select = 1;
822+
no_select = true;
822823
break;
823824
}
824825
}
825-
PG_SETMASK(&UnBlockSig);
826826
if (no_select)
827827
FD_ZERO(&rmask); /* So we don't accept() anything below */
828-
else
829-
#else
830-
PG_SETMASK(&UnBlockSig);
831828
#endif
829+
830+
PG_SETMASK(&UnBlockSig);
831+
832832
if (select(nSockets, &rmask, &wmask, (fd_set *) NULL,
833833
(struct timeval *) NULL) < 0)
834834
{
@@ -838,6 +838,21 @@ ServerLoop(void)
838838
progname, strerror(errno));
839839
return STATUS_ERROR;
840840
}
841+
842+
/*
843+
* Block all signals until we wait again
844+
*/
845+
PG_SETMASK(&BlockSig);
846+
847+
/*
848+
* Respond to signals, if needed
849+
*/
850+
if (got_SIGHUP)
851+
{
852+
got_SIGHUP = false;
853+
ProcessConfigFile(PGC_SIGHUP);
854+
}
855+
841856
/*
842857
* Select a random seed at the time of first receiving a request.
843858
*/
@@ -856,11 +871,8 @@ ServerLoop(void)
856871
}
857872

858873
/*
859-
* Block all signals
874+
* new connection pending on our well-known port's socket?
860875
*/
861-
PG_SETMASK(&BlockSig);
862-
863-
/* new connection pending on our well-known port's socket */
864876

865877
#ifdef HAVE_UNIX_SOCKETS
866878
if (ServerSock_UNIX != INVALID_SOCK &&
@@ -893,21 +905,12 @@ ServerLoop(void)
893905
Port *port = (Port *) DLE_VAL(curr);
894906
int status = STATUS_OK;
895907
Dlelem *next;
896-
int readyread = 0;
897908

909+
if (FD_ISSET(port->sock, &rmask)
898910
#ifdef USE_SSL
899-
if (port->ssl)
900-
{
901-
if (SSL_pending(port->ssl) ||
902-
FD_ISSET(port->sock, &rmask))
903-
readyread = 1;
904-
}
905-
else
911+
|| (port->ssl && SSL_pending(port->ssl))
906912
#endif
907-
if (FD_ISSET(port->sock, &rmask))
908-
readyread = 1;
909-
910-
if (readyread)
913+
)
911914
{
912915
if (DebugLvl > 1)
913916
fprintf(stderr, "%s: ServerLoop:\t\thandling reading %d\n",
@@ -997,13 +1000,7 @@ ServerLoop(void)
9971000
}
9981001

9991002
curr = next;
1000-
}
1001-
1002-
if (got_SIGHUP)
1003-
{
1004-
got_SIGHUP = false;
1005-
ProcessConfigFile(PGC_SIGHUP);
1006-
}
1003+
} /* loop over active ports */
10071004
}
10081005
}
10091006

@@ -1269,7 +1266,6 @@ reset_shared(int port)
12691266
static void
12701267
SIGHUP_handler(SIGNAL_ARGS)
12711268
{
1272-
got_SIGHUP = true;
12731269
if (Shutdown > SmartShutdown)
12741270
return;
12751271
got_SIGHUP = true;

src/backend/tcop/postgres.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.180 2000/10/07 14:39:14 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.181 2000/10/24 21:33:48 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -1618,7 +1618,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
16181618
if (!IsUnderPostmaster)
16191619
{
16201620
puts("\nPOSTGRES backend interactive interface ");
1621-
puts("$Revision: 1.180 $ $Date: 2000/10/07 14:39:14 $\n");
1621+
puts("$Revision: 1.181 $ $Date: 2000/10/24 21:33:48 $\n");
16221622
}
16231623

16241624
/*
@@ -1695,14 +1695,6 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
16951695

16961696
parser_input = makeStringInfo();
16971697

1698-
/* XXX this could be moved after ReadCommand below to get more
1699-
* sensical behaviour */
1700-
if (got_SIGHUP)
1701-
{
1702-
got_SIGHUP = false;
1703-
ProcessConfigFile(PGC_SIGHUP);
1704-
}
1705-
17061698
/* ----------------
17071699
* (1) tell the frontend we're ready for a new query.
17081700
*
@@ -1738,7 +1730,18 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
17381730
DisableNotifyInterrupt();
17391731

17401732
/* ----------------
1741-
* (5) process the command.
1733+
* (5) check for any other interesting events that happened
1734+
* while we slept.
1735+
* ----------------
1736+
*/
1737+
if (got_SIGHUP)
1738+
{
1739+
got_SIGHUP = false;
1740+
ProcessConfigFile(PGC_SIGHUP);
1741+
}
1742+
1743+
/* ----------------
1744+
* (6) process the command.
17421745
* ----------------
17431746
*/
17441747
switch (firstchar)
@@ -1766,7 +1769,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
17661769
* ----------------
17671770
*/
17681771
case 'Q':
1769-
if (strspn(parser_input->data, " \t\n") == parser_input->len)
1772+
if (strspn(parser_input->data, " \t\r\n") == parser_input->len)
17701773
{
17711774
/* ----------------
17721775
* if there is nothing in the input buffer, don't bother

0 commit comments

Comments
 (0)