Am Donnerstag, 15. November 2007 schrieb Tom Lane:
> Peter Eisentraut <[EMAIL PROTECTED]> writes:
> > Am Donnerstag, 15. November 2007 schrieb Tom Lane:
> >> This seems too far removed from the scene of the crime
> >
> > Yeah, my zeroth attempt was to place this in gets_fromFile(), but there
> > you don't have any opportunity to report failure to the main loop.  We'd
> > need to change the function signature to be able to pass that around. 
> > Maybe that's better overall.
>
> Well, you could still handle that the same as in your patch: on NULL
> return, check ferror.  It's just that I don't trust errno to stay
> unchanged for very long.

This should do better:

diff -ur ../cvs-pgsql/src/bin/psql/input.c ./src/bin/psql/input.c
--- ../cvs-pgsql/src/bin/psql/input.c   2007-01-12 10:22:42.000000000 +0100
+++ ./src/bin/psql/input.c      2007-11-27 18:46:34.000000000 +0100
@@ -179,9 +179,16 @@
                /* Disable SIGINT again */
                sigint_interrupt_enabled = false;

-               /* EOF? */
+               /* EOF or error? */
                if (result == NULL)
+               {
+                       if (ferror(source))
+                       {
+                               psql_error("could not read from input file: 
%s\n", strerror(errno));
+                               return NULL;
+                       }
                        break;
+               }

                appendPQExpBufferStr(buffer, line);

diff -ur ../cvs-pgsql/src/bin/psql/mainloop.c ./src/bin/psql/mainloop.c
--- ../cvs-pgsql/src/bin/psql/mainloop.c        2007-01-12 10:22:42.000000000 
+0100
+++ ./src/bin/psql/mainloop.c   2007-11-27 18:30:13.000000000 +0100
@@ -129,7 +129,11 @@
                        line = gets_interactive(get_prompt(prompt_status));
                }
                else
+               {
                        line = gets_fromFile(source);
+                       if (!line && ferror(source))
+                               successResult = EXIT_FAILURE;
+               }

                /*
                 * query_buf holds query already accumulated.  line is the 
malloc'd

-- 
Peter Eisentraut
http://developer.postgresql.org/~petere/

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to [EMAIL PROTECTED] so that your
       message can get through to the mailing list cleanly

Reply via email to