Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit75c93c0

Browse files
committed
Rearrange LOG_CONNECTIONS code so that two log messages are made:
one immediately upon forking to handle a new connection, and one afterthe authentication cycle is finished. Per today's pggeneral discussion.
1 parent36a1e73 commit75c93c0

File tree

1 file changed

+54
-39
lines changed

1 file changed

+54
-39
lines changed

‎src/backend/postmaster/postmaster.c

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.274 2002/05/17 01:19:17 tgl Exp $
40+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.275 2002/05/28 23:56:51 tgl Exp $
4141
*
4242
* NOTES
4343
*
@@ -1065,10 +1065,13 @@ ProcessStartupPacket(Port *port, bool SSLdone)
10651065
len=ntohl(len);
10661066
len-=4;
10671067

1068-
if (len<sizeof(len)||len>sizeof(len)+sizeof(StartupPacket))
1068+
if (len<sizeof(ProtocolVersion)||len>sizeof(StartupPacket))
10691069
elog(FATAL,"invalid length of startup packet");
10701070

1071-
buf=palloc(len);
1071+
buf=palloc(sizeof(StartupPacket));
1072+
1073+
/* Ensure we see zeroes for any bytes not sent */
1074+
MemSet(buf,0,sizeof(StartupPacket));
10721075

10731076
if (pq_getbytes(buf,len)==EOF)
10741077
{
@@ -1141,7 +1144,7 @@ ProcessStartupPacket(Port *port, bool SSLdone)
11411144
/*
11421145
* Get the parameters from the startup packet as C strings. The
11431146
* packet destination was cleared first so a short packet has zeros
1144-
* silently added and a long packet is silently truncated.
1147+
* silently added.
11451148
*/
11461149
StrNCpy(port->database,packet->database,sizeof(port->database));
11471150
StrNCpy(port->user,packet->user,sizeof(port->user));
@@ -1188,7 +1191,7 @@ ProcessStartupPacket(Port *port, bool SSLdone)
11881191
break;
11891192
caseCAC_OK:
11901193
default:
1191-
;
1194+
break;
11921195
}
11931196

11941197
returnSTATUS_OK;
@@ -2036,42 +2039,15 @@ DoBackend(Port *port)
20362039
* We arrange for a simple exit(0) if we receive SIGTERM or SIGQUIT
20372040
* during any client authentication related communication. Otherwise
20382041
* the postmaster cannot shutdown the database FAST or IMMED cleanly
2039-
* if a buggy client blocks a backend during authentication. We also
2040-
* will exit(0) after a time delay, so that a broken client can't hog
2041-
* a connection indefinitely.
2042-
*
2043-
* PreAuthDelay is a debugging aid for investigating problems in the
2044-
* authentication cycle: it can be set in postgresql.conf to allow
2045-
* time to attach to the newly-forked backend with a debugger. (See
2046-
* also the -W backend switch, which we allow clients to pass through
2047-
* PGOPTIONS, but it is not honored until after authentication.)
2042+
* if a buggy client blocks a backend during authentication.
20482043
*/
20492044
pqsignal(SIGTERM,authdie);
20502045
pqsignal(SIGQUIT,authdie);
20512046
pqsignal(SIGALRM,authdie);
20522047
PG_SETMASK(&AuthBlockSig);
20532048

2054-
if (PreAuthDelay>0)
2055-
sleep(PreAuthDelay);
2056-
2057-
if (!enable_sigalrm_interrupt(AuthenticationTimeout*1000))
2058-
elog(FATAL,"DoBackend: Unable to set timer for auth timeout");
2059-
20602049
/*
2061-
* Receive the startup packet (which might turn out to be a cancel
2062-
* request packet).
2063-
*/
2064-
status=ProcessStartupPacket(port, false);
2065-
2066-
if (status!=STATUS_OK)
2067-
return0;/* cancel request processed, or error */
2068-
2069-
/*
2070-
* Now that we have the user and database name, we can set the process
2071-
* title for ps. It's good to do this as early as possible in
2072-
* startup.
2073-
*
2074-
* But first, we need the remote host name.
2050+
* Get the remote host name and port for logging and status display.
20752051
*/
20762052
if (port->raddr.sa.sa_family==AF_INET)
20772053
{
@@ -2101,11 +2077,17 @@ DoBackend(Port *port)
21012077
if (remote_host==NULL)
21022078
remote_host=pstrdup(host_addr);
21032079

2080+
if (Log_connections)
2081+
elog(LOG,"connection received: host=%s port=%hu",
2082+
remote_host,remote_port);
2083+
21042084
if (ShowPortNumber)
21052085
{
2106-
char*str=palloc(strlen(remote_host)+7);
2086+
/* modify remote_host for use in ps status */
2087+
intslen=strlen(remote_host)+10;
2088+
char*str=palloc(slen);
21072089

2108-
sprintf(str,"%s:%hu",remote_host,remote_port);
2090+
snprintf(str,slen,"%s:%hu",remote_host,remote_port);
21092091
pfree(remote_host);
21102092
remote_host=str;
21112093
}
@@ -2114,10 +2096,43 @@ DoBackend(Port *port)
21142096
{
21152097
/* not AF_INET */
21162098
remote_host="[local]";
2099+
2100+
if (Log_connections)
2101+
elog(LOG,"connection received: host=%s",
2102+
remote_host);
21172103
}
21182104

21192105
/*
2120-
* Set process parameters for ps display.
2106+
* PreAuthDelay is a debugging aid for investigating problems in the
2107+
* authentication cycle: it can be set in postgresql.conf to allow
2108+
* time to attach to the newly-forked backend with a debugger. (See
2109+
* also the -W backend switch, which we allow clients to pass through
2110+
* PGOPTIONS, but it is not honored until after authentication.)
2111+
*/
2112+
if (PreAuthDelay>0)
2113+
sleep(PreAuthDelay);
2114+
2115+
/*
2116+
* Ready to begin client interaction. We will give up and exit(0)
2117+
* after a time delay, so that a broken client can't hog a connection
2118+
* indefinitely. PreAuthDelay doesn't count against the time limit.
2119+
*/
2120+
if (!enable_sigalrm_interrupt(AuthenticationTimeout*1000))
2121+
elog(FATAL,"DoBackend: Unable to set timer for auth timeout");
2122+
2123+
/*
2124+
* Receive the startup packet (which might turn out to be a cancel
2125+
* request packet).
2126+
*/
2127+
status=ProcessStartupPacket(port, false);
2128+
2129+
if (status!=STATUS_OK)
2130+
return0;/* cancel request processed, or error */
2131+
2132+
/*
2133+
* Now that we have the user and database name, we can set the process
2134+
* title for ps. It's good to do this as early as possible in
2135+
* startup.
21212136
*/
21222137
init_ps_display(port->user,port->database,remote_host);
21232138
set_ps_display("authentication");
@@ -2136,8 +2151,8 @@ DoBackend(Port *port)
21362151
PG_SETMASK(&BlockSig);
21372152

21382153
if (Log_connections)
2139-
elog(LOG,"connection: host=%s user=%s database=%s",
2140-
remote_host,port->user,port->database);
2154+
elog(LOG,"connection authorized: user=%s database=%s",
2155+
port->user,port->database);
21412156

21422157
/*
21432158
* Don't want backend to be able to see the postmaster random number

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp