aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2012-06-28 23:27:00 -0400
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2012-06-29 11:39:11 -0400
commit4741e9afb93f0d769655b2d18c2b73b86f281010 (patch)
treefe0a771bb218f0cd8693db3ad7a6050c12b91aa9
parentb344c651fb87cb7c7f9f59b714e2879e777caf66 (diff)
downloadpostgresql-4741e9afb93f0d769655b2d18c2b73b86f281010.tar.gz
postgresql-4741e9afb93f0d769655b2d18c2b73b86f281010.zip
Make the pg_upgrade log files contain actual commands
Now the log file not only contains the output from commands executed by system(), but also what command it was in the first place. This arrangement makes debugging a lot simpler.
-rw-r--r--contrib/pg_upgrade/exec.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/contrib/pg_upgrade/exec.c b/contrib/pg_upgrade/exec.c
index 9e63bd58568..0d6fb8d792d 100644
--- a/contrib/pg_upgrade/exec.c
+++ b/contrib/pg_upgrade/exec.c
@@ -29,7 +29,8 @@ static int win32_check_directory_write_permissions(void);
*
* Formats a command from the given argument list and executes that
* command. If the command executes, exec_prog() returns 1 otherwise
- * exec_prog() logs an error message and returns 0.
+ * exec_prog() logs an error message and returns 0. Either way, the command
+ * line to be executed is saved to the specified log file.
*
* If throw_error is TRUE, this function will throw a PG_FATAL error
* instead of returning should an error occur.
@@ -40,8 +41,10 @@ exec_prog(bool throw_error, bool is_priv,
{
va_list args;
int result;
+ int retval;
char cmd[MAXPGPATH];
mode_t old_umask = 0;
+ FILE *log = fopen(log_file, "a+");
if (is_priv)
old_umask = umask(S_IRWXG | S_IRWXO);
@@ -51,6 +54,8 @@ exec_prog(bool throw_error, bool is_priv,
va_end(args);
pg_log(PG_VERBOSE, "%s\n", cmd);
+ fprintf(log, "command: %s\n", cmd);
+ fflush(log);
result = system(cmd);
@@ -66,10 +71,15 @@ exec_prog(bool throw_error, bool is_priv,
"Consult the last few lines of \"%s\" for\n"
"the probable cause of the failure.\n",
log_file);
- return 1;
+ retval = 1;
}
+ else
+ retval = 0;
- return 0;
+ fprintf(log, "\n\n");
+ fclose(log);
+
+ return retval;
}