src/bin/pg_upgrade/option.c
void
adjust_data_dir(ClusterInfo *cluster)
{
	char		filename[MAXPGPATH];
	char		cmd[MAXPGPATH],
				cmd_output[MAX_STRING];
	FILE	   *fp,
			   *output;

	/* Initially assume config dir and data dir are the same */
	cluster->pgconfig = pg_strdup(cluster->pgdata);

	/* If there is no postgresql.conf, it can't be a config-only dir */
	snprintf(filename, sizeof(filename), "%s/postgresql.conf", cluster->pgconfig);
	if ((fp = fopen(filename, "r")) == NULL)
		return;
	fclose(fp);

	/* If PG_VERSION exists, it can't be a config-only dir */
	snprintf(filename, sizeof(filename), "%s/PG_VERSION", cluster->pgconfig);
	if ((fp = fopen(filename, "r")) != NULL)
	{
		fclose(fp);
		return;
	}

	/* Must be a configuration directory, so find the real data directory. */

	if (cluster == &old_cluster)
		prep_status("Finding the real data directory for the source cluster");
	else
		prep_status("Finding the real data directory for the target cluster");

	/*
	 * We don't have a data directory yet, so we can't check the PG version,
	 * so this might fail --- only works for PG 9.2+.   If this fails,
	 * pg_upgrade will fail anyway because the data files will not be found.
	 */
	snprintf(cmd, sizeof(cmd), "\"%s/postgres\" -D \"%s\" -C data_directory",
			 cluster->bindir, cluster->pgconfig);

	if ((output = popen(cmd, "r")) == NULL ||
		fgets(cmd_output, sizeof(cmd_output), output) == NULL)
		pg_fatal("could not get data directory using %s: %s\n",
				 cmd, strerror(errno));

	pclose(output);

	/* strip trailing newline and carriage return */
	(void) pg_strip_crlf(cmd_output);

	cluster->pgdata = pg_strdup(cmd_output);

	check_ok();
}
/*
 * adjust_data_dir
 *
 * If a configuration-only directory was specified, find the real data dir
 * by querying the running server.  This has limited checking because we
 * can't check for a running server because we can't find postmaster.pid.
 *
 * On entry, cluster->pgdata has been set from command line or env variable,
 * but cluster->pgconfig isn't set.  We fill both variables with corrected
 * values.
 */
adjust_data_dir
If a configuration-only directory was specified, find the real data dir
by querying the running server.  This has limited checking because we
can't check for a running server because we can't find postmaster.pid.

On entry, cluster->pgdata has been set from command line or env variable,
but cluster->pgconfig isn't set.  We fill both variables with corrected
values.
adjust_data_dir If a configuration - only directory was specified find the real data dir by querying the running server . This has limited checking because we can ' t check for a running server because we can ' t find postmaster . pid . On entry cluster - > pgdata has been set from command line or env variable but cluster - > pgconfig isn ' t set . We fill both variables with corrected values .
void
adjust_data_dir(ClusterInfo *cluster)
{
	char		filename[MAXPGPATH];
	char		cmd[MAXPGPATH],
				cmd_output[MAX_STRING];
	FILE	   *fp,
			   *output;
	cluster->pgconfig = pg_strdup(cluster->pgdata);
	snprintf(filename, sizeof(filename), "%s/postgresql.conf", cluster->pgconfig);
	if ((fp = fopen(filename, "r")) == NULL)
		return;
	fclose(fp);
	snprintf(filename, sizeof(filename), "%s/PG_VERSION", cluster->pgconfig);
	if ((fp = fopen(filename, "r")) != NULL)
	{
		fclose(fp);
		return;
	}
	if (cluster == &old_cluster)
		prep_status("Finding the real data directory for the source cluster");
	else
		prep_status("Finding the real data directory for the target cluster");
	snprintf(cmd, sizeof(cmd), "\"%s/postgres\" -D \"%s\" -C data_directory",
			 cluster->bindir, cluster->pgconfig);
	if ((output = popen(cmd, "r")) == NULL ||
		fgets(cmd_output, sizeof(cmd_output), output) == NULL)
		pg_fatal("could not get data directory using %s: %s\n",
				 cmd, strerror(errno));
	pclose(output);
	(void) pg_strip_crlf(cmd_output);
	cluster->pgdata = pg_strdup(cmd_output);
	check_ok();
}
void adjust_data_dir ( ClusterInfo * cluster ) { char filename [ MAXPGPATH ] ; char cmd [ MAXPGPATH ] , cmd_output [ MAX_STRING ] ; FILE * fp , * output ; cluster -> pgconfig = pg_strdup ( cluster -> pgdata ) ; snprintf ( filename , sizeof ( filename ) , " " , cluster -> pgconfig ) ; if ( ( fp = fopen ( filename , " " ) ) == NULL ) return ; fclose ( fp ) ; snprintf ( filename , sizeof ( filename ) , " " , cluster -> pgconfig ) ; if ( ( fp = fopen ( filename , " " ) ) != NULL ) { fclose ( fp ) ; return ; } if ( cluster == & old_cluster ) prep_status ( " " ) ; else prep_status ( " " ) ; snprintf ( cmd , sizeof ( cmd ) , " \" \" \" \" " , cluster -> bindir , cluster -> pgconfig ) ; if ( ( output = popen ( cmd , " " ) ) == NULL || fgets ( cmd_output , sizeof ( cmd_output ) , output ) == NULL ) pg_fatal ( " \n " , cmd , strerror ( errno ) ) ; pclose ( output ) ; ( void ) pg_strip_crlf ( cmd_output ) ; cluster -> pgdata = pg_strdup ( cmd_output ) ; check_ok ( ) ; }
adjust_data_dir
 If a configuration-only directory was specified, find the real data dir
 by querying the running server.
adjust_data_dir If a configuration - only directory was specified find the real data dir by querying the running server .
/* Initially assume config dir and data dir are the same */ /* If there is no postgresql.conf, it can't be a config-only dir */ /* If PG_VERSION exists, it can't be a config-only dir */ /* Must be a configuration directory, so find the real data directory. */ /*
	 * We don't have a data directory yet, so we can't check the PG version,
	 * so this might fail --- only works for PG 9.2+.   If this fails,
	 * pg_upgrade will fail anyway because the data files will not be found.
	 */ /* strip trailing newline and carriage return */