src/backend/utils/misc/guc.c
void
InitializeGUCOptions(void)
{
	int			i;
	char	   *env;
	long		stack_rlimit;

	/*
	 * Before log_line_prefix could possibly receive a nonempty setting, make
	 * sure that timezone processing is minimally alive (see elog.c).
	 */
	pg_timezone_pre_initialize();

	/*
	 * Build sorted array of all GUC variables.
	 */
	build_guc_variables();

	/*
	 * Load all variables with their compiled-in defaults, and initialize
	 * status fields as needed.
	 */
	for (i = 0; i < num_guc_variables; i++)
	{
		struct config_generic *gconf = guc_variables[i];

		gconf->status = 0;
		gconf->reset_source = PGC_S_DEFAULT;
		gconf->tentative_source = PGC_S_DEFAULT;
		gconf->source = PGC_S_DEFAULT;
		gconf->stack = NULL;

		switch (gconf->vartype)
		{
			case PGC_BOOL:
				{
					struct config_bool *conf = (struct config_bool *) gconf;

					if (conf->assign_hook)
						if (!(*conf->assign_hook) (conf->reset_val, true,
												   PGC_S_DEFAULT))
							elog(FATAL, "failed to initialize %s to %d",
								 conf->gen.name, (int) conf->reset_val);
					*conf->variable = conf->reset_val;
					break;
				}
			case PGC_INT:
				{
					struct config_int *conf = (struct config_int *) gconf;

					Assert(conf->reset_val >= conf->min);
					Assert(conf->reset_val <= conf->max);
					if (conf->assign_hook)
						if (!(*conf->assign_hook) (conf->reset_val, true,
												   PGC_S_DEFAULT))
							elog(FATAL, "failed to initialize %s to %d",
								 conf->gen.name, conf->reset_val);
					*conf->variable = conf->reset_val;
					break;
				}
			case PGC_REAL:
				{
					struct config_real *conf = (struct config_real *) gconf;

					Assert(conf->reset_val >= conf->min);
					Assert(conf->reset_val <= conf->max);
					if (conf->assign_hook)
						if (!(*conf->assign_hook) (conf->reset_val, true,
												   PGC_S_DEFAULT))
							elog(FATAL, "failed to initialize %s to %g",
								 conf->gen.name, conf->reset_val);
					*conf->variable = conf->reset_val;
					break;
				}
			case PGC_STRING:
				{
					struct config_string *conf = (struct config_string *) gconf;
					char	   *str;

					*conf->variable = NULL;
					conf->reset_val = NULL;
					conf->tentative_val = NULL;

					if (conf->boot_val == NULL)
					{
						/* Cannot set value yet */
						break;
					}

					str = guc_strdup(FATAL, conf->boot_val);
					conf->reset_val = str;

					if (conf->assign_hook)
					{
						const char *newstr;

						newstr = (*conf->assign_hook) (str, true,
													   PGC_S_DEFAULT);
						if (newstr == NULL)
						{
							elog(FATAL, "failed to initialize %s to \"%s\"",
								 conf->gen.name, str);
						}
						else if (newstr != str)
						{
							free(str);

							/*
							 * See notes in set_config_option about casting
							 */
							str = (char *) newstr;
							conf->reset_val = str;
						}
					}
					*conf->variable = str;
					break;
				}
		}
	}

	guc_dirty = false;
	guc_cannotprepare = false;

	reporting_enabled = false;

	/*
	 * Prevent any attempt to override the transaction modes from
	 * non-interactive sources.
	 */
	SetConfigOption("transaction_isolation", "default",
					PGC_POSTMASTER, PGC_S_OVERRIDE);
	SetConfigOption("transaction_read_only", "no",
					PGC_POSTMASTER, PGC_S_OVERRIDE);

	/*
	 * For historical reasons, some GUC parameters can receive defaults from
	 * environment variables.  Process those settings.
	 */

	env = getenv("PGPORT");
	if (env != NULL)
		SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);

	env = getenv("PGDATESTYLE");
	if (env != NULL)
		SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);

	env = getenv("PGCLIENTENCODING");
	if (env != NULL)
		SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);

	/*
	 * rlimit isn't exactly an "environment variable", but it behaves about
	 * the same.  If we can identify the platform stack depth rlimit, increase
	 * default stack depth setting up to whatever is safe (but at most 2MB).
	 */
	stack_rlimit = get_stack_depth_rlimit();
	if (stack_rlimit > 0)
	{
		int		new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;

		if (new_limit > 100)
		{
			char	limbuf[16];

			new_limit = Min(new_limit, 2048);
			sprintf(limbuf, "%d", new_limit);
			SetConfigOption("max_stack_depth", limbuf,
							PGC_POSTMASTER, PGC_S_ENV_VAR);
		}
	}
}
/*
 * Initialize GUC options during program startup.
 *
 * Note that we cannot read the config file yet, since we have not yet
 * processed command-line switches.
 */
