Unsurprisingly, this shaves code. get_major_server_version() can be
replaced by the new routine added by
cd0be131ba6f, with the contents of
PG_VERSION stored in an allocated buffer instead of a fixed-sized one.
Author: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
Discussion: https://postgr.es/m/aOiirvWJzwdVCXph@paquier.xyz
#include <fcntl.h>
#include "common/string.h"
+#include "fe_utils/version.h"
#include "pg_upgrade.h"
static void check_data_dir(ClusterInfo *cluster);
const char *pg_data = cluster->pgdata;
/* get the cluster version */
- cluster->major_version = get_major_server_version(cluster);
-
+ cluster->major_version = get_pg_version(cluster->pgdata,
+ &cluster->major_version_str);
check_single_dir(pg_data, "");
check_single_dir(pg_data, "base");
check_single_dir(pg_data, "global");
char *sockdir; /* directory for Unix Domain socket, if any */
unsigned short port; /* port number where postmaster is waiting */
uint32 major_version; /* PG_VERSION of cluster */
- char major_version_str[64]; /* string PG_VERSION of cluster */
+ char *major_version_str; /* string PG_VERSION of cluster */
uint32 bin_version; /* version returned from pg_ctl */
char **tablespaces; /* tablespace directories */
int num_tablespaces;
bool start_postmaster(ClusterInfo *cluster, bool report_and_exit_on_error);
void stop_postmaster(bool in_atexit);
-uint32 get_major_server_version(ClusterInfo *cluster);
void check_pghost_envvar(void);
}
-/*
- * get_major_server_version()
- *
- * gets the version (in unsigned int form) for the given datadir. Assumes
- * that datadir is an absolute path to a valid pgdata directory. The version
- * is retrieved by reading the PG_VERSION file.
- */
-uint32
-get_major_server_version(ClusterInfo *cluster)
-{
- FILE *version_fd;
- char ver_filename[MAXPGPATH];
- int v1 = 0,
- v2 = 0;
-
- snprintf(ver_filename, sizeof(ver_filename), "%s/PG_VERSION",
- cluster->pgdata);
- if ((version_fd = fopen(ver_filename, "r")) == NULL)
- pg_fatal("could not open version file \"%s\": %m", ver_filename);
-
- if (fscanf(version_fd, "%63s", cluster->major_version_str) == 0 ||
- sscanf(cluster->major_version_str, "%d.%d", &v1, &v2) < 1)
- pg_fatal("could not parse version file \"%s\"", ver_filename);
-
- fclose(version_fd);
-
- if (v1 < 10)
- {
- /* old style, e.g. 9.6.1 */
- return v1 * 10000 + v2 * 100;
- }
- else
- {
- /* new style, e.g. 10.1 */
- return v1 * 10000;
- }
-}
-
-
static void
stop_postmaster_atexit(void)
{