|
|
|
@ -160,11 +160,6 @@ parseCommandLine(int argc, char *argv[]) |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Someday, the port number option could be removed and passed |
|
|
|
|
* using -o/-O, but that requires postmaster -C to be |
|
|
|
|
* supported on all old/new versions (added in PG 9.2). |
|
|
|
|
*/ |
|
|
|
|
case 'p': |
|
|
|
|
if ((old_cluster.port = atoi(optarg)) <= 0) |
|
|
|
|
pg_fatal("invalid old port number\n"); |
|
|
|
@ -187,12 +182,6 @@ parseCommandLine(int argc, char *argv[]) |
|
|
|
|
pg_free(os_info.user); |
|
|
|
|
os_info.user = pg_strdup(optarg); |
|
|
|
|
os_info.user_specified = true; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Push the user name into the environment so pre-9.1 |
|
|
|
|
* pg_ctl/libpq uses it. |
|
|
|
|
*/ |
|
|
|
|
setenv("PGUSER", os_info.user, 1); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case 'v': |
|
|
|
@ -469,67 +458,51 @@ void |
|
|
|
|
get_sock_dir(ClusterInfo *cluster, bool live_check) |
|
|
|
|
{ |
|
|
|
|
#if defined(HAVE_UNIX_SOCKETS) && !defined(WIN32) |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* sockdir and port were added to postmaster.pid in PG 9.1. Pre-9.1 cannot |
|
|
|
|
* process pg_ctl -w for sockets in non-default locations. |
|
|
|
|
*/ |
|
|
|
|
if (GET_MAJOR_VERSION(cluster->major_version) >= 901) |
|
|
|
|
if (!live_check) |
|
|
|
|
cluster->sockdir = user_opts.socketdir; |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
if (!live_check) |
|
|
|
|
cluster->sockdir = user_opts.socketdir; |
|
|
|
|
else |
|
|
|
|
/*
|
|
|
|
|
* If we are doing a live check, we will use the old cluster's Unix |
|
|
|
|
* domain socket directory so we can connect to the live server. |
|
|
|
|
*/ |
|
|
|
|
unsigned short orig_port = cluster->port; |
|
|
|
|
char filename[MAXPGPATH], |
|
|
|
|
line[MAXPGPATH]; |
|
|
|
|
FILE *fp; |
|
|
|
|
int lineno; |
|
|
|
|
|
|
|
|
|
snprintf(filename, sizeof(filename), "%s/postmaster.pid", |
|
|
|
|
cluster->pgdata); |
|
|
|
|
if ((fp = fopen(filename, "r")) == NULL) |
|
|
|
|
pg_fatal("could not open file \"%s\": %s\n", |
|
|
|
|
filename, strerror(errno)); |
|
|
|
|
|
|
|
|
|
for (lineno = 1; |
|
|
|
|
lineno <= Max(LOCK_FILE_LINE_PORT, LOCK_FILE_LINE_SOCKET_DIR); |
|
|
|
|
lineno++) |
|
|
|
|
{ |
|
|
|
|
/*
|
|
|
|
|
* If we are doing a live check, we will use the old cluster's |
|
|
|
|
* Unix domain socket directory so we can connect to the live |
|
|
|
|
* server. |
|
|
|
|
*/ |
|
|
|
|
unsigned short orig_port = cluster->port; |
|
|
|
|
char filename[MAXPGPATH], |
|
|
|
|
line[MAXPGPATH]; |
|
|
|
|
FILE *fp; |
|
|
|
|
int lineno; |
|
|
|
|
|
|
|
|
|
snprintf(filename, sizeof(filename), "%s/postmaster.pid", |
|
|
|
|
cluster->pgdata); |
|
|
|
|
if ((fp = fopen(filename, "r")) == NULL) |
|
|
|
|
pg_fatal("could not open file \"%s\": %s\n", |
|
|
|
|
filename, strerror(errno)); |
|
|
|
|
|
|
|
|
|
for (lineno = 1; |
|
|
|
|
lineno <= Max(LOCK_FILE_LINE_PORT, LOCK_FILE_LINE_SOCKET_DIR); |
|
|
|
|
lineno++) |
|
|
|
|
if (fgets(line, sizeof(line), fp) == NULL) |
|
|
|
|
pg_fatal("could not read line %d from file \"%s\": %s\n", |
|
|
|
|
lineno, filename, strerror(errno)); |
|
|
|
|
|
|
|
|
|
/* potentially overwrite user-supplied value */ |
|
|
|
|
if (lineno == LOCK_FILE_LINE_PORT) |
|
|
|
|
sscanf(line, "%hu", &old_cluster.port); |
|
|
|
|
if (lineno == LOCK_FILE_LINE_SOCKET_DIR) |
|
|
|
|
{ |
|
|
|
|
if (fgets(line, sizeof(line), fp) == NULL) |
|
|
|
|
pg_fatal("could not read line %d from file \"%s\": %s\n", |
|
|
|
|
lineno, filename, strerror(errno)); |
|
|
|
|
|
|
|
|
|
/* potentially overwrite user-supplied value */ |
|
|
|
|
if (lineno == LOCK_FILE_LINE_PORT) |
|
|
|
|
sscanf(line, "%hu", &old_cluster.port); |
|
|
|
|
if (lineno == LOCK_FILE_LINE_SOCKET_DIR) |
|
|
|
|
{ |
|
|
|
|
/* strip trailing newline and carriage return */ |
|
|
|
|
cluster->sockdir = pg_strdup(line); |
|
|
|
|
(void) pg_strip_crlf(cluster->sockdir); |
|
|
|
|
} |
|
|
|
|
/* strip trailing newline and carriage return */ |
|
|
|
|
cluster->sockdir = pg_strdup(line); |
|
|
|
|
(void) pg_strip_crlf(cluster->sockdir); |
|
|
|
|
} |
|
|
|
|
fclose(fp); |
|
|
|
|
|
|
|
|
|
/* warn of port number correction */ |
|
|
|
|
if (orig_port != DEF_PGUPORT && old_cluster.port != orig_port) |
|
|
|
|
pg_log(PG_WARNING, "user-supplied old port number %hu corrected to %hu\n", |
|
|
|
|
orig_port, cluster->port); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
fclose(fp); |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Can't get sockdir and pg_ctl -w can't use a non-default, use |
|
|
|
|
* default |
|
|
|
|
*/ |
|
|
|
|
cluster->sockdir = NULL; |
|
|
|
|
/* warn of port number correction */ |
|
|
|
|
if (orig_port != DEF_PGUPORT && old_cluster.port != orig_port) |
|
|
|
|
pg_log(PG_WARNING, "user-supplied old port number %hu corrected to %hu\n", |
|
|
|
|
orig_port, cluster->port); |
|
|
|
|
} |
|
|
|
|
#else /* !HAVE_UNIX_SOCKETS || WIN32 */ |
|
|
|
|
cluster->sockdir = NULL; |
|
|
|
|
#endif |
|
|
|
|