Re: psql -1 -f - busted

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Stephen Frost <sfrost(at)snowman(dot)net>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: psql -1 -f - busted
Date: 2009-12-01 22:34:40
Message-ID: 200912012234.nB1MYeD25454@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


Applied. Thanks for the report.

---------------------------------------------------------------------------

Bruce Momjian wrote:
> Robert Haas wrote:
> > On Fri, Nov 27, 2009 at 1:42 AM, Peter Eisentraut <peter_e(at)gmx(dot)net> wrote:
> > > On tor, 2009-11-26 at 22:59 -0500, Robert Haas wrote:
> > >> ISTM that if you run psql with "-f -", you shouldn't expect to get an
> > >> interactive shell. ?Rather, you should expect psql to do whatever it
> > >> normally does when given -f somefilename, except using stdin rather
> > >> than the file. ?After all, you could have left out -f altogether if
> > >> you'd wanted the interactive behavior. ?But then IJWH.
> > >
> > > But by that logic, psql < file should also set interactive mode.
> >
> > Those two cases are not symmetrical. If you're reading from something
> > other than a terminal, you certainly don't want interactive mode. If
> > you ARE reading from a terminal, you might nevertheless want
> > non-interactive mode. And you CERTAINLY might want -1 when reading a
> > pipe, as when you do this:
> >
> > ssh otherhost pg_dump | psql -1 -f -
> >
> > Currently, this silently fails to deliver the expected behavior.
>
> You are right --- there is definitely something wrong with that code. I
> tried to find out why it was coded that way but that code hasn't changed
> since 2000 or 2001. My guess is that is was OK then, but when we added
> "-1" we didn't think about its placement.
>
> I think the proper, consistent fix is to check for "-" inside
> process_file(), rather than earlier. The attached patch accomplishes
> this. The code still goes into interactive mode, though:
>
> $ psql -f - test
> test=>
>
> Should that prompt not appear? Seems OK to me.
>
> --
> Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
> EnterpriseDB http://enterprisedb.com
>
> + If your life is a hard drive, Christ can be your backup. +

[ text/x-diff is unsupported, treating like TEXT/PLAIN ]

> Index: src/bin/psql/command.c
> ===================================================================
> RCS file: /cvsroot/pgsql/src/bin/psql/command.c,v
> retrieving revision 1.211
> diff -c -c -r1.211 command.c
> *** src/bin/psql/command.c 22 Nov 2009 05:20:41 -0000 1.211
> --- src/bin/psql/command.c 30 Nov 2009 13:47:17 -0000
> ***************
> *** 1691,1698 ****
> if (!filename)
> return EXIT_FAILURE;
>
> ! canonicalize_path(filename);
> ! fd = fopen(filename, PG_BINARY_R);
>
> if (!fd)
> {
> --- 1691,1703 ----
> if (!filename)
> return EXIT_FAILURE;
>
> ! if (strcmp(filename, "-") != 0)
> ! {
> ! canonicalize_path(filename);
> ! fd = fopen(filename, PG_BINARY_R);
> ! }
> ! else
> ! fd = stdin;
>
> if (!fd)
> {
> Index: src/bin/psql/startup.c
> ===================================================================
> RCS file: /cvsroot/pgsql/src/bin/psql/startup.c,v
> retrieving revision 1.156
> diff -c -c -r1.156 startup.c
> *** src/bin/psql/startup.c 5 Apr 2009 04:19:58 -0000 1.156
> --- src/bin/psql/startup.c 30 Nov 2009 13:47:17 -0000
> ***************
> *** 225,231 ****
> /*
> * process file given by -f
> */
> ! if (options.action == ACT_FILE && strcmp(options.action_string, "-") != 0)
> {
> if (!options.no_psqlrc)
> process_psqlrc(argv[0]);
> --- 225,231 ----
> /*
> * process file given by -f
> */
> ! if (options.action == ACT_FILE)
> {
> if (!options.no_psqlrc)
> process_psqlrc(argv[0]);

>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Craig Ringer 2009-12-02 01:12:48 Re: BUG #5222: failed to run initdb: 1!
Previous Message Alvaro Herrera 2009-12-01 21:52:38 Re: BUG #5216: pgFouine 1.1 not working correctly, when LC_MESSAGES is "es_ES.UTF-8"