Re: psql -1 -f - busted

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: psql -1 -f - busted
Дата
Msg-id 200911301359.nAUDxDj19992@momjian.us
обсуждение исходный текст
Ответ на Re: psql -1 -f - busted  (Robert Haas <robertmhaas@gmail.com>)
Ответы Re: psql -1 -f - busted  (Bruce Momjian <bruce@momjian.us>)
Список pgsql-bugs
Robert Haas wrote:
> On Fri, Nov 27, 2009 at 1:42 AM, Peter Eisentraut <peter_e@gmx.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@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
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]);

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Kenaniah Cerny
Дата:
Сообщение: Re: BUG #5219: Segfault in to_tsvector
Следующее
От: "jef peeraer"
Дата:
Сообщение: BUG #5220: regexp fails on punctuation characters