diff options
Diffstat (limited to 'src/backend/utils/error/elog.c')
-rw-r--r-- | src/backend/utils/error/elog.c | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 358bd982b34..0d019167773 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.4 2005/11/05 03:05:05 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.155.4.5 2007/06/14 01:50:34 adunstan Exp $ * *------------------------------------------------------------------------- */ @@ -119,7 +119,7 @@ static char *expand_fmt_string(const char *fmt, ErrorData *edata); static const char *useful_strerror(int errnum); static const char *error_severity(int elevel); static void append_with_tabs(StringInfo buf, const char *str); - +static void write_pipe_chunks(int fd, char *data, int len); /* * errstart --- begin an error-reporting cycle @@ -1674,7 +1674,10 @@ send_message_to_server_log(ErrorData *edata) write_eventlog(edata->elevel, buf.data); else #endif - fprintf(stderr, "%s", buf.data); + if (Redirect_stderr) + write_pipe_chunks(fileno(stderr), buf.data, buf.len); + else + write(fileno(stderr), buf.data, buf.len); } /* If in the syslogger process, try to write messages direct to file */ @@ -1684,6 +1687,37 @@ send_message_to_server_log(ErrorData *edata) pfree(buf.data); } +/* + * Send data to the syslogger using the chunked protocol + */ +static void +write_pipe_chunks(int fd, char *data, int len) +{ + PipeProtoChunk p; + + Assert(len > 0); + + p.proto.nuls[0] = p.proto.nuls[1] = '\0'; + p.proto.pid = MyProcPid; + + /* write all but the last chunk */ + while (len > PIPE_MAX_PAYLOAD) + { + p.proto.is_last = 'f'; + p.proto.len = PIPE_MAX_PAYLOAD; + memcpy(p.proto.data, data, PIPE_MAX_PAYLOAD); + write(fd, &p, PIPE_HEADER_SIZE + PIPE_MAX_PAYLOAD); + data += PIPE_MAX_PAYLOAD; + len -= PIPE_MAX_PAYLOAD; + } + + /* write the last chunk */ + p.proto.is_last = 't'; + p.proto.len = len; + memcpy(p.proto.data, data, len); + write(fd, &p, PIPE_HEADER_SIZE + len); +} + /* * Write error report to client @@ -2007,6 +2041,7 @@ write_stderr(const char *fmt,...) #ifndef WIN32 /* On Unix, we just fprintf to stderr */ vfprintf(stderr, fmt, ap); + fflush(stderr); #else /* @@ -2022,8 +2057,11 @@ write_stderr(const char *fmt,...) write_eventlog(EVENTLOG_ERROR_TYPE, errbuf); } else + { /* Not running as service, write to stderr */ vfprintf(stderr, fmt, ap); + fflush(stderr); + } #endif va_end(ap); } |