pgsql: Make psql handle EOF during COPY FROM STDIN properly on all plat

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Make psql handle EOF during COPY FROM STDIN properly on all plat
Date: 2017-05-17 16:24:37
Message-ID: E1dB1kb-0007ST-HF@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Make psql handle EOF during COPY FROM STDIN properly on all platforms.

When stdin is a terminal, it's possible to end a COPY FROM STDIN with
a keyboard EOF signal (typically control-D), and then keep on issuing
SQL commands. One would expect another COPY FROM STDIN to work as well,
but on some platforms it did not. This turns out to be because we were
not resetting the stream's feof() flag, and BSD-ish versions of fread()
and fgets() won't attempt to read more data if that's set.

The misbehavior is observed on BSDen (including macOS), but not Linux,
Windows, or SysV-ish Unixen, which makes this a portability bug not
just a missing feature.

Add a clearerr() call to fix the behavior, and improve the prompt that's
issued when copying from a TTY to mention that EOF signals work.

It's been like this forever, so back-patch to all supported branches.

Thomas Munro

Discussion: https://postgr.es/m/CAEepm=0MCGfYf=JAMiYhO6JPtv9-3ZfBo8fcGeCZ8oMzaw+Z+Q@mail.gmail.com

Branch
------
REL9_4_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/ff0e30512276fa59985a6fa0e3afaa80aad40480

Modified Files
--------------
src/bin/psql/copy.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2017-05-17 16:25:01 pgsql: Add more tests for CREATE SUBSCRIPTION
Previous Message Robert Haas 2017-05-17 16:24:01 Re: pgsql: Tag refs/tags/REL_10_BETA1 was created