Tom Lane wrote:
> 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?
Yes, it does.
int fd=_open_osfhandle(....); // additional fdes from winhandle
_dup2(fd, ...)
close(fd);
>
> BTW, is it correct to use 0 as "invalid handle"? Or should we be using
> -1 or some such?
0 is usually ok, valid handles are never 0. The official value is
INVALID_HANDLE_VALUE which expands to (HANDLE)-1.
>
>
>>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.
We could have *two* handles open to the syslogger file, but that's
probably more fragile. Making the current write_syslogger_file static
and providing another function that converts in a local buffer and
calles write_syslogger_file seems best.
Regards,
Andreas