postgres.git / summary / log / commit / refs
commit 19c9660ca8e87cee53d80dc4e2c19b4530c44264
Author: Andrew Dunstan <andrew@dunslane.net>
Date: Thu Jul 19 19:15:25 2007 +0000
First released in: 8.3.0, 8.0.14, 8.1.10, 8.2.5
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.
src/backend/postmaster/postmaster.c | 8 +++++++-
src/backend/postmaster/syslogger.c | 9 +++------
src/backend/utils/error/elog.c | 8 +++++---
3 files changed, 15 insertions(+), 10 deletions(-)
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 69a2b5bbcf7..afe953cd6d4 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.443.4.8 2006/07/16 18:17:35 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.443.4.9 2007/07/19 19:15:25 adunstan Exp $
*
* NOTES
*
@@ -221,6 +221,7 @@ static bool FatalError = false; /* T if recovering from backend crash */
bool ClientAuthInProgress = false; /* T during new-client
* authentication */
+bool redirection_done = false;
/*
* State for assigning random salts and cancel keys.
@@ -330,6 +331,7 @@ typedef struct
InheritableSocket pgStatPipe0;
InheritableSocket pgStatPipe1;
pid_t PostmasterPid;
+ bool redirection_done;
#ifdef WIN32
HANDLE PostmasterHandle;
HANDLE initial_signal_pipe;
@@ -3718,6 +3720,8 @@ save_backend_variables(BackendParameters *param, Port *port,
param->PostmasterPid = PostmasterPid;
+ param->redirection_done = redirection_done;
+
#ifdef WIN32
param->PostmasterHandle = PostmasterHandle;
write_duplicated_handle(¶m->initial_signal_pipe,
@@ -3920,6 +3924,8 @@ restore_backend_variables(BackendParameters *param, Port *port)
PostmasterPid = param->PostmasterPid;
+ redirection_done = param->redirection_done;
+
#ifdef WIN32
PostmasterHandle = param->PostmasterHandle;
pgwin32_initial_signal_pipe = param->initial_signal_pipe;
diff --git a/src/backend/postmaster/syslogger.c b/src/backend/postmaster/syslogger.c
index db11beae9e2..342becb7dae 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -18,7 +18,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.12.4.2 2007/06/14 01:50:34 adunstan Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.12.4.3 2007/07/19 19:15:25 adunstan Exp $
*
*-------------------------------------------------------------------------
*/
@@ -78,11 +78,12 @@ bool Log_truncate_on_rotation = false;
*/
bool am_syslogger = false;
+extern bool redirection_done;
+
/*
* Private state
*/
static pg_time_t next_rotation_time;
-static bool redirection_done = false;
static bool pipe_eof_seen = false;
static FILE *syslogFile = NULL;
static char *last_file_name = NULL;
@@ -600,14 +601,12 @@ syslogger_forkexec(void)
snprintf(numbuf[bufc++], 32, "%d", fileno(syslogFile));
else
strcpy(numbuf[bufc++], "-1");
- snprintf(numbuf[bufc++], 32, "%d", (int) redirection_done);
#else /* WIN32 */
if (syslogFile != NULL)
snprintf(numbuf[bufc++], 32, "%ld",
_get_osfhandle(_fileno(syslogFile)));
else
strcpy(numbuf[bufc++], "0");
- snprintf(numbuf[bufc++], 32, "%d", (int) redirection_done);
#endif /* WIN32 */
/* Add to the arg list */
@@ -641,7 +640,6 @@ syslogger_parseArgs(int argc, char *argv[])
syslogFile = fdopen(fd, "a");
setvbuf(syslogFile, NULL, LBF_MODE, 0);
}
- redirection_done = (bool) atoi(*argv++);
#else /* WIN32 */
fd = atoi(*argv++);
if (fd != 0)
@@ -653,7 +651,6 @@ syslogger_parseArgs(int argc, char *argv[])
setvbuf(syslogFile, NULL, LBF_MODE, 0);
}
}
- redirection_done = (bool) atoi(*argv++);
#endif /* WIN32 */
}
#endif /* EXEC_BACKEND */
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index 0d019167773..61039b66d8b 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -42,7 +42,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.155.4.5 2007/06/14 01:50:34 adunstan Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.155.4.6 2007/07/19 19:15:25 adunstan Exp $
*
*-------------------------------------------------------------------------
*/
@@ -75,6 +75,8 @@ ErrorContextCallback *error_context_stack = NULL;
sigjmp_buf *PG_exception_stack = NULL;
+extern bool redirection_done;
+
/* GUC parameters */
PGErrorVerbosity Log_error_verbosity = PGERROR_VERBOSE;
char *Log_line_prefix = NULL; /* format for extra log line info */
@@ -1670,11 +1672,11 @@ send_message_to_server_log(ErrorData *edata)
* If stderr redirection is active, it's ok to write to stderr
* because that's really a pipe to the syslogger process.
*/
- if ((!Redirect_stderr || am_syslogger) && pgwin32_is_service())
+ if (pgwin32_is_service() && (!redirection_done || am_syslogger) )
write_eventlog(edata->elevel, buf.data);
else
#endif
- if (Redirect_stderr)
+ if (redirection_done && !am_syslogger)
write_pipe_chunks(fileno(stderr), buf.data, buf.len);
else
write(fileno(stderr), buf.data, buf.len);
[parent: a41c4b218fc7]