Re: Win32 testing needed

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
Cc: pgsql-hackers-win32(at)postgresql(dot)org, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Subject: Re: Win32 testing needed
Date: 2004-08-06 16:12:13
Message-ID: 18894.1091808733@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers-win32

Andreas Pflug <pgadmin(at)pse-consulting(dot)de> writes:
> Apparently, this is a mixture of binary and text file mode. Initially,
> stderr is in text mode. When redirecting with dup2, it will be binary;
> this must be corrected with

> dup2(_open_osfhandle(...., _O_APPEND | _O_TEXT), ...

Okay, I added _O_TEXT to that call; the #ifdef WIN32 part now looks like

fflush(stderr);
if (dup2(_open_osfhandle((long)syslogPipe[1],
_O_APPEND | _O_TEXT),
_fileno(stderr)) < 0)
ereport(FATAL,
(errcode_for_file_access(),
errmsg("could not redirect stderr: %m")));
/* Now we are done with the write end of the pipe. */
CloseHandle(syslogPipe[1]);
syslogPipe[1] = 0;

One question about this: isn't this coding leaking a file descriptor?
That is, shouldn't we catch the result of _open_osfhandle and do a
CloseHandle on it after the dup2 step?

BTW, is it correct to use 0 as "invalid handle"? Or should we be using
-1 or some such?

> Now, the pipe ReadFile will receive completely formatted data, which
> must be written binary (otherwise we will get CRCRLF), OTOH, the
> logger's calls to write_syslogger_file should write in text mode or
> replace \n by \r\n. Seems we need another function for elog to call.

Yeah. What do you think is the most convenient way to do that? I'd
be inclined to build a function that just expands \n to \r\n and then
calls write_syslogger_file, but maybe there's an easier way.

regards, tom lane

In response to

Responses

Browse pgsql-hackers-win32 by date

  From Date Subject
Next Message Tom Lane 2004-08-06 16:48:48 Re: Win32 testing needed
Previous Message Merlin Moncure 2004-08-06 15:57:05 Re: Point in Time recovery on Win32