summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2012-09-05 23:14:49 -0400
committerAndrew Dunstan <andrew@dunslane.net>2012-09-05 23:14:49 -0400
commitf8c81c5dde23a0be553e95728ffc11e76602fd24 (patch)
tree1e8f54bb8e37698cbd0859458235f8352a1e09ce
parent4c60b80094009c6f8ed9ccee365e445f07e609ab (diff)
In pg_upgrade, try a few times to open a log file.
If we call pg_ctl stop, the server might continue and thus hold a log file for a short time after it has deleted its pid file, (which is when pg_ctl will exit), and so a subsequent attempt to open the log file might fail. We therefore try to open it a few times, sleeping one second between tries, to give the server time to exit. This corrects an error that was observed on the buildfarm. Backpatched to 9.2,
-rw-r--r--contrib/pg_upgrade/exec.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/contrib/pg_upgrade/exec.c b/contrib/pg_upgrade/exec.c
index 99f500645ef..644ea0eb277 100644
--- a/contrib/pg_upgrade/exec.c
+++ b/contrib/pg_upgrade/exec.c
@@ -63,7 +63,28 @@ exec_prog(const char *log_file, const char *opt_log_file,
if (written >= MAXCMDLEN)
pg_log(PG_FATAL, "command too long\n");
- if ((log = fopen_priv(log_file, "a")) == NULL)
+ log = fopen_priv(log_file, "a");
+
+#ifdef WIN32
+ {
+ /*
+ * "pg_ctl -w stop" might have reported that the server has
+ * stopped because the postmaster.pid file has been removed,
+ * but "pg_ctl -w start" might still be in the process of
+ * closing and might still be holding its stdout and -l log
+ * file descriptors open. Therefore, try to open the log
+ * file a few more times.
+ */
+ int iter;
+ for (iter = 0; iter < 4 && log == NULL; iter++)
+ {
+ sleep(1);
+ log = fopen_priv(log_file, "a");
+ }
+ }
+#endif
+
+ if (log == NULL)
pg_log(PG_FATAL, "cannot write to log file %s\n", log_file);
#ifdef WIN32
fprintf(log, "\n\n");