Initialize GUC options during program startup.
Note that we cannot read the config file yet, since we have not yet
processed command-line switches.
Initialize GUC options during program startup . Note that we cannot read the config file yet since we have not yet processed command - line switches .
void
InitializeGUCOptions(void)
{
	int			i;
	char	   *env;
	long		stack_rlimit;
	pg_timezone_pre_initialize();
	build_guc_variables();
	for (i = 0; i < num_guc_variables; i++)
	{
		struct config_generic *gconf = guc_variables[i];
		gconf->status = 0;
		gconf->reset_source = PGC_S_DEFAULT;
		gconf->tentative_source = PGC_S_DEFAULT;
		gconf->source = PGC_S_DEFAULT;
		gconf->stack = NULL;
		switch (gconf->vartype)
		{
			case PGC_BOOL:
				{
					struct config_bool *conf = (struct config_bool *) gconf;
					if (conf->assign_hook)
						if (!(*conf->assign_hook) (conf->reset_val, true,
												   PGC_S_DEFAULT))
							elog(FATAL, "failed to initialize %s to %d",
								 conf->gen.name, (int) conf->reset_val);
					*conf->variable = conf->reset_val;
					break;
				}
			case PGC_INT:
				{
					struct config_int *conf = (struct config_int *) gconf;
					Assert(conf->reset_val >= conf->min);
					Assert(conf->reset_val <= conf->max);
					if (conf->assign_hook)
						if (!(*conf->assign_hook) (conf->reset_val, true,
												   PGC_S_DEFAULT))
							elog(FATAL, "failed to initialize %s to %d",
								 conf->gen.name, conf->reset_val);
					*conf->variable = conf->reset_val;
					break;
				}
			case PGC_REAL:
				{
					struct config_real *conf = (struct config_real *) gconf;
					Assert(conf->reset_val >= conf->min);
					Assert(conf->reset_val <= conf->max);
					if (conf->assign_hook)
						if (!(*conf->assign_hook) (conf->reset_val, true,
												   PGC_S_DEFAULT))
							elog(FATAL, "failed to initialize %s to %g",
								 conf->gen.name, conf->reset_val);
					*conf->variable = conf->reset_val;
					break;
				}
			case PGC_STRING:
				{
					struct config_string *conf = (struct config_string *) gconf;
					char	   *str;
					*conf->variable = NULL;
					conf->reset_val = NULL;
					conf->tentative_val = NULL;
					if (conf->boot_val == NULL)
					{
						break;
					}
					str = guc_strdup(FATAL, conf->boot_val);
					conf->reset_val = str;
					if (conf->assign_hook)
					{
						const char *newstr;
						newstr = (*conf->assign_hook) (str, true,
													   PGC_S_DEFAULT);
						if (newstr == NULL)
						{
							elog(FATAL, "failed to initialize %s to \"%s\"",
								 conf->gen.name, str);
						}
						else if (newstr != str)
						{
							free(str);
							str = (char *) newstr;
							conf->reset_val = str;
						}
					}
					*conf->variable = str;
					break;
				}
		}
	}
	guc_dirty = false;
	guc_cannotprepare = false;
	reporting_enabled = false;
	SetConfigOption("transaction_isolation", "default",
					PGC_POSTMASTER, PGC_S_OVERRIDE);
	SetConfigOption("transaction_read_only", "no",
					PGC_POSTMASTER, PGC_S_OVERRIDE);
	env = getenv("PGPORT");
	if (env != NULL)
		SetConfigOption("port", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
	env = getenv("PGDATESTYLE");
	if (env != NULL)
		SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
	env = getenv("PGCLIENTENCODING");
	if (env != NULL)
		SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
	stack_rlimit = get_stack_depth_rlimit();
	if (stack_rlimit > 0)
	{
		int		new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
		if (new_limit > 100)
		{
			char	limbuf[16];
			new_limit = Min(new_limit, 2048);
			sprintf(limbuf, "%d", new_limit);
			SetConfigOption("max_stack_depth", limbuf,
							PGC_POSTMASTER, PGC_S_ENV_VAR);
		}
	}
}
void InitializeGUCOptions ( void ) { int i ; char * env ; long stack_rlimit ; pg_timezone_pre_initialize ( ) ; build_guc_variables ( ) ; for ( i = 0 ; i < num_guc_variables ; i ++ ) { struct config_generic * gconf = guc_variables [ i ] ; gconf -> status = 0 ; gconf -> reset_source = PGC_S_DEFAULT ; gconf -> tentative_source = PGC_S_DEFAULT ; gconf -> source = PGC_S_DEFAULT ; gconf -> stack = NULL ; switch ( gconf -> vartype ) { case PGC_BOOL : { struct config_bool * conf = ( struct config_bool * ) gconf ; if ( conf -> assign_hook ) if ( ! ( * conf -> assign_hook ) ( conf -> reset_val , true , PGC_S_DEFAULT ) ) elog ( FATAL , " " , conf -> gen . name , ( int ) conf -> reset_val ) ; * conf -> variable = conf -> reset_val ; break ; } case PGC_INT : { struct config_int * conf = ( struct config_int * ) gconf ; Assert ( conf -> reset_val >= conf -> min ) ; Assert ( conf -> reset_val <= conf -> max ) ; if ( conf -> assign_hook ) if ( ! ( * conf -> assign_hook ) ( conf -> reset_val , true , PGC_S_DEFAULT ) ) elog ( FATAL , " " , conf -> gen . name , conf -> reset_val ) ; * conf -> variable = conf -> reset_val ; break ; } case PGC_REAL : { struct config_real * conf = ( struct config_real * ) gconf ; Assert ( conf -> reset_val >= conf -> min ) ; Assert ( conf -> reset_val <= conf -> max ) ; if ( conf -> assign_hook ) if ( ! ( * conf -> assign_hook ) ( conf -> reset_val , true , PGC_S_DEFAULT ) ) elog ( FATAL , " " , conf -> gen . name , conf -> reset_val ) ; * conf -> variable = conf -> reset_val ; break ; } case PGC_STRING : { struct config_string * conf = ( struct config_string * ) gconf ; char * str ; * conf -> variable = NULL ; conf -> reset_val = NULL ; conf -> tentative_val = NULL ; if ( conf -> boot_val == NULL ) { break ; } str = guc_strdup ( FATAL , conf -> boot_val ) ; conf -> reset_val = str ; if ( conf -> assign_hook ) { const char * newstr ; newstr = ( * conf -> assign_hook ) ( str , true , PGC_S_DEFAULT ) ; if ( newstr == NULL ) { elog ( FATAL , " \" \" " , conf -> gen . name , str ) ; } else if ( newstr != str ) { free ( str ) ; str = ( char * ) newstr ; conf -> reset_val = str ; } } * conf -> variable = str ; break ; } } } guc_dirty = false ; guc_cannotprepare = false ; reporting_enabled = false ; SetConfigOption ( " " , " " , PGC_POSTMASTER , PGC_S_OVERRIDE ) ; SetConfigOption ( " " , " " , PGC_POSTMASTER , PGC_S_OVERRIDE ) ; env = getenv ( " " ) ; if ( env != NULL ) SetConfigOption ( " " , env , PGC_POSTMASTER , PGC_S_ENV_VAR ) ; env = getenv ( " " ) ; if ( env != NULL ) SetConfigOption ( " " , env , PGC_POSTMASTER , PGC_S_ENV_VAR ) ; env = getenv ( " " ) ; if ( env != NULL ) SetConfigOption ( " " , env , PGC_POSTMASTER , PGC_S_ENV_VAR ) ; stack_rlimit = get_stack_depth_rlimit ( ) ; if ( stack_rlimit > 0 ) { int new_limit = ( stack_rlimit - STACK_DEPTH_SLOP ) / 1024L ; if ( new_limit > 100 ) { char limbuf [ 16 ] ; new_limit = Min ( new_limit , 2048 ) ; sprintf ( limbuf , " " , new_limit ) ; SetConfigOption ( " " , limbuf , PGC_POSTMASTER , PGC_S_ENV_VAR ) ; } } }
Initialize GUC options during program startup.
Initialize GUC options during program startup .
/*
	 * Before log_line_prefix could possibly receive a nonempty setting, make
	 * sure that timezone processing is minimally alive (see elog.c).
	 */ /*
	 * Build sorted array of all GUC variables.
	 */ /*
	 * Load all variables with their compiled-in defaults, and initialize
	 * status fields as needed.
	 */ /* Cannot set value yet */ /*
							 * See notes in set_config_option about casting
							 */ /*
	 * Prevent any attempt to override the transaction modes from
	 * non-interactive sources.
	 */ /*
	 * For historical reasons, some GUC parameters can receive defaults from
	 * environment variables.  Process those settings.
	 */ /*
	 * rlimit isn't exactly an "environment variable", but it behaves about
	 * the same.  If we can identify the platform stack depth rlimit, increase
	 * default stack depth setting up to whatever is safe (but at most 2MB).
	 */