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

From Dmitry Koval
Subject Re: BUG #17288: PSQL bug with COPY command (Windows)
Date
Msg-id 9e4efe29-0ff9-0808-fe32-d1d50e0be4fa@postgrespro.ru
Whole thread Raw
In response to Re: BUG #17288: PSQL bug with COPY command (Windows)  (Michael Paquier <michael@paquier.xyz>)
Responses Re: BUG #17288: PSQL bug with COPY command (Windows)
List 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

pgsql-bugs by date:

Previous
From: Juan José Santamaría Flecha
Date:
Subject: Re: BUG #17288: PSQL bug with COPY command (Windows)
Next
From: Dmitry Koval
Date:
Subject: Re: BUG #17288: PSQL bug with COPY command (Windows)