317
* Trim off any trailing path separators because we construct paths
318
* by appending to this path.
317
* Trim off any trailing path separators because we construct paths by
318
* appending to this path.
321
321
if ((*dirpath)[strlen(*dirpath) - 1] == '/')
398
398
get_sock_dir(ClusterInfo *cluster, bool live_check)
400
400
#ifdef HAVE_UNIX_SOCKETS
402
* sockdir and port were added to postmaster.pid in PG 9.1.
403
* Pre-9.1 cannot process pg_ctl -w for sockets in non-default
403
* sockdir and port were added to postmaster.pid in PG 9.1. Pre-9.1 cannot
404
* process pg_ctl -w for sockets in non-default locations.
406
406
if (GET_MAJOR_VERSION(cluster->major_version) >= 901)
423
* If we are doing a live check, we will use the old cluster's Unix
424
* domain socket directory so we can connect to the live server.
423
* If we are doing a live check, we will use the old cluster's
424
* Unix domain socket directory so we can connect to the live
426
427
unsigned short orig_port = cluster->port;
427
char filename[MAXPGPATH], line[MAXPGPATH];
428
char filename[MAXPGPATH],
431
433
snprintf(filename, sizeof(filename), "%s/postmaster.pid",
432
434
cluster->pgdata);
433
435
if ((fp = fopen(filename, "r")) == NULL)
434
436
pg_log(PG_FATAL, "Cannot open file %s: %m\n", filename);
437
lineno <= Max(LOCK_FILE_LINE_PORT, LOCK_FILE_LINE_SOCKET_DIR);
439
lineno <= Max(LOCK_FILE_LINE_PORT, LOCK_FILE_LINE_SOCKET_DIR);
440
442
if (fgets(line, sizeof(line), fp) == NULL)
441
443
pg_log(PG_FATAL, "Cannot read line %d from %s: %m\n", lineno, filename);
443
445
/* potentially overwrite user-supplied value */
444
446
if (lineno == LOCK_FILE_LINE_PORT)
445
447
sscanf(line, "%hu", &old_cluster.port);
455
457
/* warn of port number correction */
456
458
if (orig_port != DEF_PGUPORT && old_cluster.port != orig_port)
457
459
pg_log(PG_WARNING, "User-supplied old port number %hu corrected to %hu\n",
458
orig_port, cluster->port);
460
orig_port, cluster->port);
462
/* Can't get sockdir and pg_ctl -w can't use a non-default, use default */
466
* Can't get sockdir and pg_ctl -w can't use a non-default, use
463
469
cluster->sockdir = NULL;
465
#else /* !HAVE_UNIX_SOCKETS */
470
#else /* !HAVE_UNIX_SOCKETS */
466
471
cluster->sockdir = NULL;