* Select the configuration files and data directory to be used, and * do the initial read of postgresql.conf. * * This is called after processing command-line switches. * userDoption is the -D switch value if any (NULL if unspecified). * progname is just for use in error messages. * * Returns true on success; on failure, prints a suitable error message * to stderr and returns false. */
| 6131 | * to stderr and returns false. |
| 6132 | */ |
| 6133 | bool |
| 6134 | SelectConfigFiles(const char *userDoption, const char *progname) |
| 6135 | { |
| 6136 | char *configdir; |
| 6137 | char *fname; |
| 6138 | struct stat stat_buf; |
| 6139 | |
| 6140 | /* configdir is -D option, or $PGDATA if no -D */ |
| 6141 | if (userDoption) |
| 6142 | configdir = make_absolute_path(userDoption); |
| 6143 | else |
| 6144 | configdir = make_absolute_path(getenv("PGDATA")); |
| 6145 | |
| 6146 | if (configdir && stat(configdir, &stat_buf) != 0) |
| 6147 | { |
| 6148 | write_stderr("%s: could not access directory \"%s\": %s\n", |
| 6149 | progname, |
| 6150 | configdir, |
| 6151 | strerror(errno)); |
| 6152 | if (errno == ENOENT) |
| 6153 | write_stderr("Run initdb or pg_basebackup to initialize a PostgreSQL data directory.\n"); |
| 6154 | return false; |
| 6155 | } |
| 6156 | |
| 6157 | /* |
| 6158 | * Find the configuration file: if config_file was specified on the |
| 6159 | * command line, use it, else use configdir/postgresql.conf. In any case |
| 6160 | * ensure the result is an absolute path, so that it will be interpreted |
| 6161 | * the same way by future backends. |
| 6162 | */ |
| 6163 | if (ConfigFileName) |
| 6164 | fname = make_absolute_path(ConfigFileName); |
| 6165 | else if (configdir) |
| 6166 | { |
| 6167 | fname = guc_malloc(FATAL, |
| 6168 | strlen(configdir) + strlen(CONFIG_FILENAME) + 2); |
| 6169 | sprintf(fname, "%s/%s", configdir, CONFIG_FILENAME); |
| 6170 | } |
| 6171 | else |
| 6172 | { |
| 6173 | write_stderr("%s does not know where to find the server configuration file.\n" |
| 6174 | "You must specify the --config-file or -D invocation " |
| 6175 | "option or set the PGDATA environment variable.\n", |
| 6176 | progname); |
| 6177 | return false; |
| 6178 | } |
| 6179 | |
| 6180 | /* |
| 6181 | * Set the ConfigFileName GUC variable to its final value, ensuring that |
| 6182 | * it can't be overridden later. |
| 6183 | */ |
| 6184 | SetConfigOption("config_file", fname, PGC_POSTMASTER, PGC_S_OVERRIDE); |
| 6185 | free(fname); |
| 6186 | |
| 6187 | /* |
| 6188 | * Now read the config file for the first time. |
| 6189 | */ |
| 6190 | if (stat(ConfigFileName, &stat_buf) != 0) |
no test coverage detected