]> granicus.if.org Git - postgresql/commitdiff
In pg_upgrade, fix the -l/log option to work on Windows.
authorBruce Momjian <bruce@momjian.us>
Wed, 20 Jul 2011 22:31:03 +0000 (18:31 -0400)
committerBruce Momjian <bruce@momjian.us>
Wed, 20 Jul 2011 22:31:03 +0000 (18:31 -0400)
Also, double-quote the log file name in all places, to allow (on all
platforms) log file names with spaces.

Back patch to 9.0 and 9.1.

contrib/pg_upgrade/check.c
contrib/pg_upgrade/option.c
contrib/pg_upgrade/pg_upgrade.c
contrib/pg_upgrade/pg_upgrade.h
contrib/pg_upgrade/server.c

index fa4ef8dcc7c05609fca6d89b8aab34eef7157140..528b674b4f0f080bf6dfa55133349faa4be0cc8d 100644 (file)
@@ -170,7 +170,7 @@ issue_warnings(char *sequence_script_file_name)
                                          "--no-psqlrc --port %d --username \"%s\" "
                                          "-f \"%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
                                          new_cluster.bindir, new_cluster.port, os_info.user,
-                                         sequence_script_file_name, log_opts.filename);
+                                         sequence_script_file_name, log_opts.filename2);
                        unlink(sequence_script_file_name);
                        check_ok();
                }
index 1793bb320e82e31063833a898924ecd8744e7497..32bd3b896e22dd87d9b85a7494a3ae53c2316256 100644 (file)
@@ -192,8 +192,15 @@ parseCommandLine(int argc, char *argv[])
                        pg_log(PG_FATAL, "cannot write to log file %s\n", log_opts.filename);
        }
        else
-               log_opts.filename = strdup(DEVNULL);
+               log_opts.filename = pg_strdup(DEVNULL);
 
+       /* WIN32 files do not accept writes from multiple processes */
+#ifndef WIN32
+       log_opts.filename2 = pg_strdup(log_opts.filename);
+#else
+       log_opts.filename2 = pg_strdup(DEVNULL);
+#endif
+               
        /* if no debug file name, output to the terminal */
        if (log_opts.debug && !log_opts.debug_fd)
        {
index efa5c0f177a765085de71e214c6f67b474a0d76a..4912f7727f6568bdcb3ee0898137a476d5bba331 100644 (file)
@@ -193,8 +193,8 @@ prepare_new_cluster(void)
        prep_status("Analyzing all rows in the new cluster");
        exec_prog(true,
                          SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" "
-                         "--all --analyze >> %s 2>&1" SYSTEMQUOTE,
-         new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename);
+                         "--all --analyze >> \"%s\" 2>&1" SYSTEMQUOTE,
+         new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename2);
        check_ok();
 
        /*
@@ -206,8 +206,8 @@ prepare_new_cluster(void)
        prep_status("Freezing all rows on the new cluster");
        exec_prog(true,
                          SYSTEMQUOTE "\"%s/vacuumdb\" --port %d --username \"%s\" "
-                         "--all --freeze >> %s 2>&1" SYSTEMQUOTE,
-         new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename);
+                         "--all --freeze >> \"%s\" 2>&1" SYSTEMQUOTE,
+         new_cluster.bindir, new_cluster.port, os_info.user, log_opts.filename2);
        check_ok();
 
        get_pg_database_relfilenode(&new_cluster);
@@ -245,7 +245,7 @@ prepare_new_databases(void)
                          "--no-psqlrc --port %d --username \"%s\" "
                          "-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
                          new_cluster.bindir, new_cluster.port, os_info.user, os_info.cwd,
-                         GLOBALS_DUMP_FILE, log_opts.filename);
+                         GLOBALS_DUMP_FILE, log_opts.filename2);
        check_ok();
 
        /* we load this to get a current list of databases */
@@ -276,7 +276,7 @@ create_new_objects(void)
                          "--no-psqlrc --port %d --username \"%s\" "
                          "-f \"%s/%s\" --dbname template1 >> \"%s\"" SYSTEMQUOTE,
                          new_cluster.bindir, new_cluster.port, os_info.user, os_info.cwd,
-                         DB_DUMP_FILE, log_opts.filename);
+                         DB_DUMP_FILE, log_opts.filename2);
        check_ok();
 
        /* regenerate now that we have objects in the databases */
