Re: BUG #17288: PSQL bug with COPY command (Windows) - Mailing list pgsql-bugs

From Juan José Santamaría Flecha
Subject Re: BUG #17288: PSQL bug with COPY command (Windows)
Date
Msg-id CAC+AXB3BKByL8O39qARu3XYMWmrNqMWhcHZZ_2ygqvrK-W6O1g@mail.gmail.com
Whole thread Raw
In response to Re: BUG #17288: PSQL bug with COPY command (Windows)  (Dmitry Koval <d.koval@postgrespro.ru>)
Responses Re: BUG #17288: PSQL bug with COPY command (Windows)
List pgsql-bugs

On Thu, Nov 18, 2021 at 2:40 PM Dmitry Koval <d.koval@postgrespro.ru> wrote:
 >I think that we had better never call GetFileInformationByHandle() if
 >we use a fileno that maps to stdin, stdout or stderr.

Probably we should call GetFileInformationByHandle() for case standard
streams stdin/stdout/stderr are redirected to files.
See file src\backend\utils\error\elog.c, for example. It contains
lines:

if (!freopen(OutputFileName, "a", stderr))
if (!freopen(OutputFileName, "a", stdout))

And this command with "stderr" works in PSQL without crash (in
contrast to "stdout"):

\copy (SELECT 1) TO stderr

(it put resullt into file with name "stderr").
We can emulate stats for stdin/stdout/stderr after call
GetFileInformationByHandle().

You are right about freopen(), but stderr works just because it's being parsed as a file, not a stream, by parse_slash_copy().
 
I attached new patch version.

I would keep the memset(buf, 0, sizeof(*buf)) for the members we are not setting.

Regards,

Juan José Santamaría Flecha

pgsql-bugs by date:

Previous
From: Дмитрий Иванов
Date:
Subject: Re: pg_restore depending on user functions
Next
From: Dmitry Koval
Date:
Subject: Re: BUG #17288: PSQL bug with COPY command (Windows)