Re: BUG #17288: PSQL bug with COPY command (Windows)
Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
From: Juan José Santamaría Flecha <juanjo.santamaria@gmail.com>
To: Dmitry Koval <d.koval@postgrespro.ru>
Cc: Michael Paquier <michael@paquier.xyz>, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Date: 2021-11-18T18:13:53Z
Lists: 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
Commits
-
Fix compatibility thinko for fstat() on standard streams in win32stat.c
- 5550a9c38519 14.2 landed
- 58651d8dd6a5 15.0 landed
-
Fix fstat() emulation on Windows with standard streams
- d2198b4593cc 14.2 landed
- 10260c794b21 15.0 landed