@@ -324,7 +324,7 @@ copy_clog_xlog_xid(void)
        exec_prog(true, SYSTEMQUOTE "\"%s/pg_resetxlog\" -l %u,%u,%u \"%s\" >> \"%s\" 2>&1" SYSTEMQUOTE,
                          new_cluster.bindir, old_cluster.controldata.chkpnt_tli,
                        old_cluster.controldata.logid, old_cluster.controldata.nxtlogseg,
-                         new_cluster.pgdata, log_opts.filename);
+                         new_cluster.pgdata, log_opts.filename2);
        check_ok();
 }
 
index 4729ac39d91d5d68b45291ea387dee6af98ffcbb..df884bd684b6f4cbf0a2ab9cdecd6da28f738f60 100644 (file)
@@ -199,6 +199,16 @@ typedef struct
 typedef struct
 {
        char       *filename;           /* name of log file (may be /dev/null) */
+       /*
+        * WIN32 files do not accept writes from multiple processes
+        *
+        * On Win32, we can't send both pg_upgrade output and command output to the
+        * same file because we get the error: "The process cannot access the file
+        * because it is being used by another process." so we have to send all
+        * other output to 'nul'.  Therefore, we set this to DEVNULL on Win32, and
+        * it equals 'filename' on all other platforms.
+        */
+       char       *filename2;
        FILE       *fd;                         /* log FILE */
        bool            debug;                  /* TRUE -> log more information */
        FILE       *debug_fd;           /* debug-level log FILE */
index 59eaad9dcf7ca1ae89f3f5e3c8d1c24e0131cfae..17231da790e388e755beccf741ce656bc3d0ebaa 100644 (file)
@@ -147,19 +147,6 @@ start_postmaster(ClusterInfo *cluster)
        bool            exit_hook_registered = false;
        int                     pg_ctl_return = 0;
 
-#ifndef WIN32
-       char       *output_filename = log_opts.filename;
-#else
-
-       /*
-        * On Win32, we can't send both pg_upgrade output and pg_ctl output to the
-        * same file because we get the error: "The process cannot access the file
-        * because it is being used by another process." so we have to send all
-        * other output to 'nul'.
-        */
-       char       *output_filename = DEVNULL;
-#endif
-
        if (!exit_hook_registered)
        {
 #ifdef HAVE_ATEXIT
@@ -180,11 +167,11 @@ start_postmaster(ClusterInfo *cluster)
        snprintf(cmd, sizeof(cmd),
                         SYSTEMQUOTE "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" "
                         "-o \"-p %d %s\" start >> \"%s\" 2>&1" SYSTEMQUOTE,
-                        cluster->bindir, output_filename, cluster->pgdata, cluster->port,
+                        cluster->bindir, log_opts.filename2, cluster->pgdata, cluster->port,
                         (cluster->controldata.cat_ver >=
                          BINARY_UPGRADE_SERVER_FLAG_CAT_VER) ? "-b" :
                         "-c autovacuum=off -c autovacuum_freeze_max_age=2000000000",
-                        log_opts.filename);
+                        log_opts.filename2);
 
        /*
         * Don't throw an error right away, let connecting throw the error because
@@ -221,13 +208,6 @@ stop_postmaster(bool fast)
        const char *bindir;
        const char *datadir;
 
-#ifndef WIN32
-       char       *output_filename = log_opts.filename;
-#else
-       /* See comment in start_postmaster() about why win32 output is ignored. */
-       char       *output_filename = DEVNULL;
-#endif
-
        if (os_info.running_cluster == &old_cluster)
        {
                bindir = old_cluster.bindir;
@@ -244,8 +224,8 @@ stop_postmaster(bool fast)
        snprintf(cmd, sizeof(cmd),
                         SYSTEMQUOTE "\"%s/pg_ctl\" -w -l \"%s\" -D \"%s\" %s stop >> "
                         "\"%s\" 2>&1" SYSTEMQUOTE,
-                        bindir, output_filename, datadir, fast ? "-m fast" : "",
-                        output_filename);
+                        bindir, log_opts.filename2, datadir, fast ? "-m fast" : "",
+                        log_opts.filename2);
 
        exec_prog(fast ? false : true, "%s", cmd);