+/*
+ * Function to read and process the configuration file. The
+ * parameter indicates the context that the file is being read
+ * (postmaster startup, backend startup, or SIGHUP). All options
+ * mentioned in the configuration file are set to new values. This
+ * function does not return if an error occurs. If an error occurs, no
+ * values will be changed.
+ */
+void
+ProcessConfigFile(GucContext context)
+{
+ char *filename;
+
+ Assert(context == PGC_POSTMASTER || context == PGC_BACKEND || context == PGC_SIGHUP);
+
+ /* Added for explicit config file */
+ if (user_pgconfig)
+ {
+ struct stat sb;
+
+ if (stat(user_pgconfig, &sb) != 0)
+ {
+ int elevel = (context == PGC_SIGHUP) ? DEBUG3 : ERROR;
+ elog(elevel, "Configuration file \"%s\" does not exist", user_pgconfig);
+ return;
+ }
+
+ if (S_ISDIR(sb.st_mode))
+ {
+ /* This will cause a small one time memory leak
+ * if the user also specifies hba_conf,
+ * ident_conf, and data_dir
+ */
+ filename = malloc(strlen(user_pgconfig) + strlen(CONFIG_FILENAME) + 2);
+ sprintf(filename, "%s/%s", user_pgconfig, CONFIG_FILENAME);
+ user_pgconfig_is_dir = true;
+ }
+ else
+ filename = strdup(user_pgconfig); /* Use explicit file */
+ }
+ else
+ {
+ /* Use datadir for config */
+ filename = malloc(strlen(DataDir) + strlen(CONFIG_FILENAME) + 2);
+ sprintf(filename, "%s/%s", DataDir, CONFIG_FILENAME);
+ }
+
+ if (filename == NULL)
+ {
+ int elevel = (context == PGC_SIGHUP) ? DEBUG3 : ERROR;
+ elog(elevel, "out of memory");
+ return;
+ }
+
+ ReadConfigFile(filename, context);
+
+ free(filename);
+}
+