0003-Default-new-bindir-to-exec_path-v2.patch
application/octet-stream
Filename: 0003-Default-new-bindir-to-exec_path-v2.patch
Type: application/octet-stream
Part: 2
Patch
Format: format-patch
Series: patch v2-0003
Subject: Default new bindir to exec_path
| File | + | − |
|---|---|---|
| doc/src/sgml/ref/pgupgrade.sgml | 1 | 0 |
| src/bin/pg_upgrade/option.c | 14 | 1 |
| src/bin/pg_upgrade/pg_upgrade.c | 0 | 11 |
| src/bin/pg_upgrade/pg_upgrade.h | 0 | 1 |
From 7dbd62f61c9c0aa4dfb639460e864cea81df44c8 Mon Sep 17 00:00:00 2001
From: Daniel Gustafsson <daniel@yesql.se>
Date: Mon, 25 Mar 2019 23:57:25 +0100
Subject: [PATCH 3/3] Default new bindir to exec_path
Make the directory where the pg_upgrade binary resides the default
for new bindir; move the codepath for finding the exec_path to the
options parsing to support this. The rationale is that since the
new pg_upgrade is highly likely to be executed from the new bindir,
make this the default and avoid the need to separately specify it.
---
doc/src/sgml/ref/pgupgrade.sgml | 1 +
src/bin/pg_upgrade/option.c | 15 ++++++++++++++-
src/bin/pg_upgrade/pg_upgrade.c | 11 -----------
src/bin/pg_upgrade/pg_upgrade.h | 1 -
4 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/doc/src/sgml/ref/pgupgrade.sgml b/doc/src/sgml/ref/pgupgrade.sgml
index c896882dd1..424f0730f1 100644
--- a/doc/src/sgml/ref/pgupgrade.sgml
+++ b/doc/src/sgml/ref/pgupgrade.sgml
@@ -89,6 +89,7 @@
<term><option>-B</option> <replaceable>bindir</replaceable></term>
<term><option>--new-bindir=</option><replaceable>bindir</replaceable></term>
<listitem><para>the new PostgreSQL executable directory;
+ default is the directory where <application>pg_upgrade</application> resides;
environment variable <envar>PGBINNEW</envar></para></listitem>
</varlistentry>
diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c
index ab5e2d6a30..a54fe35eb1 100644
--- a/src/bin/pg_upgrade/option.c
+++ b/src/bin/pg_upgrade/option.c
@@ -65,6 +65,7 @@ parseCommandLine(int argc, char *argv[])
FILE *fp;
char **filename;
time_t run_time = time(NULL);
+ char exec_path[MAXPGPATH]; /* full path to my executable */
user_opts.transfer_mode = TRANSFER_MODE_COPY;
@@ -74,6 +75,17 @@ parseCommandLine(int argc, char *argv[])
old_cluster.port = getenv("PGPORTOLD") ? atoi(getenv("PGPORTOLD")) : DEF_PGUPORT;
new_cluster.port = getenv("PGPORTNEW") ? atoi(getenv("PGPORTNEW")) : DEF_PGUPORT;
+ /*
+ * Get path to pg_upgrade executable to use as default in case -B isn't
+ * supplied by the user. Load the path here for usage() output.
+ */
+ if (find_my_exec(argv[0], exec_path) < 0)
+ pg_fatal("%s: could not find own program executable\n", argv[0]);
+ /* Trim off program name and keep just path */
+ *last_dir_separator(exec_path) = '\0';
+ canonicalize_path(exec_path);
+ new_cluster.bindir = pg_strdup(exec_path);
+
os_user_effective_id = get_user_info(&os_info.user);
/* we override just the database user name; we got the OS id above */
if (getenv("PGUSER"))
@@ -114,6 +126,7 @@ parseCommandLine(int argc, char *argv[])
break;
case 'B':
+ pg_free(new_cluster.bindir);
new_cluster.bindir = pg_strdup(optarg);
break;
@@ -291,7 +304,7 @@ usage(void)
printf(_(" pg_upgrade [OPTION]...\n\n"));
printf(_("Options:\n"));
printf(_(" -b, --old-bindir=BINDIR old cluster executable directory\n"));
- printf(_(" -B, --new-bindir=BINDIR new cluster executable directory\n"));
+ printf(_(" -B, --new-bindir=BINDIR new cluster executable directory (default \"%s\"\n"), new_cluster.bindir);
printf(_(" -c, --check check clusters only, don't change any data\n"));
printf(_(" -d, --old-datadir=DATADIR old cluster data directory\n"));
printf(_(" -D, --new-datadir=DATADIR new cluster data directory\n"));
diff --git a/src/bin/pg_upgrade/pg_upgrade.c b/src/bin/pg_upgrade/pg_upgrade.c
index 0b304bbd56..f3d0501fa6 100644
--- a/src/bin/pg_upgrade/pg_upgrade.c
+++ b/src/bin/pg_upgrade/pg_upgrade.c
@@ -204,8 +204,6 @@ main(int argc, char **argv)
static void
setup(char *argv0, bool *live_check)
{
- char exec_path[MAXPGPATH]; /* full path to my executable */
-
/*
* make sure the user has a clean environment, otherwise, we may confuse
* libpq when we connect to one (or both) of the servers.
@@ -247,15 +245,6 @@ setup(char *argv0, bool *live_check)
pg_fatal("There seems to be a postmaster servicing the new cluster.\n"
"Please shutdown that postmaster and try again.\n");
}
-
- /* get path to pg_upgrade executable */
- if (find_my_exec(argv0, exec_path) < 0)
- pg_fatal("%s: could not find own program executable\n", argv0);
-
- /* Trim off program name and keep just path */
- *last_dir_separator(exec_path) = '\0';
- canonicalize_path(exec_path);
- os_info.exec_path = pg_strdup(exec_path);
}
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index baeb8ff0f8..04b537a8cd 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -320,7 +320,6 @@ typedef struct
typedef struct
{
const char *progname; /* complete pathname for this program */
- char *exec_path; /* full path to my executable */
char *user; /* username for clusters */
bool user_specified; /* user specified on command-line */
char **old_tablespaces; /* tablespaces */
--
2.14.1.145.gb3622a4ee