summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2007-11-28 09:17:46 +0000
committerPeter Eisentraut2007-11-28 09:17:46 +0000
commit4ec2ee416b879e4e04dfbe780329d4b079c57e13 (patch)
tree625824194b607999541c6d07e5c09467396ff96d
parent7ab2b7c76594f17d8f6ce53a0a35ba71f9b51ae7 (diff)
Properly recognize and announce input errors.
-rw-r--r--src/bin/psql/input.c11
-rw-r--r--src/bin/psql/mainloop.c4
2 files changed, 13 insertions, 2 deletions
diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c
index 38cfc33307..2d53270ac2 100644
--- a/src/bin/psql/input.c
+++ b/src/bin/psql/input.c
@@ -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);
diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c
index 5697d37a1e..a69b068a2e 100644
--- a/src/bin/psql/mainloop.c
+++ b/src/bin/psql/mainloop.c
@@ -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