diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-12-16 12:01:59 -0500 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-12-16 12:01:59 -0500 |
| commit | c49d926833fa6a987e3f9a66027f4a01d7a008be (patch) | |
| tree | e2eb64f8d7406a299c9c4fd8d758fbe5aaddb5f7 /src/bin/pg_upgrade/option.c | |
| parent | 58e2e6eb67fec14c793c74207407e172d7e0291d (diff) | |
| download | postgresql-c49d926833fa6a987e3f9a66027f4a01d7a008be.tar.gz | |
Clean up some more freshly-dead code in pg_dump and pg_upgrade.
I missed a few things in 30e7c175b and e469f0aaf,
as noted by Justin Pryzby.
Discussion: https://postgr.es/m/2923349.1634942313@sss.pgh.pa.us
Diffstat (limited to 'src/bin/pg_upgrade/option.c')
| -rw-r--r-- | src/bin/pg_upgrade/option.c | 105 |
1 files changed, 39 insertions, 66 deletions
diff --git a/src/bin/pg_upgrade/option.c b/src/bin/pg_upgrade/option.c index 64bbda5650..2d92294d9d 100644 --- a/src/bin/pg_upgrade/option.c +++ b/src/bin/pg_upgrade/option.c @@ -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 |
