Properly recognize and announce input errors.
authorPeter Eisentraut <peter_e@gmx.net>
Wed, 28 Nov 2007 09:17:46 +0000 (09:17 +0000)
committerPeter Eisentraut <peter_e@gmx.net>
Wed, 28 Nov 2007 09:17:46 +0000 (09:17 +0000)
src/bin/psql/input.c
src/bin/psql/mainloop.c

index 38cfc333078bbcfedfa0ded8cd515c1d12e72b57..2d53270ac2da2afc5ac09f3079fb7278b5b525de 100644 (file)
@@ -147,7 +147,7 @@ pg_send_history(PQExpBuffer history_buf)
  * gets_fromFile
  *
  * Gets a line of noninteractive input from a file (which could be stdin).
- * The result is a malloc'd string.
+ * The result is a malloc'd string, or NULL on EOF or input error.
  *
  * Caller *must* have set up sigint_interrupt_jmp before calling.
  *
@@ -179,9 +179,16 @@ gets_fromFile(FILE *source)
                /* 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);
 
index 5697d37a1eb0a547cea314c7ab1cb14f2e00708a..a69b068a2e3dc586e717991547e7a16b6f3fee00 100644 (file)
@@ -129,7 +129,11 @@ MainLoop(FILE *source)
                        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