Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 81e51dd

Browse files
committed
Add fflush() before popen() calls; avoids any possible problem with
double or out-of-sequence output with child process.
1 parent 0104fc1 commit 81e51dd

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/bin/initdb/initdb.c

+15-9
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
4343
* Portions Copyright (c) 1994, Regents of the University of California
4444
*
45-
* $Header: /cvsroot/pgsql/src/bin/initdb/initdb.c,v 1.8 2003/11/14 17:19:35 tgl Exp $
45+
* $Header: /cvsroot/pgsql/src/bin/initdb/initdb.c,v 1.9 2003/11/14 17:30:41 tgl Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -204,22 +204,24 @@ static void *xmalloc(size_t);
204204

205205
#define PG_CMD_OPEN \
206206
do { \
207-
pg = popen(cmd,PG_BINARY_W); \
208-
if (pg == NULL) \
209-
exit_nicely(); \
207+
fflush(stdout); \
208+
fflush(stderr); \
209+
pg = popen(cmd, PG_BINARY_W); \
210+
if (pg == NULL) \
211+
exit_nicely(); \
210212
} while (0)
211213

212214
#define PG_CMD_CLOSE \
213215
do { \
214-
if ((pclose(pg) >> 8) & 0xff) \
215-
exit_nicely(); \
216+
if ((pclose(pg) >> 8) & 0xff) \
217+
exit_nicely(); \
216218
} while (0)
217219

218220
#define PG_CMD_PUTLINE \
219221
do { \
220-
if (fputs(*line, pg) < 0) \
221-
exit_nicely(); \
222-
fflush(pg); \
222+
if (fputs(*line, pg) < 0) \
223+
exit_nicely(); \
224+
fflush(pg); \
223225
} while (0)
224226

225227
#ifndef WIN32
@@ -862,6 +864,10 @@ find_postgres(char *path)
862864

863865
snprintf(cmd, sizeof(cmd), "\"%s/postgres\" -V 2>%s", path, DEVNULL);
864866

867+
/* flush output buffers in case popen does not... */
868+
fflush(stdout);
869+
fflush(stderr);
870+
865871
if ((pgver = popen(cmd, "r")) == NULL)
866872
return FIND_EXEC_ERR;
867873

0 commit comments

Comments
 (0)