Re: BUG #17288: PSQL bug with COPY command (Windows)

From: Dmitry Koval <d(dot)koval(at)postgrespro(dot)ru>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17288: PSQL bug with COPY command (Windows)
Date: 2021-11-18 13:23:54
Message-ID: 9e4efe29-0ff9-0808-fe32-d1d50e0be4fa@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

>_fstat64() and _stat64() have proved to be tricky to work with and
>rather unworkable across all the build systems we support

I agree, it is better not use them.

>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().

>Just to be sure, this is the code path in psql's copy.c where we check
>that a specified copystream is not a directory, right?

Yes, fstat() called from file src/bin/psql/copy.c:

/* make sure the specified file is not a directory */
if ((result = fstat(fileno(copystream), &st)) < 0)

I attached new patch version.

With best regards,
Dmitry Koval.

Attachment Content-Type Size
v3_0001-Fixed-Windows-stat-emulation-working-with-streams.patch text/plain 2.0 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Dmitry Koval 2021-11-18 13:27:24 Re: BUG #17288: PSQL bug with COPY command (Windows)
Previous Message Juan José Santamaría Flecha 2021-11-18 11:37:08 Re: BUG #17288: PSQL bug with COPY command (Windows)