|
18 | 18 | * |
19 | 19 | * |
20 | 20 | * IDENTIFICATION |
21 | | - * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.33 2007/07/19 19:13:43 adunstan Exp $ |
| 21 | + * $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.34 2007/08/02 23:15:27 adunstan Exp $ |
22 | 22 | * |
23 | 23 | *------------------------------------------------------------------------- |
24 | 24 | */ |
@@ -194,6 +194,15 @@ SysLoggerMain(int argc, char *argv[]) |
194 | 194 | close(fd); |
195 | 195 | } |
196 | 196 |
|
| 197 | +/* Syslogger's own stderr can't be the syslogPipe, so set it back to |
| 198 | + * text mode if we didn't just close it. |
| 199 | + * (It was set to binary in SubPostmasterMain). |
| 200 | + */ |
| 201 | +#ifdefWIN32 |
| 202 | +else |
| 203 | +_setmode(_fileno(stderr),_O_TEXT); |
| 204 | +#endif |
| 205 | + |
197 | 206 | /* |
198 | 207 | * Also close our copy of the write end of the pipe. This is needed to |
199 | 208 | * ensure we can detect pipe EOF correctly. (But note that in the restart |
@@ -531,14 +540,20 @@ SysLogger_Start(void) |
531 | 540 | #else |
532 | 541 | intfd; |
533 | 542 |
|
| 543 | +/* |
| 544 | + * open the pipe in binary mode and make sure |
| 545 | + * stderr is binary after it's been dup'ed into, to avoid |
| 546 | + * disturbing the pipe chunking protocol. |
| 547 | + */ |
534 | 548 | fflush(stderr); |
535 | 549 | fd=_open_osfhandle((long)syslogPipe[1], |
536 | | -_O_APPEND |_O_TEXT); |
| 550 | +_O_APPEND |_O_BINARY); |
537 | 551 | if (dup2(fd,_fileno(stderr))<0) |
538 | 552 | ereport(FATAL, |
539 | 553 | (errcode_for_file_access(), |
540 | 554 | errmsg("could not redirect stderr: %m"))); |
541 | 555 | close(fd); |
| 556 | +_setmode(_fileno(stderr),_O_BINARY); |
542 | 557 | /* Now we are done with the write end of the pipe. */ |
543 | 558 | CloseHandle(syslogPipe[1]); |
544 | 559 | syslogPipe[1]=0; |
@@ -626,7 +641,7 @@ syslogger_parseArgs(int argc, char *argv[]) |
626 | 641 | fd=atoi(*argv++); |
627 | 642 | if (fd!=0) |
628 | 643 | { |
629 | | -fd=_open_osfhandle(fd,_O_APPEND); |
| 644 | +fd=_open_osfhandle(fd,_O_APPEND |_O_TEXT); |
630 | 645 | if (fd>0) |
631 | 646 | { |
632 | 647 | syslogFile=fdopen(fd,"a"); |
@@ -988,6 +1003,10 @@ logfile_rotate(bool time_based_rotation) |
988 | 1003 |
|
989 | 1004 | setvbuf(fh,NULL,LBF_MODE,0); |
990 | 1005 |
|
| 1006 | +#ifdefWIN32 |
| 1007 | +_setmode(_fileno(fh),_O_TEXT);/* use CRLF line endings on Windows */ |
| 1008 | +#endif |
| 1009 | + |
991 | 1010 | /* On Windows, need to interlock against data-transfer thread */ |
992 | 1011 | #ifdefWIN32 |
993 | 1012 | EnterCriticalSection(&sysfileSection); |
|