aboutsummaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/initdb/initdb.c5
-rw-r--r--src/bin/pg_ctl/pg_ctl.c5
-rw-r--r--src/bin/pg_dump/pg_dumpall.c3
-rw-r--r--src/bin/pg_rewind/pg_rewind.c1
-rw-r--r--src/bin/pg_upgrade/controldata.c6
-rw-r--r--src/bin/pg_upgrade/exec.c7
-rw-r--r--src/bin/pg_upgrade/option.c1
-rw-r--r--src/bin/pg_verifybackup/pg_verifybackup.c1
-rw-r--r--src/bin/pgbench/pgbench.c2
-rw-r--r--src/bin/psql/command.c4
-rw-r--r--src/bin/psql/common.c1
-rw-r--r--src/bin/psql/copy.c8
-rw-r--r--src/bin/psql/prompt.c4
-rw-r--r--src/bin/psql/psqlscanslash.l1
14 files changed, 33 insertions, 16 deletions
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 29c28b73153..e00837ecacf 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -489,8 +489,7 @@ popen_check(const char *command, const char *mode)
{
FILE *cmdfd;
- fflush(stdout);
- fflush(stderr);
+ fflush(NULL);
errno = 0;
cmdfd = popen(command, mode);
if (cmdfd == NULL)
@@ -914,6 +913,7 @@ test_config_settings(void)
test_conns, test_buffs,
dynamic_shared_memory_type,
DEVNULL, DEVNULL);
+ fflush(NULL);
status = system(cmd);
if (status == 0)
{
@@ -950,6 +950,7 @@ test_config_settings(void)
n_connections, test_buffs,
dynamic_shared_memory_type,
DEVNULL, DEVNULL);
+ fflush(NULL);
status = system(cmd);
if (status == 0)
break;
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index 73e20081d1d..d7ff3902aa7 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -448,8 +448,7 @@ start_postmaster(void)
pgpid_t pm_pid;
/* Flush stdio channels just before fork, to avoid double-output problems */
- fflush(stdout);
- fflush(stderr);
+ fflush(NULL);
#ifdef EXEC_BACKEND
pg_disable_aslr();
@@ -916,6 +915,7 @@ do_init(void)
cmd = psprintf("\"%s\" %s%s > \"%s\"",
exec_path, pgdata_opt, post_opts, DEVNULL);
+ fflush(NULL);
if (system(cmd) != 0)
{
write_stderr(_("%s: database system initialization failed\n"), progname);
@@ -2222,6 +2222,7 @@ adjust_data_dir(void)
my_exec_path,
pgdata_opt ? pgdata_opt : "",
post_opts ? post_opts : "");
+ fflush(NULL);
fd = popen(cmd, "r");
if (fd == NULL || fgets(filename, sizeof(filename), fd) == NULL)
diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c
index 68c455f84b2..d665b257c93 100644
--- a/src/bin/pg_dump/pg_dumpall.c
+++ b/src/bin/pg_dump/pg_dumpall.c
@@ -1578,8 +1578,7 @@ runPgDump(const char *dbname, const char *create_opts)
pg_log_info("running \"%s\"", cmd->data);
- fflush(stdout);
- fflush(stderr);
+ fflush(NULL);
ret = system(cmd->data);
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index 1ff8da16764..3cd77c09b1a 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -1151,6 +1151,7 @@ ensureCleanShutdown(const char *argv0)
appendPQExpBufferStr(postgres_cmd, " template1 < ");
appendShellString(postgres_cmd, DEVNULL);
+ fflush(NULL);
if (system(postgres_cmd->data) != 0)
{
pg_log_error("postgres single-user mode in target cluster failed");
diff --git a/src/bin/pg_upgrade/controldata.c b/src/bin/pg_upgrade/controldata.c
index e2086a07dea..018cd310f7c 100644
--- a/src/bin/pg_upgrade/controldata.c
+++ b/src/bin/pg_upgrade/controldata.c
@@ -123,8 +123,7 @@ get_control_data(ClusterInfo *cluster, bool live_check)
/* only pg_controldata outputs the cluster state */
snprintf(cmd, sizeof(cmd), "\"%s/pg_controldata\" \"%s\"",
cluster->bindir, cluster->pgdata);
- fflush(stdout);
- fflush(stderr);
+ fflush(NULL);
if ((output = popen(cmd, "r")) == NULL)
pg_fatal("could not get control data using %s: %s",
@@ -191,8 +190,7 @@ get_control_data(ClusterInfo *cluster, bool live_check)
cluster->bindir,
live_check ? "pg_controldata\"" : resetwal_bin,
cluster->pgdata);
- fflush(stdout);
- fflush(stderr);
+ fflush(NULL);
if ((output = popen(cmd, "r")) == NULL)
pg_fatal("could not get control data using %s: %s",
diff --git a/src/bin/pg_upgrade/exec.c b/src/bin/pg_upgrade/exec.c
index aa3d2f88ed8..60f4b5443e6 100644
--- a/src/bin/pg_upgrade/exec.c
+++ b/src/bin/pg_upgrade/exec.c
@@ -39,6 +39,7 @@ get_bin_version(ClusterInfo *cluster)
v2 = 0;
snprintf(cmd, sizeof(cmd), "\"%s/pg_ctl\" --version", cluster->bindir);
+ fflush(NULL);
if ((output = popen(cmd, "r")) == NULL ||
fgets(cmd_output, sizeof(cmd_output), output) == NULL)
@@ -125,7 +126,10 @@ exec_prog(const char *log_filename, const char *opt_log_file,
* the file do not see to help.
*/
if (mainThreadId != GetCurrentThreadId())
+ {
+ fflush(NULL);
result = system(cmd);
+ }
#endif
log = fopen(log_file, "a");
@@ -174,7 +178,10 @@ exec_prog(const char *log_filename, const char *opt_log_file,
/* see comment above */
if (mainThreadId == GetCurrentThreadId())
#endif
+ {
+ fflush(NULL);
result = system(cmd);
+ }
if (result != 0 && report_error)
{
diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c
index fbab1c4fb72..3f719f1762c 100644
--- a/src/bin/pg_upgrade/option.c
+++ b/src/bin/pg_upgrade/option.c
@@ -416,6 +416,7 @@ adjust_data_dir(ClusterInfo *cluster)
*/
snprintf(cmd, sizeof(cmd), "\"%s/postgres\" -D \"%s\" -C data_directory",
cluster->bindir, cluster->pgconfig);
+ fflush(NULL);
if ((output = popen(cmd, "r")) == NULL ||
fgets(cmd_output, sizeof(cmd_output), output) == NULL)
diff --git a/src/bin/pg_verifybackup/pg_verifybackup.c b/src/bin/pg_verifybackup/pg_verifybackup.c
index bd18b4491d5..63d02719a61 100644
--- a/src/bin/pg_verifybackup/pg_verifybackup.c
+++ b/src/bin/pg_verifybackup/pg_verifybackup.c
@@ -811,6 +811,7 @@ parse_required_wal(verifier_context *context, char *pg_waldump_path,
pg_waldump_path, wal_directory, this_wal_range->tli,
LSN_FORMAT_ARGS(this_wal_range->start_lsn),
LSN_FORMAT_ARGS(this_wal_range->end_lsn));
+ fflush(NULL);
if (system(pg_waldump_cmd) != 0)
report_backup_error(context,
"WAL parsing failed for timeline %u",
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 07b7e0cf37c..9aadcaad71e 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -2973,6 +2973,8 @@ runShellCommand(Variables *variables, char *variable, char **argv, int argc)
command[len] = '\0';
+ fflush(NULL); /* needed before either system() or popen() */
+
/* Fast path for non-assignment case */
if (variable == NULL)
{
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index a81bd3307b4..61188d96f2a 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -2661,6 +2661,7 @@ exec_command_write(PsqlScanState scan_state, bool active_branch,
if (fname[0] == '|')
{
is_pipe = true;
+ fflush(NULL);
disable_sigpipe_trap();
fd = popen(&fname[1], "w");
}
@@ -3834,6 +3835,7 @@ editFile(const char *fname, int lineno)
sys = psprintf("\"%s\" \"%s\"",
editorName, fname);
#endif
+ fflush(NULL);
result = system(sys);
if (result == -1)
pg_log_error("could not start editor \"%s\"", editorName);
@@ -4956,6 +4958,7 @@ do_shell(const char *command)
{
int result;
+ fflush(NULL);
if (!command)
{
char *sys;
@@ -5065,6 +5068,7 @@ do_watch(PQExpBuffer query_buf, double sleep)
#endif
if (pagerprog && myopt.topt.pager)
{
+ fflush(NULL);
disable_sigpipe_trap();
pagerpipe = popen(pagerprog, "w");
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 9f95869eca6..e611e3266d0 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -59,6 +59,7 @@ openQueryOutputFile(const char *fname, FILE **fout, bool *is_pipe)
}
else if (*fname == '|')
{
+ fflush(NULL);
*fout = popen(fname + 1, "w");
*is_pipe = true;
}
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c
index c181682a132..0f66ebc2edf 100644
--- a/src/bin/psql/copy.c
+++ b/src/bin/psql/copy.c
@@ -288,8 +288,7 @@ do_copy(const char *args)
{
if (options->program)
{
- fflush(stdout);
- fflush(stderr);
+ fflush(NULL);
errno = 0;
copystream = popen(options->file, PG_BINARY_R);
}
@@ -307,10 +306,9 @@ do_copy(const char *args)
{
if (options->program)
{
- fflush(stdout);
- fflush(stderr);
- errno = 0;
+ fflush(NULL);
disable_sigpipe_trap();
+ errno = 0;
copystream = popen(options->file, PG_BINARY_W);
}
else
diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c
index 509e6422b7e..3955d72206c 100644
--- a/src/bin/psql/prompt.c
+++ b/src/bin/psql/prompt.c
@@ -266,8 +266,10 @@ get_prompt(promptStatus_t status, ConditionalStack cstack)
{
int cmdend = strcspn(p + 1, "`");
char *file = pnstrdup(p + 1, cmdend);
- FILE *fd = popen(file, "r");
+ FILE *fd;
+ fflush(NULL);
+ fd = popen(file, "r");
if (fd)
{
if (fgets(buf, sizeof(buf), fd) == NULL)
diff --git a/src/bin/psql/psqlscanslash.l b/src/bin/psql/psqlscanslash.l
index 878da9f48e9..a467b721449 100644
--- a/src/bin/psql/psqlscanslash.l
+++ b/src/bin/psql/psqlscanslash.l
@@ -777,6 +777,7 @@ evaluate_backtick(PsqlScanState state)
initPQExpBuffer(&cmd_output);
+ fflush(NULL);
fd = popen(cmd, "r");
if (!fd)
{