diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2004-10-09 23:13:22 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2004-10-09 23:13:22 +0000 |
commit | 337ffcddbae15a3bde25b17dbb8a0832c597003f (patch) | |
tree | 8901b4f89003a45b6a7ebf5fc1a75c6506dd3264 /src/backend/utils/init | |
parent | 0d069c53c3b01b37388473c123f0a78a09d7d3e5 (diff) | |
download | postgresql-337ffcddbae15a3bde25b17dbb8a0832c597003f.tar.gz |
Adjust configuration-files GUC behavior as per my recent proposal.
The vars are renamed to data_directory, config_file, hba_file, and
ident_file, and are guaranteed to be set to accurate absolute paths
during postmaster startup.
This commit does not yet do anything about hiding path values from
non-superusers.
Diffstat (limited to 'src/backend/utils/init')
-rw-r--r-- | src/backend/utils/init/miscinit.c | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 346ae3b951..5a81c0467b 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.134 2004/10/04 14:55:17 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.135 2004/10/09 23:13:06 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -171,7 +171,34 @@ SetDataDir(const char *dir) AssertArg(dir); /* If presented path is relative, convert to absolute */ - if (!is_absolute_path(dir)) + new = make_absolute_path(dir); + + if (DataDir) + free(DataDir); + DataDir = new; +} + +/* + * If the given pathname isn't already absolute, make it so, interpreting + * it relative to the current working directory. + * + * Also canonicalizes the path. The result is always a malloc'd copy. + * + * Note: it is probably unwise to use this in running backends, since they + * have chdir'd to a database-specific subdirectory; the results would not be + * consistent across backends. Currently this is used only during postmaster + * or standalone-backend startup. + */ +char * +make_absolute_path(const char *path) +{ + char *new; + + /* Returning null for null input is convenient for some callers */ + if (path == NULL) + return NULL; + + if (!is_absolute_path(path)) { char *buf; size_t buflen; @@ -200,28 +227,27 @@ SetDataDir(const char *dir) } } - new = malloc(strlen(buf) + 1 + strlen(dir) + 1); + new = malloc(strlen(buf) + strlen(path) + 2); if (!new) ereport(FATAL, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); - sprintf(new, "%s/%s", buf, dir); + sprintf(new, "%s/%s", buf, path); free(buf); } else { - new = strdup(dir); + new = strdup(path); if (!new) ereport(FATAL, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); } + /* Make sure punctuation is canonical, too */ canonicalize_path(new); - if (DataDir) - free(DataDir); - DataDir = new; + return new; } |