*** a/src/bin/initdb/initdb.c --- b/src/bin/initdb/initdb.c *************** *** 177,182 **** static const char *backend_options = "--single -F -O -c search_path=pg_catalog - --- 177,183 ---- static char bin_path[MAXPGPATH]; static char backend_exec[MAXPGPATH]; + static char * make_absolute_path(const char *path); static void *pg_malloc(size_t size); static char *pg_strdup(const char *s); static char **replace_token(char **lines, *************** *** 1163,1168 **** setup_config(void) --- 1164,1171 ---- char repltok[MAXPGPATH]; char path[MAXPGPATH]; const char *default_timezone; + char *abs_data_dir; + FILE *autofile; fputs(_("creating configuration files ... "), stdout); fflush(stdout); *************** *** 1245,1255 **** setup_config(void) --- 1248,1285 ---- conflines = replace_token(conflines, "#log_timezone = 'GMT'", repltok); } + abs_data_dir = make_absolute_path(pg_data); + + snprintf(repltok, sizeof(repltok), "include_dir = '%s/config_dir'", + abs_data_dir); + conflines = replace_token(conflines, "#include_dir = 'conf.d'", repltok); + snprintf(path, sizeof(path), "%s/postgresql.conf", pg_data); writefile(path, conflines); chmod(path, S_IRUSR | S_IWUSR); + /*create a .auto for conf file*/ + sprintf(path, "%s/config_dir/postgresql.auto.conf", pg_data); + autofile = fopen(path, PG_BINARY_W); + if (autofile == NULL) + { + fprintf(stderr, _("%s: could not open file \"%s\" for writing: %s\n"), + progname, path, strerror(errno)); + exit_nicely(); + } + + + if (fclose(autofile)) + { + fprintf(stderr, _("%s: could not write file \"%s\": %s\n"), + progname, path, strerror(errno)); + exit_nicely(); + } + + chmod(path, S_IRUSR | S_IWUSR); + + free(conflines); *************** *** 2823,2828 **** check_need_password(const char *authmethodlocal, const char *authmethodhost) --- 2853,2934 ---- } } + /* + * 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. + * + */ + static 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; + + buflen = MAXPGPATH; + for (;;) + { + buf = malloc(buflen); + if (!buf) + { + fprintf(stderr, _("%s: Memory allocation failed\n"), + progname); + exit_nicely(); + } + + if (getcwd(buf, buflen)) + break; + else if (errno == ERANGE) + { + free(buf); + buflen *= 2; + continue; + } + else + { + free(buf); + fprintf(stderr, _("%s: could not get current working directory\n"), + progname); + exit_nicely(); + } + } + + new = malloc(strlen(buf) + strlen(path) + 2); + if (!new) + { + fprintf(stderr, _("%s: Memory allocation failed\n"), + progname); + exit_nicely(); + } + sprintf(new, "%s/%s", buf, path); + free(buf); + } + else + { + new = strdup(path); + if (!new) + { + fprintf(stderr, _("%s: Memory allocation failed\n"), + progname); + exit_nicely(); + } + } + + /* Make sure punctuation is canonical, too */ + canonicalize_path(new); + + return new; + } + int main(int argc, char *argv[]) { *************** *** 2887,2893 **** main(int argc, char *argv[]) "base", "base/1", "pg_tblspc", ! "pg_stat_tmp" }; progname = get_progname(argv[0]); --- 2993,3000 ---- "base", "base/1", "pg_tblspc", ! "pg_stat_tmp", ! "config_dir" }; progname = get_progname(argv[0]);