diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c index bde90bf60b..44f555b8e7 100644 --- a/src/bin/pg_rewind/pg_rewind.c +++ b/src/bin/pg_rewind/pg_rewind.c @@ -1104,7 +1104,7 @@ getRestoreCommand(const char *argv0) /* add -C switch, for restore_command */ appendPQExpBufferStr(postgres_cmd, " -C restore_command"); - restore_command = pipe_read_line(postgres_cmd->data); + restore_command = pipe_read_line(postgres_cmd->data, false); if (restore_command == NULL) pg_fatal("unable to read restore_command from target cluster"); diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c index 3552cf00af..2cd76f9f99 100644 --- a/src/bin/pg_upgrade/exec.c +++ b/src/bin/pg_upgrade/exec.c @@ -442,7 +442,7 @@ check_exec(const char *dir, const char *program, bool check_version) snprintf(cmd, sizeof(cmd), "\"%s\" -V", path); - if ((line = pipe_read_line(cmd)) == NULL) + if ((line = pipe_read_line(cmd, false)) == NULL) pg_fatal("check for \"%s\" failed: cannot execute", path); diff --git a/src/common/exec.c b/src/common/exec.c index da929f15b9..2f4d4264c7 100644 --- a/src/common/exec.c +++ b/src/common/exec.c @@ -348,7 +348,7 @@ find_other_exec(const char *argv0, const char *target, snprintf(cmd, sizeof(cmd), "\"%s\" -V", retpath); - if ((line = pipe_read_line(cmd)) == NULL) + if ((line = pipe_read_line(cmd, false)) == NULL) return -1; if (strcmp(line, versionstr) != 0) @@ -368,7 +368,7 @@ find_other_exec(const char *argv0, const char *target, * for freeing. */ char * -pipe_read_line(char *cmd) +pipe_read_line(char *cmd, bool empty_ok) { FILE *pipe_cmd; char *line; @@ -391,9 +391,9 @@ pipe_read_line(char *cmd) if (ferror(pipe_cmd)) log_error(errcode_for_file_access(), _("could not read from command \"%s\": %m"), cmd); - else - log_error(errcode_for_file_access(), - _("no data was returned by command \"%s\": %m"), cmd); + if (!empty_ok) + log_error(errcode(ERRCODE_NO_DATA), + _("no data was returned by command \"%s\""), cmd); } (void) pclose_check(pipe_cmd); diff --git a/src/include/port.h b/src/include/port.h index ae115d2d97..20f150b3a5 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -137,7 +137,7 @@ extern int validate_exec(const char *path); extern int find_my_exec(const char *argv0, char *retpath); extern int find_other_exec(const char *argv0, const char *target, const char *versionstr, char *retpath); -extern char *pipe_read_line(char *cmd); +extern char *pipe_read_line(char *cmd, bool empty_ok); /* Doesn't belong here, but this is used with find_other_exec(), so... */ #define PG_BACKEND_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"