Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0e5b4f0

Browse files
committed
Only use the pipe chunking protocol if we know the syslogger should
be catching stderr output, and we are not ourselves the syslogger. Otherwise, go directly to stderr. Bug noticed by Tom Lane. Backpatch as far as 8.0.
1 parent 177be3f commit 0e5b4f0

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/backend/postmaster/postmaster.c

+10-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.532 2007/07/11 08:27:33 mha Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.533 2007/07/19 19:13:43 adunstan Exp $
4141
*
4242
* NOTES
4343
*
@@ -203,8 +203,8 @@ static pid_t StartupPID = 0,
203203
BgWriterPID = 0,
204204
AutoVacPID = 0,
205205
PgArchPID = 0,
206-
PgStatPID = 0;
207-
pid_t SysLoggerPID = 0; /* Needs to be accessed from elog.c */
206+
PgStatPID = 0,
207+
SysLoggerPID = 0;
208208

209209
/* Startup/shutdown state */
210210
#define NoShutdown 0
@@ -218,6 +218,8 @@ static bool FatalError = false; /* T if recovering from backend crash */
218218
bool ClientAuthInProgress = false; /* T during new-client
219219
* authentication */
220220

221+
bool redirection_done = false;
222+
221223
/* received START_AUTOVAC_LAUNCHER signal */
222224
static bool start_autovac_launcher = false;
223225

@@ -332,6 +334,7 @@ typedef struct
332334
InheritableSocket pgStatSock;
333335
pid_t PostmasterPid;
334336
TimestampTz PgStartTime;
337+
bool redirection_done;
335338
#ifdef WIN32
336339
HANDLE PostmasterHandle;
337340
HANDLE initial_signal_pipe;
@@ -3953,6 +3956,8 @@ save_backend_variables(BackendParameters * param, Port *port,
39533956
param->PostmasterPid = PostmasterPid;
39543957
param->PgStartTime = PgStartTime;
39553958

3959+
param->redirection_done = redirection_done;
3960+
39563961
#ifdef WIN32
39573962
param->PostmasterHandle = PostmasterHandle;
39583963
write_duplicated_handle(&param->initial_signal_pipe,
@@ -4156,6 +4161,8 @@ restore_backend_variables(BackendParameters * param, Port *port)
41564161
PostmasterPid = param->PostmasterPid;
41574162
PgStartTime = param->PgStartTime;
41584163

4164+
redirection_done = param->redirection_done;
4165+
41594166
#ifdef WIN32
41604167
PostmasterHandle = param->PostmasterHandle;
41614168
pgwin32_initial_signal_pipe = param->initial_signal_pipe;

src/backend/postmaster/syslogger.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
*
2020
* IDENTIFICATION
21-
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.32 2007/06/14 01:48:51 adunstan Exp $
21+
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.33 2007/07/19 19:13:43 adunstan Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -79,11 +79,12 @@ bool Log_truncate_on_rotation = false;
7979
*/
8080
bool am_syslogger = false;
8181

82+
extern bool redirection_done;
83+
8284
/*
8385
* Private state
8486
*/
8587
static pg_time_t next_rotation_time;
86-
static bool redirection_done = false;
8788
static bool pipe_eof_seen = false;
8889
static FILE *syslogFile = NULL;
8990
static char *last_file_name = NULL;
@@ -582,14 +583,12 @@ syslogger_forkexec(void)
582583
snprintf(numbuf[bufc++], 32, "%d", fileno(syslogFile));
583584
else
584585
strcpy(numbuf[bufc++], "-1");
585-
snprintf(numbuf[bufc++], 32, "%d", (int) redirection_done);
586586
#else /* WIN32 */
587587
if (syslogFile != NULL)
588588
snprintf(numbuf[bufc++], 32, "%ld",
589589
_get_osfhandle(_fileno(syslogFile)));
590590
else
591591
strcpy(numbuf[bufc++], "0");
592-
snprintf(numbuf[bufc++], 32, "%d", (int) redirection_done);
593592
#endif /* WIN32 */
594593

595594
/* Add to the arg list */
@@ -623,7 +622,6 @@ syslogger_parseArgs(int argc, char *argv[])
623622
syslogFile = fdopen(fd, "a");
624623
setvbuf(syslogFile, NULL, LBF_MODE, 0);
625624
}
626-
redirection_done = (bool) atoi(*argv++);
627625
#else /* WIN32 */
628626
fd = atoi(*argv++);
629627
if (fd != 0)
@@ -635,7 +633,6 @@ syslogger_parseArgs(int argc, char *argv[])
635633
setvbuf(syslogFile, NULL, LBF_MODE, 0);
636634
}
637635
}
638-
redirection_done = (bool) atoi(*argv++);
639636
#endif /* WIN32 */
640637
}
641638
#endif /* EXEC_BACKEND */

src/backend/utils/error/elog.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*
4343
*
4444
* IDENTIFICATION
45-
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.187 2007/06/14 01:48:51 adunstan Exp $
45+
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.188 2007/07/19 19:13:43 adunstan Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -76,7 +76,7 @@ ErrorContextCallback *error_context_stack = NULL;
7676

7777
sigjmp_buf *PG_exception_stack = NULL;
7878

79-
extern pid_t SysLoggerPID;
79+
extern bool redirection_done;
8080

8181
/* GUC parameters */
8282
PGErrorVerbosity Log_error_verbosity = PGERROR_VERBOSE;
@@ -1780,11 +1780,15 @@ send_message_to_server_log(ErrorData *edata)
17801780
* that's really a pipe to the syslogger process. Unless we're in the
17811781
* postmaster, and the syslogger process isn't started yet.
17821782
*/
1783-
if ((!Redirect_stderr || am_syslogger || (!IsUnderPostmaster && SysLoggerPID==0)) && pgwin32_is_service())
1783+
if (pgwin32_is_service() && (!redirection_done || am_syslogger) )
17841784
write_eventlog(edata->elevel, buf.data);
17851785
else
17861786
#endif
1787-
if (Redirect_stderr)
1787+
/* only use the chunking protocol if we know the syslogger should
1788+
* be catching stderr output, and we are not ourselves the
1789+
* syslogger. Otherwise, go directly to stderr.
1790+
*/
1791+
if (redirection_done && !am_syslogger)
17881792
write_pipe_chunks(fileno(stderr), buf.data, buf.len);
17891793
else
17901794
write(fileno(stderr), buf.data, buf.len);

0 commit comments

Comments
 (0)