PostgreSQL Source Code  git master
guc.c File Reference
#include "postgres.h"
#include <limits.h>
#include <sys/stat.h>
#include <unistd.h>
#include "access/xact.h"
#include "access/xlog.h"
#include "catalog/objectaccess.h"
#include "catalog/pg_authid.h"
#include "catalog/pg_parameter_acl.h"
#include "guc_internal.h"
#include "libpq/pqformat.h"
#include "parser/scansup.h"
#include "port/pg_bitutils.h"
#include "storage/fd.h"
#include "storage/lwlock.h"
#include "storage/shmem.h"
#include "tcop/tcopprot.h"
#include "utils/acl.h"
#include "utils/backend_status.h"
#include "utils/builtins.h"
#include "utils/conffiles.h"
#include "utils/float.h"
#include "utils/guc_tables.h"
#include "utils/memutils.h"
#include "utils/timestamp.h"
Include dependency graph for guc.c:

Go to the source code of this file.

Data Structures

struct  unit_conversion
 
struct  GUCHashEntry
 

Macros

#define CONFIG_FILENAME   "postgresql.conf"
 
#define HBA_FILENAME   "pg_hba.conf"
 
#define IDENT_FILENAME   "pg_ident.conf"
 
#define REALTYPE_PRECISION   17
 
#define MAX_UNIT_LEN   3 /* length of longest recognized unit string */
 
#define newval   (newval_union.boolval)
 
#define newval   (newval_union.intval)
 
#define newval   (newval_union.realval)
 
#define newval   (newval_union.stringval)
 
#define newval   (newval_union.enumval)
 

Functions

static int guc_var_compare (const void *a, const void *b)
 
static uint32 guc_name_hash (const void *key, Size keysize)
 
static int guc_name_match (const void *key1, const void *key2, Size keysize)
 
static void InitializeGUCOptionsFromEnvironment (void)
 
static void InitializeOneGUCOption (struct config_generic *gconf)
 
static void RemoveGUCFromLists (struct config_generic *gconf)
 
static void set_guc_source (struct config_generic *gconf, GucSource newsource)
 
static void pg_timezone_abbrev_initialize (void)
 
static void push_old_value (struct config_generic *gconf, GucAction action)
 
static void ReportGUCOption (struct config_generic *record)
 
static void set_config_sourcefile (const char *name, char *sourcefile, int sourceline)
 
static void reapply_stacked_values (struct config_generic *variable, struct config_string *pHolder, GucStack *stack, const char *curvalue, GucContext curscontext, GucSource cursource, Oid cursrole)
 
static bool validate_option_array_item (const char *name, const char *value, bool skipIfNoPermissions)
 
static void write_auto_conf_file (int fd, const char *filename, ConfigVariable *head)
 
static void replace_auto_config_value (ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
 
static bool valid_custom_variable_name (const char *name)
 
static void do_serialize (char **destptr, Size *maxbytes, const char *fmt,...) pg_attribute_printf(3
 
static void static bool call_bool_check_hook (struct config_bool *conf, bool *newval, void **extra, GucSource source, int elevel)
 
static bool call_int_check_hook (struct config_int *conf, int *newval, void **extra, GucSource source, int elevel)
 
static bool call_real_check_hook (struct config_real *conf, double *newval, void **extra, GucSource source, int elevel)
 
static bool call_string_check_hook (struct config_string *conf, char **newval, void **extra, GucSource source, int elevel)
 
static bool call_enum_check_hook (struct config_enum *conf, int *newval, void **extra, GucSource source, int elevel)
 
ConfigVariableProcessConfigFileInternal (GucContext context, bool applySettings, int elevel)
 
void * guc_malloc (int elevel, size_t size)
 
void * guc_realloc (int elevel, void *old, size_t size)
 
char * guc_strdup (int elevel, const char *src)
 
void guc_free (void *ptr)
 
static bool string_field_used (struct config_string *conf, char *strval)
 
static void set_string_field (struct config_string *conf, char **field, char *newval)
 
static bool extra_field_used (struct config_generic *gconf, void *extra)
 
static void set_extra_field (struct config_generic *gconf, void **field, void *newval)
 
static void set_stack_value (struct config_generic *gconf, config_var_value *val)
 
static void discard_stack_value (struct config_generic *gconf, config_var_value *val)
 
struct config_generic ** get_guc_variables (int *num_vars)
 
void build_guc_variables (void)
 
static bool add_guc_variable (struct config_generic *var, int elevel)
 
static struct config_genericadd_placeholder_variable (const char *name, int elevel)
 
struct config_genericfind_option (const char *name, bool create_placeholders, bool skip_errors, int elevel)
 
int guc_name_compare (const char *namea, const char *nameb)
 
char * convert_GUC_name_for_parameter_acl (const char *name)
 
bool check_GUC_name_for_parameter_acl (const char *name)
 
void InitializeGUCOptions (void)
 
bool SelectConfigFiles (const char *userDoption, const char *progname)
 
void ResetAllOptions (void)
 
void AtStart_GUC (void)
 
int NewGUCNestLevel (void)
 
void AtEOXact_GUC (bool isCommit, int nestLevel)
 
void BeginReportingGUCOptions (void)
 
void ReportChangedGUCOptions (void)
 
static bool convert_to_base_unit (double value, const char *unit, int base_unit, double *base_value)
 
static void convert_int_from_base_unit (int64 base_value, int base_unit, int64 *value, const char **unit)
 
static void convert_real_from_base_unit (double base_value, int base_unit, double *value, const char **unit)
 
const char * get_config_unit_name (int flags)
 
bool parse_int (const char *value, int *result, int flags, const char **hintmsg)
 
bool parse_real (const char *value, double *result, int flags, const char **hintmsg)
 
const char * config_enum_lookup_by_value (struct config_enum *record, int val)
 
bool config_enum_lookup_by_name (struct config_enum *record, const char *value, int *retval)
 
char * config_enum_get_options (struct config_enum *record, const char *prefix, const char *suffix, const char *separator)
 
static bool parse_and_validate_value (struct config_generic *record, const char *name, const char *value, GucSource source, int elevel, union config_var_val *newval, void **newextra)
 
int set_config_option (const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
 
int set_config_option_ext (const char *name, const char *value, GucContext context, GucSource source, Oid srole, GucAction action, bool changeVal, int elevel, bool is_reload)
 
void SetConfigOption (const char *name, const char *value, GucContext context, GucSource source)
 
const char * GetConfigOption (const char *name, bool missing_ok, bool restrict_privileged)
 
const char * GetConfigOptionResetString (const char *name)
 
int GetConfigOptionFlags (const char *name, bool missing_ok)
 
void AlterSystemSetConfigFile (AlterSystemStmt *altersysstmt)
 
static struct config_genericinit_custom_variable (const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
 
static void define_custom_variable (struct config_generic *variable)
 
void DefineCustomBoolVariable (const char *name, const char *short_desc, const char *long_desc, bool *valueAddr, bool bootValue, GucContext context, int flags, GucBoolCheckHook check_hook, GucBoolAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomIntVariable (const char *name, const char *short_desc, const char *long_desc, int *valueAddr, int bootValue, int minValue, int maxValue, GucContext context, int flags, GucIntCheckHook check_hook, GucIntAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomRealVariable (const char *name, const char *short_desc, const char *long_desc, double *valueAddr, double bootValue, double minValue, double maxValue, GucContext context, int flags, GucRealCheckHook check_hook, GucRealAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomStringVariable (const char *name, const char *short_desc, const char *long_desc, char **valueAddr, const char *bootValue, GucContext context, int flags, GucStringCheckHook check_hook, GucStringAssignHook assign_hook, GucShowHook show_hook)
 
void DefineCustomEnumVariable (const char *name, const char *short_desc, const char *long_desc, int *valueAddr, int bootValue, const struct config_enum_entry *options, GucContext context, int flags, GucEnumCheckHook check_hook, GucEnumAssignHook assign_hook, GucShowHook show_hook)
 
void MarkGUCPrefixReserved (const char *className)
 
struct config_generic ** get_explain_guc_options (int *num)
 
char * GetConfigOptionByName (const char *name, const char **varname, bool missing_ok)
 
char * ShowGUCOption (struct config_generic *record, bool use_units)
 
static bool can_skip_gucvar (struct config_generic *gconf)
 
static Size estimate_variable_size (struct config_generic *gconf)
 
Size EstimateGUCStateSpace (void)
 
static void do_serialize_binary (char **destptr, Size *maxbytes, void *val, Size valsize)
 
static void serialize_variable (char **destptr, Size *maxbytes, struct config_generic *gconf)
 
void SerializeGUCState (Size maxsize, char *start_address)
 
static char * read_gucstate (char **srcptr, char *srcend)
 
static void read_gucstate_binary (char **srcptr, char *srcend, void *dest, Size size)
 
static void guc_restore_error_context_callback (void *arg)
 
void RestoreGUCState (void *gucstate)
 
void ParseLongOption (const char *string, char **name, char **value)
 
void TransformGUCArray (ArrayType *array, List **names, List **values)
 
void ProcessGUCArray (ArrayType *array, GucContext context, GucSource source, GucAction action)
 
ArrayTypeGUCArrayAdd (ArrayType *array, const char *name, const char *value)
 
ArrayTypeGUCArrayDelete (ArrayType *array, const char *name)
 
ArrayTypeGUCArrayReset (ArrayType *array)
 
void GUC_check_errcode (int sqlerrcode)
 

Variables

static int GUC_check_errcode_value
 
static Listreserved_class_prefix = NIL
 
char * GUC_check_errmsg_string
 
char * GUC_check_errdetail_string
 
char * GUC_check_errhint_string
 
bool in_hot_standby_guc
 
static const char *const memory_units_hint = gettext_noop("Valid units for this parameter are \"B\", \"kB\", \"MB\", \"GB\", and \"TB\".")
 
static const unit_conversion memory_unit_conversion_table []
 
static const char *const time_units_hint = gettext_noop("Valid units for this parameter are \"us\", \"ms\", \"s\", \"min\", \"h\", and \"d\".")
 
static const unit_conversion time_unit_conversion_table []
 
static const char *const map_old_guc_names []
 
static MemoryContext GUCMemoryContext
 
static HTABguc_hashtab
 
static dlist_head guc_nondef_list
 
static slist_head guc_stack_list
 
static slist_head guc_report_list
 
static bool reporting_enabled
 
static int GUCNestLevel = 0
 

Macro Definition Documentation

◆ CONFIG_FILENAME

#define CONFIG_FILENAME   "postgresql.conf"

Definition at line 54 of file guc.c.

◆ HBA_FILENAME

#define HBA_FILENAME   "pg_hba.conf"

Definition at line 55 of file guc.c.

◆ IDENT_FILENAME

#define IDENT_FILENAME   "pg_ident.conf"

Definition at line 56 of file guc.c.

◆ MAX_UNIT_LEN

#define MAX_UNIT_LEN   3 /* length of longest recognized unit string */

Definition at line 97 of file guc.c.

◆ newval [1/5]

#define newval   (newval_union.boolval)

◆ newval [2/5]

#define newval   (newval_union.intval)

◆ newval [3/5]

#define newval   (newval_union.realval)

◆ newval [4/5]

#define newval   (newval_union.stringval)

◆ newval [5/5]

#define newval   (newval_union.enumval)

◆ REALTYPE_PRECISION

#define REALTYPE_PRECISION   17

Definition at line 67 of file guc.c.

Function Documentation

◆ add_guc_variable()

static bool add_guc_variable ( struct config_generic var,
int  elevel 
)
static

Definition at line 1040 of file guc.c.

1041 {
1042  GUCHashEntry *hentry;
1043  bool found;
1044 
1045  hentry = (GUCHashEntry *) hash_search(guc_hashtab,
1046  &var->name,
1048  &found);
1049  if (unlikely(hentry == NULL))
1050  {
1051  ereport(elevel,
1052  (errcode(ERRCODE_OUT_OF_MEMORY),
1053  errmsg("out of memory")));
1054  return false; /* out of memory */
1055  }
1056  Assert(!found);
1057  hentry->gucvar = var;
1058  return true;
1059 }
#define unlikely(x)
Definition: c.h:300
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:953
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ereport(elevel,...)
Definition: elog.h:149
static HTAB * guc_hashtab
Definition: guc.c:207
@ HASH_ENTER_NULL
Definition: hsearch.h:116
Assert(fmt[strlen(fmt) - 1] !='\n')
struct config_generic * gucvar
Definition: guc.c:204
const char * name
Definition: guc_tables.h:155

References Assert(), ereport, errcode(), errmsg(), guc_hashtab, GUCHashEntry::gucvar, HASH_ENTER_NULL, hash_search(), config_generic::name, and unlikely.

Referenced by add_placeholder_variable(), and define_custom_variable().

◆ add_placeholder_variable()

static struct config_generic* add_placeholder_variable ( const char *  name,
int  elevel 
)
static

Definition at line 1105 of file guc.c.

1106 {
1107  size_t sz = sizeof(struct config_string) + sizeof(char *);
1108  struct config_string *var;
1109  struct config_generic *gen;
1110 
1111  var = (struct config_string *) guc_malloc(elevel, sz);
1112  if (var == NULL)
1113  return NULL;
1114  memset(var, 0, sz);
1115  gen = &var->gen;
1116 
1117  gen->name = guc_strdup(elevel, name);
1118  if (gen->name == NULL)
1119  {
1120  guc_free(var);
1121  return NULL;
1122  }
1123 
1124  gen->context = PGC_USERSET;
1126  gen->short_desc = "GUC placeholder variable";
1128  gen->vartype = PGC_STRING;
1129 
1130  /*
1131  * The char* is allocated at the end of the struct since we have no
1132  * 'static' place to point to. Note that the current value, as well as
1133  * the boot and reset values, start out NULL.
1134  */
1135  var->variable = (char **) (var + 1);
1136 
1137  if (!add_guc_variable((struct config_generic *) var, elevel))
1138  {
1139  guc_free(unconstify(char *, gen->name));
1140  guc_free(var);
1141  return NULL;
1142  }
1143 
1144  return gen;
1145 }
#define unconstify(underlying_type, expr)
Definition: c.h:1255
void * guc_malloc(int elevel, size_t size)
Definition: guc.c:631
void guc_free(void *ptr)
Definition: guc.c:682
static bool add_guc_variable(struct config_generic *var, int elevel)
Definition: guc.c:1040
char * guc_strdup(int elevel, const char *src)
Definition: guc.c:670
#define GUC_CUSTOM_PLACEHOLDER
Definition: guc.h:217
#define GUC_NO_SHOW_ALL
Definition: guc.h:210
@ PGC_USERSET
Definition: guc.h:75
#define GUC_NOT_IN_SAMPLE
Definition: guc.h:215
@ CUSTOM_OPTIONS
Definition: guc_tables.h:99
@ PGC_STRING
Definition: guc_tables.h:28
enum config_group group
Definition: guc_tables.h:157
GucContext context
Definition: guc_tables.h:156
const char * short_desc
Definition: guc_tables.h:158
enum config_type vartype
Definition: guc_tables.h:162
struct config_generic gen
Definition: guc_tables.h:245
char ** variable
Definition: guc_tables.h:247
const char * name

References add_guc_variable(), config_generic::context, CUSTOM_OPTIONS, config_generic::flags, config_string::gen, config_generic::group, GUC_CUSTOM_PLACEHOLDER, guc_free(), guc_malloc(), GUC_NO_SHOW_ALL, GUC_NOT_IN_SAMPLE, guc_strdup(), name, config_generic::name, PGC_STRING, PGC_USERSET, config_generic::short_desc, unconstify, config_string::variable, and config_generic::vartype.

Referenced by find_option().

◆ AlterSystemSetConfigFile()

void AlterSystemSetConfigFile ( AlterSystemStmt altersysstmt)

Definition at line 4450 of file guc.c.

4451 {
4452  char *name;
4453  char *value;
4454  bool resetall = false;
4455  ConfigVariable *head = NULL;
4456  ConfigVariable *tail = NULL;
4457  volatile int Tmpfd;
4458  char AutoConfFileName[MAXPGPATH];
4459  char AutoConfTmpFileName[MAXPGPATH];
4460 
4461  /*
4462  * Extract statement arguments
4463  */
4464  name = altersysstmt->setstmt->name;
4465 
4466  switch (altersysstmt->setstmt->kind)
4467  {
4468  case VAR_SET_VALUE:
4469  value = ExtractSetVariableArgs(altersysstmt->setstmt);
4470  break;
4471 
4472  case VAR_SET_DEFAULT:
4473  case VAR_RESET:
4474  value = NULL;
4475  break;
4476 
4477  case VAR_RESET_ALL:
4478  value = NULL;
4479  resetall = true;
4480  break;
4481 
4482  default:
4483  elog(ERROR, "unrecognized alter system stmt type: %d",
4484  altersysstmt->setstmt->kind);
4485  break;
4486  }
4487 
4488  /*
4489  * Check permission to run ALTER SYSTEM on the target variable
4490  */
4491  if (!superuser())
4492  {
4493  if (resetall)
4494  ereport(ERROR,
4495  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4496  errmsg("permission denied to perform ALTER SYSTEM RESET ALL")));
4497  else
4498  {
4499  AclResult aclresult;
4500 
4501  aclresult = pg_parameter_aclcheck(name, GetUserId(),
4503  if (aclresult != ACLCHECK_OK)
4504  ereport(ERROR,
4505  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4506  errmsg("permission denied to set parameter \"%s\"",
4507  name)));
4508  }
4509  }
4510 
4511  /*
4512  * Unless it's RESET_ALL, validate the target variable and value
4513  */
4514  if (!resetall)
4515  {
4516  struct config_generic *record;
4517 
4518  record = find_option(name, false, false, ERROR);
4519  Assert(record != NULL);
4520 
4521  /*
4522  * Don't allow parameters that can't be set in configuration files to
4523  * be set in PG_AUTOCONF_FILENAME file.
4524  */
4525  if ((record->context == PGC_INTERNAL) ||
4526  (record->flags & GUC_DISALLOW_IN_FILE) ||
4527  (record->flags & GUC_DISALLOW_IN_AUTO_FILE))
4528  ereport(ERROR,
4529  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
4530  errmsg("parameter \"%s\" cannot be changed",
4531  name)));
4532 
4533  /*
4534  * If a value is specified, verify that it's sane.
4535  */
4536  if (value)
4537  {
4538  union config_var_val newval;
4539  void *newextra = NULL;
4540 
4541  /* Check that it's acceptable for the indicated parameter */
4542  if (!parse_and_validate_value(record, name, value,
4543  PGC_S_FILE, ERROR,
4544  &newval, &newextra))
4545  ereport(ERROR,
4546  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4547  errmsg("invalid value for parameter \"%s\": \"%s\"",
4548  name, value)));
4549 
4550  if (record->vartype == PGC_STRING && newval.stringval != NULL)
4551  guc_free(newval.stringval);
4552  guc_free(newextra);
4553 
4554  /*
4555  * We must also reject values containing newlines, because the
4556  * grammar for config files doesn't support embedded newlines in
4557  * string literals.
4558  */
4559  if (strchr(value, '\n'))
4560  ereport(ERROR,
4561  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
4562  errmsg("parameter value for ALTER SYSTEM must not contain a newline")));
4563  }
4564  }
4565 
4566  /*
4567  * PG_AUTOCONF_FILENAME and its corresponding temporary file are always in
4568  * the data directory, so we can reference them by simple relative paths.
4569  */
4570  snprintf(AutoConfFileName, sizeof(AutoConfFileName), "%s",
4572  snprintf(AutoConfTmpFileName, sizeof(AutoConfTmpFileName), "%s.%s",
4573  AutoConfFileName,
4574  "tmp");
4575 
4576  /*
4577  * Only one backend is allowed to operate on PG_AUTOCONF_FILENAME at a
4578  * time. Use AutoFileLock to ensure that. We must hold the lock while
4579  * reading the old file contents.
4580  */
4581  LWLockAcquire(AutoFileLock, LW_EXCLUSIVE);
4582 
4583  /*
4584  * If we're going to reset everything, then no need to open or parse the
4585  * old file. We'll just write out an empty list.
4586  */
4587  if (!resetall)
4588  {
4589  struct stat st;
4590 
4591  if (stat(AutoConfFileName, &st) == 0)
4592  {
4593  /* open old file PG_AUTOCONF_FILENAME */
4594  FILE *infile;
4595 
4596  infile = AllocateFile(AutoConfFileName, "r");
4597  if (infile == NULL)
4598  ereport(ERROR,
4600  errmsg("could not open file \"%s\": %m",
4601  AutoConfFileName)));
4602 
4603  /* parse it */
4604  if (!ParseConfigFp(infile, AutoConfFileName, CONF_FILE_START_DEPTH,
4605  LOG, &head, &tail))
4606  ereport(ERROR,
4607  (errcode(ERRCODE_CONFIG_FILE_ERROR),
4608  errmsg("could not parse contents of file \"%s\"",
4609  AutoConfFileName)));
4610 
4611  FreeFile(infile);
4612  }
4613 
4614  /*
4615  * Now, replace any existing entry with the new value, or add it if
4616  * not present.
4617  */
4618  replace_auto_config_value(&head, &tail, name, value);
4619  }
4620 
4621  /*
4622  * Invoke the post-alter hook for setting this GUC variable. GUCs
4623  * typically do not have corresponding entries in pg_parameter_acl, so we
4624  * call the hook using the name rather than a potentially-non-existent
4625  * OID. Nonetheless, we pass ParameterAclRelationId so that this call
4626  * context can be distinguished from others. (Note that "name" will be
4627  * NULL in the RESET ALL case.)
4628  *
4629  * We do this here rather than at the end, because ALTER SYSTEM is not
4630  * transactional. If the hook aborts our transaction, it will be cleaner
4631  * to do so before we touch any files.
4632  */
4633  InvokeObjectPostAlterHookArgStr(ParameterAclRelationId, name,
4635  altersysstmt->setstmt->kind,
4636  false);
4637 
4638  /*
4639  * To ensure crash safety, first write the new file data to a temp file,
4640  * then atomically rename it into place.
4641  *
4642  * If there is a temp file left over due to a previous crash, it's okay to
4643  * truncate and reuse it.
4644  */
4645  Tmpfd = BasicOpenFile(AutoConfTmpFileName,
4646  O_CREAT | O_RDWR | O_TRUNC);
4647  if (Tmpfd < 0)
4648  ereport(ERROR,
4650  errmsg("could not open file \"%s\": %m",
4651  AutoConfTmpFileName)));
4652 
4653  /*
4654  * Use a TRY block to clean up the file if we fail. Since we need a TRY
4655  * block anyway, OK to use BasicOpenFile rather than OpenTransientFile.
4656  */
4657  PG_TRY();
4658  {
4659  /* Write and sync the new contents to the temporary file */
4660  write_auto_conf_file(Tmpfd, AutoConfTmpFileName, head);
4661 
4662  /* Close before renaming; may be required on some platforms */
4663  close(Tmpfd);
4664  Tmpfd = -1;
4665 
4666  /*
4667  * As the rename is atomic operation, if any problem occurs after this
4668  * at worst it can lose the parameters set by last ALTER SYSTEM
4669  * command.
4670  */
4671  durable_rename(AutoConfTmpFileName, AutoConfFileName, ERROR);
4672  }
4673  PG_CATCH();
4674  {
4675  /* Close file first, else unlink might fail on some platforms */
4676  if (Tmpfd >= 0)
4677  close(Tmpfd);
4678 
4679  /* Unlink, but ignore any error */
4680  (void) unlink(AutoConfTmpFileName);
4681 
4682  PG_RE_THROW();
4683  }
4684  PG_END_TRY();
4685 
4686  FreeConfigVariables(head);
4687 
4688  LWLockRelease(AutoFileLock);
4689 }
AclResult
Definition: acl.h:181
@ ACLCHECK_OK
Definition: acl.h:182
AclResult pg_parameter_aclcheck(const char *name, Oid roleid, AclMode mode)
Definition: aclchk.c:3935
#define CONF_FILE_START_DEPTH
Definition: conffiles.h:17
int errcode_for_file_access(void)
Definition: elog.c:881
#define LOG
Definition: elog.h:31
#define PG_RE_THROW()
Definition: elog.h:411
#define PG_TRY(...)
Definition: elog.h:370
#define PG_END_TRY(...)
Definition: elog.h:395
#define ERROR
Definition: elog.h:39
#define PG_CATCH(...)
Definition: elog.h:380
FILE * AllocateFile(const char *name, const char *mode)
Definition: fd.c:2528
int durable_rename(const char *oldfile, const char *newfile, int elevel)
Definition: fd.c:734
int BasicOpenFile(const char *fileName, int fileFlags)
Definition: fd.c:1039
int FreeFile(FILE *file)
Definition: fd.c:2726
struct config_generic * find_option(const char *name, bool create_placeholders, bool skip_errors, int elevel)
Definition: guc.c:1163
static bool parse_and_validate_value(struct config_generic *record, const char *name, const char *value, GucSource source, int elevel, union config_var_val *newval, void **newextra)
Definition: guc.c:3083
static void write_auto_conf_file(int fd, const char *filename, ConfigVariable *head)
Definition: guc.c:4312
#define newval
static void replace_auto_config_value(ConfigVariable **head_p, ConfigVariable **tail_p, const char *name, const char *value)
Definition: guc.c:4380
#define PG_AUTOCONF_FILENAME
Definition: guc.h:33
void FreeConfigVariables(ConfigVariable *list)
bool ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
#define GUC_DISALLOW_IN_FILE
Definition: guc.h:216
@ PGC_S_FILE
Definition: guc.h:112
#define GUC_DISALLOW_IN_AUTO_FILE
Definition: guc.h:221
@ PGC_INTERNAL
Definition: guc.h:69
char * ExtractSetVariableArgs(VariableSetStmt *stmt)
Definition: guc_funcs.c:167
static struct @148 value
#define close(a)
Definition: win32.h:12
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1195
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1808
@ LW_EXCLUSIVE
Definition: lwlock.h:116
Oid GetUserId(void)
Definition: miscinit.c:509
#define InvokeObjectPostAlterHookArgStr(classId, objectName, subId, auxiliaryId, is_internal)
Definition: objectaccess.h:247
@ VAR_SET_DEFAULT
Definition: parsenodes.h:2472
@ VAR_RESET
Definition: parsenodes.h:2475
@ VAR_SET_VALUE
Definition: parsenodes.h:2471
@ VAR_RESET_ALL
Definition: parsenodes.h:2476
#define ACL_ALTER_SYSTEM
Definition: parsenodes.h:96
#define MAXPGPATH
#define snprintf
Definition: port.h:238
VariableSetStmt * setstmt
Definition: parsenodes.h:3689
VariableSetKind kind
Definition: parsenodes.h:2482
bool superuser(void)
Definition: superuser.c:46
#define stat
Definition: win32_port.h:284
static void infile(const char *name)
Definition: zic.c:1243

References ACL_ALTER_SYSTEM, ACLCHECK_OK, AllocateFile(), Assert(), BasicOpenFile(), close, CONF_FILE_START_DEPTH, config_generic::context, durable_rename(), elog(), ereport, errcode(), errcode_for_file_access(), errmsg(), ERROR, ExtractSetVariableArgs(), find_option(), config_generic::flags, FreeConfigVariables(), FreeFile(), GetUserId(), GUC_DISALLOW_IN_AUTO_FILE, GUC_DISALLOW_IN_FILE, guc_free(), infile(), InvokeObjectPostAlterHookArgStr, VariableSetStmt::kind, LOG, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MAXPGPATH, name, VariableSetStmt::name, newval, parse_and_validate_value(), ParseConfigFp(), PG_AUTOCONF_FILENAME, PG_CATCH, PG_END_TRY, pg_parameter_aclcheck(), PG_RE_THROW, PG_TRY, PGC_INTERNAL, PGC_S_FILE, PGC_STRING, replace_auto_config_value(), AlterSystemStmt::setstmt, snprintf, stat, superuser(), value, VAR_RESET, VAR_RESET_ALL, VAR_SET_DEFAULT, VAR_SET_VALUE, config_generic::vartype, and write_auto_conf_file().

Referenced by standard_ProcessUtility().

◆ AtEOXact_GUC()

void AtEOXact_GUC ( bool  isCommit,
int  nestLevel 
)

Definition at line 2215 of file guc.c.

2216 {
2217  slist_mutable_iter iter;
2218 
2219  /*
2220  * Note: it's possible to get here with GUCNestLevel == nestLevel-1 during
2221  * abort, if there is a failure during transaction start before
2222  * AtStart_GUC is called.
2223  */
2224  Assert(nestLevel > 0 &&
2225  (nestLevel <= GUCNestLevel ||
2226  (nestLevel == GUCNestLevel + 1 && !isCommit)));
2227 
2228  /* We need only process GUCs having nonempty stacks */
2230  {
2231  struct config_generic *gconf = slist_container(struct config_generic,
2232  stack_link, iter.cur);
2233  GucStack *stack;
2234 
2235  /*
2236  * Process and pop each stack entry within the nest level. To simplify
2237  * fmgr_security_definer() and other places that use GUC_ACTION_SAVE,
2238  * we allow failure exit from code that uses a local nest level to be
2239  * recovered at the surrounding transaction or subtransaction abort;
2240  * so there could be more than one stack entry to pop.
2241  */
2242  while ((stack = gconf->stack) != NULL &&
2243  stack->nest_level >= nestLevel)
2244  {
2245  GucStack *prev = stack->prev;
2246  bool restorePrior = false;
2247  bool restoreMasked = false;
2248  bool changed;
2249 
2250  /*
2251  * In this next bit, if we don't set either restorePrior or
2252  * restoreMasked, we must "discard" any unwanted fields of the
2253  * stack entries to avoid leaking memory. If we do set one of
2254  * those flags, unused fields will be cleaned up after restoring.
2255  */
2256  if (!isCommit) /* if abort, always restore prior value */
2257  restorePrior = true;
2258  else if (stack->state == GUC_SAVE)
2259  restorePrior = true;
2260  else if (stack->nest_level == 1)
2261  {
2262  /* transaction commit */
2263  if (stack->state == GUC_SET_LOCAL)
2264  restoreMasked = true;
2265  else if (stack->state == GUC_SET)
2266  {
2267  /* we keep the current active value */
2268  discard_stack_value(gconf, &stack->prior);
2269  }
2270  else /* must be GUC_LOCAL */
2271  restorePrior = true;
2272  }
2273  else if (prev == NULL ||
2274  prev->nest_level < stack->nest_level - 1)
2275  {
2276  /* decrement entry's level and do not pop it */
2277  stack->nest_level--;
2278  continue;
2279  }
2280  else
2281  {
2282  /*
2283  * We have to merge this stack entry into prev. See README for
2284  * discussion of this bit.
2285  */
2286  switch (stack->state)
2287  {
2288  case GUC_SAVE:
2289  Assert(false); /* can't get here */
2290  break;
2291 
2292  case GUC_SET:
2293  /* next level always becomes SET */
2294  discard_stack_value(gconf, &stack->prior);
2295  if (prev->state == GUC_SET_LOCAL)
2296  discard_stack_value(gconf, &prev->masked);
2297  prev->state = GUC_SET;
2298  break;
2299 
2300  case GUC_LOCAL:
2301  if (prev->state == GUC_SET)
2302  {
2303  /* LOCAL migrates down */
2304  prev->masked_scontext = stack->scontext;
2305  prev->masked_srole = stack->srole;
2306  prev->masked = stack->prior;
2307  prev->state = GUC_SET_LOCAL;
2308  }
2309  else
2310  {
2311  /* else just forget this stack level */
2312  discard_stack_value(gconf, &stack->prior);
2313  }
2314  break;
2315 
2316  case GUC_SET_LOCAL:
2317  /* prior state at this level no longer wanted */
2318  discard_stack_value(gconf, &stack->prior);
2319  /* copy down the masked state */
2321  prev->masked_srole = stack->masked_srole;
2322  if (prev->state == GUC_SET_LOCAL)
2323  discard_stack_value(gconf, &prev->masked);
2324  prev->masked = stack->masked;
2325  prev->state = GUC_SET_LOCAL;
2326  break;
2327  }
2328  }
2329 
2330  changed = false;
2331 
2332  if (restorePrior || restoreMasked)
2333  {
2334  /* Perform appropriate restoration of the stacked value */
2335  config_var_value newvalue;
2336  GucSource newsource;
2337  GucContext newscontext;
2338  Oid newsrole;
2339 
2340  if (restoreMasked)
2341  {
2342  newvalue = stack->masked;
2343  newsource = PGC_S_SESSION;
2344  newscontext = stack->masked_scontext;
2345  newsrole = stack->masked_srole;
2346  }
2347  else
2348  {
2349  newvalue = stack->prior;
2350  newsource = stack->source;
2351  newscontext = stack->scontext;
2352  newsrole = stack->srole;
2353  }
2354 
2355  switch (gconf->vartype)
2356  {
2357  case PGC_BOOL:
2358  {
2359  struct config_bool *conf = (struct config_bool *) gconf;
2360  bool newval = newvalue.val.boolval;
2361  void *newextra = newvalue.extra;
2362 
2363  if (*conf->variable != newval ||
2364  conf->gen.extra != newextra)
2365  {
2366  if (conf->assign_hook)
2367  conf->assign_hook(newval, newextra);
2368  *conf->variable = newval;
2369  set_extra_field(&conf->gen, &conf->gen.extra,
2370  newextra);
2371  changed = true;
2372  }
2373  break;
2374  }
2375  case PGC_INT:
2376  {
2377  struct config_int *conf = (struct config_int *) gconf;
2378  int newval = newvalue.val.intval;
2379  void *newextra = newvalue.extra;
2380 
2381  if (*conf->variable != newval ||
2382  conf->gen.extra != newextra)
2383  {
2384  if (conf->assign_hook)
2385  conf->assign_hook(newval, newextra);
2386  *conf->variable = newval;
2387  set_extra_field(&conf->gen, &conf->gen.extra,
2388  newextra);
2389  changed = true;
2390  }
2391  break;
2392  }
2393  case PGC_REAL:
2394  {
2395  struct config_real *conf = (struct config_real *) gconf;
2396  double newval = newvalue.val.realval;
2397  void *newextra = newvalue.extra;
2398 
2399  if (*conf->variable != newval ||
2400  conf->gen.extra != newextra)
2401  {
2402  if (conf->assign_hook)
2403  conf->assign_hook(newval, newextra);
2404  *conf->variable = newval;
2405  set_extra_field(&conf->gen, &conf->gen.extra,
2406  newextra);
2407  changed = true;
2408  }
2409  break;
2410  }
2411  case PGC_STRING:
2412  {
2413  struct config_string *conf = (struct config_string *) gconf;
2414  char *newval = newvalue.val.stringval;
2415  void *newextra = newvalue.extra;
2416 
2417  if (*conf->variable != newval ||
2418  conf->gen.extra != newextra)
2419  {
2420  if (conf->assign_hook)
2421  conf->assign_hook(newval, newextra);
2422  set_string_field(conf, conf->variable, newval);
2423  set_extra_field(&conf->gen, &conf->gen.extra,
2424  newextra);
2425  changed = true;
2426  }
2427 
2428  /*
2429  * Release stacked values if not used anymore. We
2430  * could use discard_stack_value() here, but since
2431  * we have type-specific code anyway, might as
2432  * well inline it.
2433  */
2434  set_string_field(conf, &stack->prior.val.stringval, NULL);
2435  set_string_field(conf, &stack->masked.val.stringval, NULL);
2436  break;
2437  }
2438  case PGC_ENUM:
2439  {
2440  struct config_enum *conf = (struct config_enum *) gconf;
2441  int newval = newvalue.val.enumval;
2442  void *newextra = newvalue.extra;
2443 
2444  if (*conf->variable != newval ||
2445  conf->gen.extra != newextra)
2446  {
2447  if (conf->assign_hook)
2448  conf->assign_hook(newval, newextra);
2449  *conf->variable = newval;
2450  set_extra_field(&conf->gen, &conf->gen.extra,
2451  newextra);
2452  changed = true;
2453  }
2454  break;
2455  }
2456  }
2457 
2458  /*
2459  * Release stacked extra values if not used anymore.
2460  */
2461  set_extra_field(gconf, &(stack->prior.extra), NULL);
2462  set_extra_field(gconf, &(stack->masked.extra), NULL);
2463 
2464  /* And restore source information */
2465  set_guc_source(gconf, newsource);
2466  gconf->scontext = newscontext;
2467  gconf->srole = newsrole;
2468  }
2469 
2470  /*
2471  * Pop the GUC's state stack; if it's now empty, remove the GUC
2472  * from guc_stack_list.
2473  */
2474  gconf->stack = prev;
2475  if (prev == NULL)
2476  slist_delete_current(&iter);
2477  pfree(stack);
2478 
2479  /* Report new value if we changed it */
2480  if (changed && (gconf->flags & GUC_REPORT) &&
2481  !(gconf->status & GUC_NEEDS_REPORT))
2482  {
2483  gconf->status |= GUC_NEEDS_REPORT;
2485  }
2486  } /* end of stack-popping loop */
2487  }
2488 
2489  /* Update nesting level */
2490  GUCNestLevel = nestLevel - 1;
2491 }
static slist_head guc_report_list
Definition: guc.c:221
static void set_string_field(struct config_string *conf, char **field, char *newval)
Definition: guc.c:724
static int GUCNestLevel
Definition: guc.c:226
static void discard_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:839
static slist_head guc_stack_list
Definition: guc.c:219
static void set_guc_source(struct config_generic *gconf, GucSource newsource)
Definition: guc.c:2077
static void set_extra_field(struct config_generic *gconf, void **field, void *newval)
Definition: guc.c:785
GucSource
Definition: guc.h:108
@ PGC_S_SESSION
Definition: guc.h:122
GucContext
Definition: guc.h:68
#define GUC_REPORT
Definition: guc.h:214
@ GUC_SET_LOCAL
Definition: guc_tables.h:113
@ GUC_SET
Definition: guc_tables.h:111
@ GUC_SAVE
Definition: guc_tables.h:110
@ GUC_LOCAL
Definition: guc_tables.h:112
#define GUC_NEEDS_REPORT
Definition: guc_tables.h:192
@ PGC_BOOL
Definition: guc_tables.h:25
@ PGC_ENUM
Definition: guc_tables.h:29
@ PGC_REAL
Definition: guc_tables.h:27
@ PGC_INT
Definition: guc_tables.h:26
static void slist_delete_current(slist_mutable_iter *iter)
Definition: ilist.h:1084
#define slist_foreach_modify(iter, lhead)
Definition: ilist.h:1148
static void slist_push_head(slist_head *head, slist_node *node)
Definition: ilist.h:1006
#define slist_container(type, membername, ptr)
Definition: ilist.h:1106
void pfree(void *pointer)
Definition: mcxt.c:1456
unsigned int Oid
Definition: postgres_ext.h:31
struct config_generic gen
Definition: guc_tables.h:199
bool * variable
Definition: guc_tables.h:201
GucBoolAssignHook assign_hook
Definition: guc_tables.h:204
int * variable
Definition: guc_tables.h:261
GucEnumAssignHook assign_hook
Definition: guc_tables.h:265
struct config_generic gen
Definition: guc_tables.h:259
GucContext scontext
Definition: guc_tables.h:166
slist_node stack_link
Definition: guc_tables.h:174
GucStack * stack
Definition: guc_tables.h:170
slist_node report_link
Definition: guc_tables.h:176
GucIntAssignHook assign_hook
Definition: guc_tables.h:220
int * variable
Definition: guc_tables.h:215
struct config_generic gen
Definition: guc_tables.h:213
GucRealAssignHook assign_hook
Definition: guc_tables.h:236
double * variable
Definition: guc_tables.h:231
struct config_generic gen
Definition: guc_tables.h:229
GucStringAssignHook assign_hook
Definition: guc_tables.h:250
union config_var_val val
Definition: guc_tables.h:47
struct guc_stack * prev
Definition: guc_tables.h:118
Oid masked_srole
Definition: guc_tables.h:126
int nest_level
Definition: guc_tables.h:119
config_var_value masked
Definition: guc_tables.h:128
config_var_value prior
Definition: guc_tables.h:127
GucContext scontext
Definition: guc_tables.h:123
GucStackState state
Definition: guc_tables.h:120
GucSource source
Definition: guc_tables.h:121
GucContext masked_scontext
Definition: guc_tables.h:124
slist_node * cur
Definition: ilist.h:274
double realval
Definition: guc_tables.h:36
char * stringval
Definition: guc_tables.h:37

References Assert(), config_bool::assign_hook, config_int::assign_hook, config_real::assign_hook, config_string::assign_hook, config_enum::assign_hook, config_var_val::boolval, slist_mutable_iter::cur, discard_stack_value(), config_var_val::enumval, config_var_value::extra, config_generic::extra, config_generic::flags, config_bool::gen, config_int::gen, config_real::gen, config_string::gen, config_enum::gen, GUC_LOCAL, GUC_NEEDS_REPORT, GUC_REPORT, guc_report_list, GUC_SAVE, GUC_SET, GUC_SET_LOCAL, guc_stack_list, GUCNestLevel, config_var_val::intval, guc_stack::masked, guc_stack::masked_scontext, guc_stack::masked_srole, guc_stack::nest_level, newval, pfree(), PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_S_SESSION, PGC_STRING, guc_stack::prev, guc_stack::prior, config_var_val::realval, config_generic::report_link, guc_stack::scontext, config_generic::scontext, set_extra_field(), set_guc_source(), set_string_field(), slist_container, slist_delete_current(), slist_foreach_modify, slist_push_head(), guc_stack::source, guc_stack::srole, config_generic::srole, config_generic::stack, config_generic::stack_link, guc_stack::state, config_generic::status, config_var_val::stringval, config_var_value::val, config_bool::variable, config_int::variable, config_real::variable, config_string::variable, config_enum::variable, and config_generic::vartype.

Referenced by AbortSubTransaction(), AbortTransaction(), brin_summarize_range(), bt_index_check_internal(), cluster_rel(), CommitSubTransaction(), CommitTransaction(), ComputeIndexAttrs(), CreateSchemaCommand(), DefineIndex(), do_analyze_rel(), ExecCreateTableAs(), ExecRefreshMatView(), execute_extension_script(), fmgr_security_definer(), index_build(), index_concurrently_build(), PrepareTransaction(), ProcedureCreate(), reindex_index(), ReindexRelationConcurrently(), reset_transmission_modes(), restoreLocalGucs(), RestoreUserContext(), RI_Initial_Check(), RI_PartitionRemove_Check(), vacuum_rel(), and validate_index().

◆ AtStart_GUC()

void AtStart_GUC ( void  )

Definition at line 2181 of file guc.c.

2182 {
2183  /*
2184  * The nest level should be 0 between transactions; if it isn't, somebody
2185  * didn't call AtEOXact_GUC, or called it with the wrong nestLevel. We
2186  * throw a warning but make no other effort to clean up.
2187  */
2188  if (GUCNestLevel != 0)
2189  elog(WARNING, "GUC nest level = %d at transaction start",
2190  GUCNestLevel);
2191  GUCNestLevel = 1;
2192 }
#define WARNING
Definition: elog.h:36

References elog(), GUCNestLevel, and WARNING.

Referenced by StartTransaction().

◆ BeginReportingGUCOptions()

void BeginReportingGUCOptions ( void  )

Definition at line 2499 of file guc.c.

2500 {
2501  HASH_SEQ_STATUS status;
2502  GUCHashEntry *hentry;
2503 
2504  /*
2505  * Don't do anything unless talking to an interactive frontend.
2506  */
2508  return;
2509 
2510  reporting_enabled = true;
2511 
2512  /*
2513  * Hack for in_hot_standby: set the GUC value true if appropriate. This
2514  * is kind of an ugly place to do it, but there's few better options.
2515  *
2516  * (This could be out of date by the time we actually send it, in which
2517  * case the next ReportChangedGUCOptions call will send a duplicate
2518  * report.)
2519  */
2520  if (RecoveryInProgress())
2521  SetConfigOption("in_hot_standby", "true",
2523 
2524  /* Transmit initial values of interesting variables */
2525  hash_seq_init(&status, guc_hashtab);
2526  while ((hentry = (GUCHashEntry *) hash_seq_search(&status)) != NULL)
2527  {
2528  struct config_generic *conf = hentry->gucvar;
2529 
2530  if (conf->flags & GUC_REPORT)
2531  ReportGUCOption(conf);
2532  }
2533 }
@ DestRemote
Definition: dest.h:89
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1431
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1421
static void ReportGUCOption(struct config_generic *record)
Definition: guc.c:2587
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:4176
static bool reporting_enabled
Definition: guc.c:224
@ PGC_S_OVERRIDE
Definition: guc.h:119
CommandDest whereToSendOutput
Definition: postgres.c:88
bool RecoveryInProgress(void)
Definition: xlog.c:5948

References DestRemote, config_generic::flags, guc_hashtab, GUC_REPORT, GUCHashEntry::gucvar, hash_seq_init(), hash_seq_search(), PGC_INTERNAL, PGC_S_OVERRIDE, RecoveryInProgress(), ReportGUCOption(), reporting_enabled, SetConfigOption(), and whereToSendOutput.

Referenced by PostgresMain().

◆ build_guc_variables()

void build_guc_variables ( void  )

Definition at line 896 of file guc.c.

897 {
898  int size_vars;
899  int num_vars = 0;
900  HASHCTL hash_ctl;
901  GUCHashEntry *hentry;
902  bool found;
903  int i;
904 
905  /*
906  * Create the memory context that will hold all GUC-related data.
907  */
908  Assert(GUCMemoryContext == NULL);
910  "GUCMemoryContext",
912 
913  /*
914  * Count all the built-in variables, and set their vartypes correctly.
915  */
916  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
917  {
918  struct config_bool *conf = &ConfigureNamesBool[i];
919 
920  /* Rather than requiring vartype to be filled in by hand, do this: */
921  conf->gen.vartype = PGC_BOOL;
922  num_vars++;
923  }
924 
925  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
926  {
927  struct config_int *conf = &ConfigureNamesInt[i];
928 
929  conf->gen.vartype = PGC_INT;
930  num_vars++;
931  }
932 
933  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
934  {
935  struct config_real *conf = &ConfigureNamesReal[i];
936 
937  conf->gen.vartype = PGC_REAL;
938  num_vars++;
939  }
940 
941  for (i = 0; ConfigureNamesString[i].gen.name; i++)
942  {
943  struct config_string *conf = &ConfigureNamesString[i];
944 
945  conf->gen.vartype = PGC_STRING;
946  num_vars++;
947  }
948 
949  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
950  {
951  struct config_enum *conf = &ConfigureNamesEnum[i];
952 
953  conf->gen.vartype = PGC_ENUM;
954  num_vars++;
955  }
956 
957  /*
958  * Create hash table with 20% slack
959  */
960  size_vars = num_vars + num_vars / 4;
961 
962  hash_ctl.keysize = sizeof(char *);
963  hash_ctl.entrysize = sizeof(GUCHashEntry);
964  hash_ctl.hash = guc_name_hash;
965  hash_ctl.match = guc_name_match;
966  hash_ctl.hcxt = GUCMemoryContext;
967  guc_hashtab = hash_create("GUC hash table",
968  size_vars,
969  &hash_ctl,
971 
972  for (i = 0; ConfigureNamesBool[i].gen.name; i++)
973  {
974  struct config_generic *gucvar = &ConfigureNamesBool[i].gen;
975 
976  hentry = (GUCHashEntry *) hash_search(guc_hashtab,
977  &gucvar->name,
978  HASH_ENTER,
979  &found);
980  Assert(!found);
981  hentry->gucvar = gucvar;
982  }
983 
984  for (i = 0; ConfigureNamesInt[i].gen.name; i++)
985  {
986  struct config_generic *gucvar = &ConfigureNamesInt[i].gen;
987 
988  hentry = (GUCHashEntry *) hash_search(guc_hashtab,
989  &gucvar->name,
990  HASH_ENTER,
991  &found);
992  Assert(!found);
993  hentry->gucvar = gucvar;
994  }
995 
996  for (i = 0; ConfigureNamesReal[i].gen.name; i++)
997  {
998  struct config_generic *gucvar = &ConfigureNamesReal[i].gen;
999 
1000  hentry = (GUCHashEntry *) hash_search(guc_hashtab,
1001  &gucvar->name,
1002  HASH_ENTER,
1003  &found);
1004  Assert(!found);
1005  hentry->gucvar = gucvar;
1006  }
1007 
1008  for (i = 0; ConfigureNamesString[i].gen.name; i++)
1009  {
1010  struct config_generic *gucvar = &ConfigureNamesString[i].gen;
1011 
1012  hentry = (GUCHashEntry *) hash_search(guc_hashtab,
1013  &gucvar->name,
1014  HASH_ENTER,
1015  &found);
1016  Assert(!found);
1017  hentry->gucvar = gucvar;
1018  }
1019 
1020  for (i = 0; ConfigureNamesEnum[i].gen.name; i++)
1021  {
1022  struct config_generic *gucvar = &ConfigureNamesEnum[i].gen;
1023 
1024  hentry = (GUCHashEntry *) hash_search(guc_hashtab,
1025  &gucvar->name,
1026  HASH_ENTER,
1027  &found);
1028  Assert(!found);
1029  hentry->gucvar = gucvar;
1030  }
1031 
1032  Assert(num_vars == hash_get_num_entries(guc_hashtab));
1033 }
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:350
long hash_get_num_entries(HTAB *hashp)
Definition: dynahash.c:1377
static int guc_name_match(const void *key1, const void *key2, Size keysize)
Definition: guc.c:1319
static uint32 guc_name_hash(const void *key, Size keysize)
Definition: guc.c:1295
static MemoryContext GUCMemoryContext
Definition: guc.c:194
struct config_string ConfigureNamesString[]
Definition: guc_tables.c:3799
struct config_int ConfigureNamesInt[]
Definition: guc_tables.c:2021
struct config_bool ConfigureNamesBool[]
Definition: guc_tables.c:811
struct config_real ConfigureNamesReal[]
Definition: guc_tables.c:3518
struct config_enum ConfigureNamesEnum[]
Definition: guc_tables.c:4562
@ HASH_ENTER
Definition: hsearch.h:114
#define HASH_CONTEXT
Definition: hsearch.h:102
#define HASH_ELEM
Definition: hsearch.h:95
#define HASH_COMPARE
Definition: hsearch.h:99
#define HASH_FUNCTION
Definition: hsearch.h:98
int i
Definition: isn.c:73
MemoryContext TopMemoryContext
Definition: mcxt.c:141
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
Size keysize
Definition: hsearch.h:75
HashValueFunc hash
Definition: hsearch.h:78
Size entrysize
Definition: hsearch.h:76
HashCompareFunc match
Definition: hsearch.h:80
MemoryContext hcxt
Definition: hsearch.h:86

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert(), ConfigureNamesBool, ConfigureNamesEnum, ConfigureNamesInt, ConfigureNamesReal, ConfigureNamesString, HASHCTL::entrysize, config_bool::gen, config_int::gen, config_real::gen, config_string::gen, config_enum::gen, guc_hashtab, guc_name_hash(), guc_name_match(), GUCMemoryContext, GUCHashEntry::gucvar, HASHCTL::hash, HASH_COMPARE, HASH_CONTEXT, hash_create(), HASH_ELEM, HASH_ENTER, HASH_FUNCTION, hash_get_num_entries(), hash_search(), HASHCTL::hcxt, i, HASHCTL::keysize, HASHCTL::match, config_generic::name, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, TopMemoryContext, and config_generic::vartype.

Referenced by GucInfoMain(), and InitializeGUCOptions().

◆ call_bool_check_hook()

static bool call_bool_check_hook ( struct config_bool conf,
bool newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

Definition at line 6622 of file guc.c.

6624 {
6625  /* Quick success if no hook */
6626  if (!conf->check_hook)
6627  return true;
6628 
6629  /* Reset variables that might be set by hook */
6630  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
6631  GUC_check_errmsg_string = NULL;
6633  GUC_check_errhint_string = NULL;
6634 
6635  if (!conf->check_hook(newval, extra, source))
6636  {
6637  ereport(elevel,
6641  errmsg("invalid value for parameter \"%s\": %d",
6642  conf->gen.name, (int) *newval),
6646  errhint("%s", GUC_check_errhint_string) : 0));
6647  /* Flush any strings created in ErrorContext */
6648  FlushErrorState();
6649  return false;
6650  }
6651 
6652  return true;
6653 }
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1156
int errdetail_internal(const char *fmt,...)
Definition: elog.c:1229
void FlushErrorState(void)
Definition: elog.c:1825
int errhint(const char *fmt,...)
Definition: elog.c:1316
char * GUC_check_errhint_string
Definition: guc.c:76
char * GUC_check_errmsg_string
Definition: guc.c:74
static int GUC_check_errcode_value
Definition: guc.c:69
char * GUC_check_errdetail_string
Definition: guc.c:75
static rewind_source * source
Definition: pg_rewind.c:89
GucBoolCheckHook check_hook
Definition: guc_tables.h:203

References config_bool::check_hook, ereport, errcode(), errdetail_internal(), errhint(), errmsg(), errmsg_internal(), config_generic::extra, FlushErrorState(), config_bool::gen, GUC_check_errcode_value, GUC_check_errdetail_string, GUC_check_errhint_string, GUC_check_errmsg_string, config_generic::name, newval, and source.

Referenced by InitializeOneGUCOption(), parse_and_validate_value(), and set_config_option_ext().

◆ call_enum_check_hook()

static bool call_enum_check_hook ( struct config_enum conf,
int *  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

Definition at line 6774 of file guc.c.

6776 {
6777  /* Quick success if no hook */
6778  if (!conf->check_hook)
6779  return true;
6780 
6781  /* Reset variables that might be set by hook */
6782  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
6783  GUC_check_errmsg_string = NULL;
6785  GUC_check_errhint_string = NULL;
6786 
6787  if (!conf->check_hook(newval, extra, source))
6788  {
6789  ereport(elevel,
6793  errmsg("invalid value for parameter \"%s\": \"%s\"",
6794  conf->gen.name,
6799  errhint("%s", GUC_check_errhint_string) : 0));
6800  /* Flush any strings created in ErrorContext */
6801  FlushErrorState();
6802  return false;
6803  }
6804 
6805  return true;
6806 }
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:2976
GucEnumCheckHook check_hook
Definition: guc_tables.h:264

References config_enum::check_hook, config_enum_lookup_by_value(), ereport, errcode(), errdetail_internal(), errhint(), errmsg(), errmsg_internal(), config_generic::extra, FlushErrorState(), config_enum::gen, GUC_check_errcode_value, GUC_check_errdetail_string, GUC_check_errhint_string, GUC_check_errmsg_string, config_generic::name, newval, and source.

Referenced by InitializeOneGUCOption(), parse_and_validate_value(), and set_config_option_ext().

◆ call_int_check_hook()

static bool call_int_check_hook ( struct config_int conf,
int *  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

Definition at line 6656 of file guc.c.

6658 {
6659  /* Quick success if no hook */
6660  if (!conf->check_hook)
6661  return true;
6662 
6663  /* Reset variables that might be set by hook */
6664  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
6665  GUC_check_errmsg_string = NULL;
6667  GUC_check_errhint_string = NULL;
6668 
6669  if (!conf->check_hook(newval, extra, source))
6670  {
6671  ereport(elevel,
6675  errmsg("invalid value for parameter \"%s\": %d",
6676  conf->gen.name, *newval),
6680  errhint("%s", GUC_check_errhint_string) : 0));
6681  /* Flush any strings created in ErrorContext */
6682  FlushErrorState();
6683  return false;
6684  }
6685 
6686  return true;
6687 }
GucIntCheckHook check_hook
Definition: guc_tables.h:219

References config_int::check_hook, ereport, errcode(), errdetail_internal(), errhint(), errmsg(), errmsg_internal(), config_generic::extra, FlushErrorState(), config_int::gen, GUC_check_errcode_value, GUC_check_errdetail_string, GUC_check_errhint_string, GUC_check_errmsg_string, config_generic::name, newval, and source.

Referenced by InitializeOneGUCOption(), parse_and_validate_value(), and set_config_option_ext().

◆ call_real_check_hook()

static bool call_real_check_hook ( struct config_real conf,
double *  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

Definition at line 6690 of file guc.c.

6692 {
6693  /* Quick success if no hook */
6694  if (!conf->check_hook)
6695  return true;
6696 
6697  /* Reset variables that might be set by hook */
6698  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
6699  GUC_check_errmsg_string = NULL;
6701  GUC_check_errhint_string = NULL;
6702 
6703  if (!conf->check_hook(newval, extra, source))
6704  {
6705  ereport(elevel,
6709  errmsg("invalid value for parameter \"%s\": %g",
6710  conf->gen.name, *newval),
6714  errhint("%s", GUC_check_errhint_string) : 0));
6715  /* Flush any strings created in ErrorContext */
6716  FlushErrorState();
6717  return false;
6718  }
6719 
6720  return true;
6721 }
GucRealCheckHook check_hook
Definition: guc_tables.h:235

References config_real::check_hook, ereport, errcode(), errdetail_internal(), errhint(), errmsg(), errmsg_internal(), config_generic::extra, FlushErrorState(), config_real::gen, GUC_check_errcode_value, GUC_check_errdetail_string, GUC_check_errhint_string, GUC_check_errmsg_string, config_generic::name, newval, and source.

Referenced by InitializeOneGUCOption(), parse_and_validate_value(), and set_config_option_ext().

◆ call_string_check_hook()

static bool call_string_check_hook ( struct config_string conf,
char **  newval,
void **  extra,
GucSource  source,
int  elevel 
)
static

Definition at line 6724 of file guc.c.

6726 {
6727  volatile bool result = true;
6728 
6729  /* Quick success if no hook */
6730  if (!conf->check_hook)
6731  return true;
6732 
6733  /*
6734  * If elevel is ERROR, or if the check_hook itself throws an elog
6735  * (undesirable, but not always avoidable), make sure we don't leak the
6736  * already-malloc'd newval string.
6737  */
6738  PG_TRY();
6739  {
6740  /* Reset variables that might be set by hook */
6741  GUC_check_errcode_value = ERRCODE_INVALID_PARAMETER_VALUE;
6742  GUC_check_errmsg_string = NULL;
6744  GUC_check_errhint_string = NULL;
6745 
6746  if (!conf->check_hook(newval, extra, source))
6747  {
6748  ereport(elevel,
6752  errmsg("invalid value for parameter \"%s\": \"%s\"",
6753  conf->gen.name, *newval ? *newval : ""),
6757  errhint("%s", GUC_check_errhint_string) : 0));
6758  /* Flush any strings created in ErrorContext */
6759  FlushErrorState();
6760  result = false;
6761  }
6762  }
6763  PG_CATCH();
6764  {
6765  guc_free(*newval);
6766  PG_RE_THROW();
6767  }
6768  PG_END_TRY();
6769 
6770  return result;
6771 }
GucStringCheckHook check_hook
Definition: guc_tables.h:249

References config_string::check_hook, ereport, errcode(), errdetail_internal(), errhint(), errmsg(), errmsg_internal(), config_generic::extra, FlushErrorState(), config_string::gen, GUC_check_errcode_value, GUC_check_errdetail_string, GUC_check_errhint_string, GUC_check_errmsg_string, guc_free(), config_generic::name, newval, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, and source.

Referenced by InitializeOneGUCOption(), parse_and_validate_value(), and set_config_option_ext().

◆ can_skip_gucvar()

static bool can_skip_gucvar ( struct config_generic gconf)
static

Definition at line 5632 of file guc.c.

5633 {
5634  /*
5635  * We can skip GUCs that are guaranteed to have the same values in leaders
5636  * and workers. (Note it is critical that the leader and worker have the
5637  * same idea of which GUCs fall into this category. It's okay to consider
5638  * context and name for this purpose, since those are unchanging
5639  * properties of a GUC.)
5640  *
5641  * PGC_POSTMASTER variables always have the same value in every child of a
5642  * particular postmaster, so the worker will certainly have the right
5643  * value already. Likewise, PGC_INTERNAL variables are set by special
5644  * mechanisms (if indeed they aren't compile-time constants). So we may
5645  * always skip these.
5646  *
5647  * Role must be handled specially because its current value can be an
5648  * invalid value (for instance, if someone dropped the role since we set
5649  * it). So if we tried to serialize it normally, we might get a failure.
5650  * We skip it here, and use another mechanism to ensure the worker has the
5651  * right value.
5652  *
5653  * For all other GUCs, we skip if the GUC has its compiled-in default
5654  * value (i.e., source == PGC_S_DEFAULT). On the leader side, this means
5655  * we don't send GUCs that have their default values, which typically
5656  * saves lots of work. On the worker side, this means we don't need to
5657  * reset the GUC to default because it already has that value. See
5658  * comments in RestoreGUCState for more info.
5659  */
5660  return gconf->context == PGC_POSTMASTER ||
5661  gconf->context == PGC_INTERNAL || gconf->source == PGC_S_DEFAULT ||
5662  strcmp(gconf->name, "role") == 0;
5663 }
@ PGC_S_DEFAULT
Definition: guc.h:109
@ PGC_POSTMASTER
Definition: guc.h:70
GucSource source
Definition: guc_tables.h:164

References config_generic::context, config_generic::name, PGC_INTERNAL, PGC_POSTMASTER, PGC_S_DEFAULT, and config_generic::source.

Referenced by estimate_variable_size(), RestoreGUCState(), and serialize_variable().

◆ check_GUC_name_for_parameter_acl()

bool check_GUC_name_for_parameter_acl ( const char *  name)

Definition at line 1375 of file guc.c.

1376 {
1377  /* OK if the GUC exists. */
1378  if (find_option(name, false, true, DEBUG1) != NULL)
1379  return true;
1380  /* Otherwise, it'd better be a valid custom GUC name. */
1382  return true;
1383  return false;
1384 }
#define DEBUG1
Definition: elog.h:30
static bool valid_custom_variable_name(const char *name)
Definition: guc.c:1069

References DEBUG1, find_option(), name, and valid_custom_variable_name().

Referenced by ParameterAclCreate().

◆ config_enum_get_options()

char* config_enum_get_options ( struct config_enum record,
const char *  prefix,
const char *  suffix,
const char *  separator 
)

Definition at line 3025 of file guc.c.

3027 {
3028  const struct config_enum_entry *entry;
3029  StringInfoData retstr;
3030  int seplen;
3031 
3032  initStringInfo(&retstr);
3033  appendStringInfoString(&retstr, prefix);
3034 
3035  seplen = strlen(separator);
3036  for (entry = record->options; entry && entry->name; entry++)
3037  {
3038  if (!entry->hidden)
3039  {
3040  appendStringInfoString(&retstr, entry->name);
3041  appendBinaryStringInfo(&retstr, separator, seplen);
3042  }
3043  }
3044 
3045  /*
3046  * All the entries may have been hidden, leaving the string empty if no
3047  * prefix was given. This indicates a broken GUC setup, since there is no
3048  * use for an enum without any values, so we just check to make sure we
3049  * don't write to invalid memory instead of actually trying to do
3050  * something smart with it.
3051  */
3052  if (retstr.len >= seplen)
3053  {
3054  /* Replace final separator */
3055  retstr.data[retstr.len - seplen] = '\0';
3056  retstr.len -= seplen;
3057  }
3058 
3059  appendStringInfoString(&retstr, suffix);
3060 
3061  return retstr.data;
3062 }
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
Definition: stringinfo.c:227
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:176
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
Definition: guc.h:168
const char * name
Definition: guc.h:169
bool hidden
Definition: guc.h:171
const struct config_enum_entry * options
Definition: guc_tables.h:263

References appendBinaryStringInfo(), appendStringInfoString(), StringInfoData::data, config_enum_entry::hidden, initStringInfo(), StringInfoData::len, config_enum_entry::name, and config_enum::options.

Referenced by GetConfigOptionValues(), and parse_and_validate_value().

◆ config_enum_lookup_by_name()

bool config_enum_lookup_by_name ( struct config_enum record,
const char *  value,
int *  retval 
)

Definition at line 2999 of file guc.c.

3001 {
3002  const struct config_enum_entry *entry;
3003 
3004  for (entry = record->options; entry && entry->name; entry++)
3005  {
3006  if (pg_strcasecmp(value, entry->name) == 0)
3007  {
3008  *retval = entry->val;
3009  return true;
3010  }
3011  }
3012 
3013  *retval = 0;
3014  return false;
3015 }
int pg_strcasecmp(const char *s1, const char *s2)
Definition: pgstrcasecmp.c:36
int val
Definition: guc.h:170

References config_enum_entry::name, config_enum::options, pg_strcasecmp(), config_enum_entry::val, and value.

Referenced by parse_and_validate_value().

◆ config_enum_lookup_by_value()

const char* config_enum_lookup_by_value ( struct config_enum record,
int  val 
)

Definition at line 2976 of file guc.c.

2977 {
2978  const struct config_enum_entry *entry;
2979 
2980  for (entry = record->options; entry && entry->name; entry++)
2981  {
2982  if (entry->val == val)
2983  return entry->name;
2984  }
2985 
2986  elog(ERROR, "could not find enum option %d for %s",
2987  val, record->gen.name);
2988  return NULL; /* silence compiler */
2989 }
long val
Definition: informix.c:664

References elog(), ERROR, config_enum::gen, config_enum_entry::name, config_generic::name, config_enum::options, config_enum_entry::val, and val.

Referenced by call_enum_check_hook(), estimate_variable_size(), GetConfigOption(), GetConfigOptionResetString(), GetConfigOptionValues(), serialize_variable(), and ShowGUCOption().

◆ convert_GUC_name_for_parameter_acl()

char* convert_GUC_name_for_parameter_acl ( const char *  name)

Definition at line 1339 of file guc.c.

1340 {
1341  char *result;
1342 
1343  /* Apply old-GUC-name mapping. */
1344  for (int i = 0; map_old_guc_names[i] != NULL; i += 2)
1345  {
1347  {
1348  name = map_old_guc_names[i + 1];
1349  break;
1350  }
1351  }
1352 
1353  /* Apply case-folding that matches guc_name_compare(). */
1354  result = pstrdup(name);
1355  for (char *ptr = result; *ptr != '\0'; ptr++)
1356  {
1357  char ch = *ptr;
1358 
1359  if (ch >= 'A' && ch <= 'Z')
1360  {
1361  ch += 'a' - 'A';
1362  *ptr = ch;
1363  }
1364  }
1365 
1366  return result;
1367 }
static const char *const map_old_guc_names[]
Definition: guc.c:186
int guc_name_compare(const char *namea, const char *nameb)
Definition: guc.c:1265
char * pstrdup(const char *in)
Definition: mcxt.c:1644

References guc_name_compare(), i, map_old_guc_names, name, and pstrdup().

Referenced by ParameterAclCreate(), ParameterAclLookup(), and pg_parameter_aclmask().

◆ convert_int_from_base_unit()

static void convert_int_from_base_unit ( int64  base_value,
int  base_unit,
int64 *  value,
const char **  unit 
)
static

Definition at line 2682 of file guc.c.

2684 {
2685  const unit_conversion *table;
2686  int i;
2687 
2688  *unit = NULL;
2689 
2690  if (base_unit & GUC_UNIT_MEMORY)
2692  else
2694 
2695  for (i = 0; *table[i].unit; i++)
2696  {
2697  if (base_unit == table[i].base_unit)
2698  {
2699  /*
2700  * Accept the first conversion that divides the value evenly. We
2701  * assume that the conversions for each base unit are ordered from
2702  * greatest unit to the smallest!
2703  */
2704  if (table[i].multiplier <= 1.0 ||
2705  base_value % (int64) table[i].multiplier == 0)
2706  {
2707  *value = (int64) rint(base_value / table[i].multiplier);
2708  *unit = table[i].unit;
2709  break;
2710  }
2711  }
2712  }
2713 
2714  Assert(*unit != NULL);
2715 }
static const unit_conversion memory_unit_conversion_table[]
Definition: guc.c:117
static const unit_conversion time_unit_conversion_table[]
Definition: guc.c:154
#define GUC_UNIT_MEMORY
Definition: guc.h:230
char unit[MAX_UNIT_LEN+1]
Definition: guc.c:101

References Assert(), GUC_UNIT_MEMORY, i, memory_unit_conversion_table, time_unit_conversion_table, unit_conversion::unit, and value.

Referenced by ShowGUCOption().

◆ convert_real_from_base_unit()

static void convert_real_from_base_unit ( double  base_value,
int  base_unit,
double *  value,
const char **  unit 
)
static

Definition at line 2724 of file guc.c.

2726 {
2727  const unit_conversion *table;
2728  int i;
2729 
2730  *unit = NULL;
2731 
2732  if (base_unit & GUC_UNIT_MEMORY)
2734  else
2736 
2737  for (i = 0; *table[i].unit; i++)
2738  {
2739  if (base_unit == table[i].base_unit)
2740  {
2741  /*
2742  * Accept the first conversion that divides the value evenly; or
2743  * if there is none, use the smallest (last) target unit.
2744  *
2745  * What we actually care about here is whether snprintf with "%g"
2746  * will print the value as an integer, so the obvious test of
2747  * "*value == rint(*value)" is too strict; roundoff error might
2748  * make us choose an unreasonably small unit. As a compromise,
2749  * accept a divisor that is within 1e-8 of producing an integer.
2750  */
2751  *value = base_value / table[i].multiplier;
2752  *unit = table[i].unit;
2753  if (*value > 0 &&
2754  fabs((rint(*value) / *value) - 1.0) <= 1e-8)
2755  break;
2756  }
2757  }
2758 
2759  Assert(*unit != NULL);
2760 }
e
Definition: preproc-init.c:82
double multiplier
Definition: guc.c:104

References Assert(), GUC_UNIT_MEMORY, i, memory_unit_conversion_table, unit_conversion::multiplier, time_unit_conversion_table, unit_conversion::unit, and value.

Referenced by ShowGUCOption().

◆ convert_to_base_unit()

static bool convert_to_base_unit ( double  value,
const char *  unit,
int  base_unit,
double *  base_value 
)
static

Definition at line 2624 of file guc.c.

2626 {
2627  char unitstr[MAX_UNIT_LEN + 1];
2628  int unitlen;
2629  const unit_conversion *table;
2630  int i;
2631 
2632  /* extract unit string to compare to table entries */
2633  unitlen = 0;
2634  while (*unit != '\0' && !isspace((unsigned char) *unit) &&
2635  unitlen < MAX_UNIT_LEN)
2636  unitstr[unitlen++] = *(unit++);
2637  unitstr[unitlen] = '\0';
2638  /* allow whitespace after unit */
2639  while (isspace((unsigned char) *unit))
2640  unit++;
2641  if (*unit != '\0')
2642  return false; /* unit too long, or garbage after it */
2643 
2644  /* now search the appropriate table */
2645  if (base_unit & GUC_UNIT_MEMORY)
2647  else
2649 
2650  for (i = 0; *table[i].unit; i++)
2651  {
2652  if (base_unit == table[i].base_unit &&
2653  strcmp(unitstr, table[i].unit) == 0)
2654  {
2655  double cvalue = value * table[i].multiplier;
2656 
2657  /*
2658  * If the user gave a fractional value such as "30.1GB", round it
2659  * off to the nearest multiple of the next smaller unit, if there
2660  * is one.
2661  */
2662  if (*table[i + 1].unit &&
2663  base_unit == table[i + 1].base_unit)
2664  cvalue = rint(cvalue / table[i + 1].multiplier) *
2665  table[i + 1].multiplier;
2666 
2667  *base_value = cvalue;
2668  return true;
2669  }
2670  }
2671  return false;
2672 }
#define MAX_UNIT_LEN
Definition: guc.c:97

References GUC_UNIT_MEMORY, i, MAX_UNIT_LEN, memory_unit_conversion_table, unit_conversion::multiplier, time_unit_conversion_table, unit_conversion::unit, and value.

Referenced by parse_int(), and parse_real().

◆ define_custom_variable()

static void define_custom_variable ( struct config_generic variable)
static

Definition at line 4757 of file guc.c.

4758 {
4759  const char *name = variable->name;
4760  GUCHashEntry *hentry;
4761  struct config_string *pHolder;
4762 
4763  /* Check mapping between initial and default value */
4764  Assert(check_GUC_init(variable));
4765 
4766  /*
4767  * See if there's a placeholder by the same name.
4768  */
4769  hentry = (GUCHashEntry *) hash_search(guc_hashtab,
4770  &name,
4771  HASH_FIND,
4772  NULL);
4773  if (hentry == NULL)
4774  {
4775  /*
4776  * No placeholder to replace, so we can just add it ... but first,
4777  * make sure it's initialized to its default value.
4778  */
4781  return;
4782  }
4783 
4784  /*
4785  * This better be a placeholder
4786  */
4787  if ((hentry->gucvar->flags & GUC_CUSTOM_PLACEHOLDER) == 0)
4788  ereport(ERROR,
4789  (errcode(ERRCODE_INTERNAL_ERROR),
4790  errmsg("attempt to redefine parameter \"%s\"", name)));
4791 
4792  Assert(hentry->gucvar->vartype == PGC_STRING);
4793  pHolder = (struct config_string *) hentry->gucvar;
4794 
4795  /*
4796  * First, set the variable to its default value. We must do this even
4797  * though we intend to immediately apply a new value, since it's possible
4798  * that the new value is invalid.
4799  */
4801 
4802  /*
4803  * Replace the placeholder in the hash table. We aren't changing the name
4804  * (at least up to case-folding), so the hash value is unchanged.
4805  */
4806  hentry->gucname = name;
4807  hentry->gucvar = variable;
4808 
4809  /*
4810  * Remove the placeholder from any lists it's in, too.
4811  */
4812  RemoveGUCFromLists(&pHolder->gen);
4813 
4814  /*
4815  * Assign the string value(s) stored in the placeholder to the real
4816  * variable. Essentially, we need to duplicate all the active and stacked
4817  * values, but with appropriate validation and datatype adjustment.
4818  *
4819  * If an assignment fails, we report a WARNING and keep going. We don't
4820  * want to throw ERROR for bad values, because it'd bollix the add-on
4821  * module that's presumably halfway through getting loaded. In such cases
4822  * the default or previous state will become active instead.
4823  */
4824 
4825  /* First, apply the reset value if any */
4826  if (pHolder->reset_val)
4827  (void) set_config_option_ext(name, pHolder->reset_val,
4828  pHolder->gen.reset_scontext,
4829  pHolder->gen.reset_source,
4830  pHolder->gen.reset_srole,
4831  GUC_ACTION_SET, true, WARNING, false);
4832  /* That should not have resulted in stacking anything */
4833  Assert(variable->stack == NULL);
4834 
4835  /* Now, apply current and stacked values, in the order they were stacked */
4836  reapply_stacked_values(variable, pHolder, pHolder->gen.stack,
4837  *(pHolder->variable),
4838  pHolder->gen.scontext, pHolder->gen.source,
4839  pHolder->gen.srole);
4840 
4841  /* Also copy over any saved source-location information */
4842  if (pHolder->gen.sourcefile)
4844  pHolder->gen.sourceline);
4845 
4846  /*
4847  * Free up as much as we conveniently can of the placeholder structure.
4848  * (This neglects any stack items, so it's possible for some memory to be
4849  * leaked. Since this can only happen once per session per variable, it
4850  * doesn't seem worth spending much code on.)
4851  */
4852  set_string_field(pHolder, pHolder->variable, NULL);
4853  set_string_field(pHolder, &pHolder->reset_val, NULL);
4854 
4855  guc_free(pHolder);
4856 }
int set_config_option_ext(const char *name, const char *value, GucContext context, GucSource source, Oid srole, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:3324
static void set_config_sourcefile(const char *name, char *sourcefile, int sourceline)
Definition: guc.c:4143
static void reapply_stacked_values(struct config_generic *variable, struct config_string *pHolder, GucStack *stack, const char *curvalue, GucContext curscontext, GucSource cursource, Oid cursrole)
Definition: guc.c:4866
static void InitializeOneGUCOption(struct config_generic *gconf)
Definition: guc.c:1609
static void RemoveGUCFromLists(struct config_generic *gconf)
Definition: guc.c:1726
@ GUC_ACTION_SET
Definition: guc.h:197
@ HASH_FIND
Definition: hsearch.h:113
const char * gucname
Definition: guc.c:203
char * sourcefile
Definition: guc_tables.h:180
GucContext reset_scontext
Definition: guc_tables.h:167
GucSource reset_source
Definition: guc_tables.h:165
char * reset_val
Definition: guc_tables.h:253
char * name
Definition: type.h:178

References add_guc_variable(), Assert(), ereport, errcode(), errmsg(), ERROR, config_generic::flags, config_string::gen, GUC_ACTION_SET, GUC_CUSTOM_PLACEHOLDER, guc_free(), guc_hashtab, GUCHashEntry::gucname, GUCHashEntry::gucvar, HASH_FIND, hash_search(), InitializeOneGUCOption(), name, variable::name, PGC_STRING, reapply_stacked_values(), RemoveGUCFromLists(), config_generic::reset_scontext, config_generic::reset_source, config_generic::reset_srole, config_string::reset_val, config_generic::scontext, set_config_option_ext(), set_config_sourcefile(), set_string_field(), config_generic::source, config_generic::sourcefile, config_generic::sourceline, config_generic::srole, config_generic::stack, config_string::variable, config_generic::vartype, and WARNING.

Referenced by DefineCustomBoolVariable(), DefineCustomEnumVariable(), DefineCustomIntVariable(), DefineCustomRealVariable(), and DefineCustomStringVariable().

◆ DefineCustomBoolVariable()

void DefineCustomBoolVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
bool valueAddr,
bool  bootValue,
GucContext  context,
int  flags,
GucBoolCheckHook  check_hook,
GucBoolAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 4958 of file guc.c.

4968 {
4969  struct config_bool *var;
4970 
4971  var = (struct config_bool *)
4972  init_custom_variable(name, short_desc, long_desc, context, flags,
4973  PGC_BOOL, sizeof(struct config_bool));
4974  var->variable = valueAddr;
4975  var->boot_val = bootValue;
4976  var->reset_val = bootValue;
4977  var->check_hook = check_hook;
4978  var->assign_hook = assign_hook;
4979  var->show_hook = show_hook;
4980  define_custom_variable(&var->gen);
4981 }
static struct config_generic * init_custom_variable(const char *name, const char *short_desc, const char *long_desc, GucContext context, int flags, enum config_type type, size_t sz)
Definition: guc.c:4697
static void define_custom_variable(struct config_generic *variable)
Definition: guc.c:4757
bool reset_val
Definition: guc_tables.h:207
bool boot_val
Definition: guc_tables.h:202
GucShowHook show_hook
Definition: guc_tables.h:205

References config_bool::assign_hook, config_bool::boot_val, config_bool::check_hook, define_custom_variable(), config_bool::gen, init_custom_variable(), name, PGC_BOOL, config_bool::reset_val, config_bool::show_hook, and config_bool::variable.

Referenced by _PG_init().

◆ DefineCustomEnumVariable()

void DefineCustomEnumVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
int *  valueAddr,
int  bootValue,
const struct config_enum_entry options,
GucContext  context,
int  flags,
GucEnumCheckHook  check_hook,
GucEnumAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 5069 of file guc.c.

5080 {
5081  struct config_enum *var;
5082 
5083  var = (struct config_enum *)
5084  init_custom_variable(name, short_desc, long_desc, context, flags,
5085  PGC_ENUM, sizeof(struct config_enum));
5086  var->variable = valueAddr;
5087  var->boot_val = bootValue;
5088  var->reset_val = bootValue;
5089  var->options = options;
5090  var->check_hook = check_hook;
5091  var->assign_hook = assign_hook;
5092  var->show_hook = show_hook;
5093  define_custom_variable(&var->gen);
5094 }
static char ** options
GucShowHook show_hook
Definition: guc_tables.h:266

References config_enum::assign_hook, config_enum::boot_val, config_enum::check_hook, define_custom_variable(), config_enum::gen, init_custom_variable(), name, options, config_enum::options, PGC_ENUM, config_enum::reset_val, config_enum::show_hook, and config_enum::variable.

Referenced by _PG_init().

◆ DefineCustomIntVariable()

void DefineCustomIntVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
int *  valueAddr,
int  bootValue,
int  minValue,
int  maxValue,
GucContext  context,
int  flags,
GucIntCheckHook  check_hook,
GucIntAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 4984 of file guc.c.

4996 {
4997  struct config_int *var;
4998 
4999  var = (struct config_int *)
5000  init_custom_variable(name, short_desc, long_desc, context, flags,
5001  PGC_INT, sizeof(struct config_int));
5002  var->variable = valueAddr;
5003  var->boot_val = bootValue;
5004  var->reset_val = bootValue;
5005  var->min = minValue;
5006  var->max = maxValue;
5007  var->check_hook = check_hook;
5008  var->assign_hook = assign_hook;
5009  var->show_hook = show_hook;
5010  define_custom_variable(&var->gen);
5011 }
int reset_val
Definition: guc_tables.h:223
int boot_val
Definition: guc_tables.h:216
GucShowHook show_hook
Definition: guc_tables.h:221

References config_int::assign_hook, config_int::boot_val, config_int::check_hook, define_custom_variable(), config_int::gen, init_custom_variable(), config_int::max, config_int::min, name, PGC_INT, config_int::reset_val, config_int::show_hook, and config_int::variable.

Referenced by _PG_init().

◆ DefineCustomRealVariable()

void DefineCustomRealVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
double *  valueAddr,
double  bootValue,
double  minValue,
double  maxValue,
GucContext  context,
int  flags,
GucRealCheckHook  check_hook,
GucRealAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 5014 of file guc.c.

5026 {
5027  struct config_real *var;
5028 
5029  var = (struct config_real *)
5030  init_custom_variable(name, short_desc, long_desc, context, flags,
5031  PGC_REAL, sizeof(struct config_real));
5032  var->variable = valueAddr;
5033  var->boot_val = bootValue;
5034  var->reset_val = bootValue;
5035  var->min = minValue;
5036  var->max = maxValue;
5037  var->check_hook = check_hook;
5038  var->assign_hook = assign_hook;
5039  var->show_hook = show_hook;
5040  define_custom_variable(&var->gen);
5041 }
double boot_val
Definition: guc_tables.h:232
double reset_val
Definition: guc_tables.h:239
double min
Definition: guc_tables.h:233
double max
Definition: guc_tables.h:234
GucShowHook show_hook
Definition: guc_tables.h:237

References config_real::assign_hook, config_real::boot_val, config_real::check_hook, define_custom_variable(), config_real::gen, init_custom_variable(), config_real::max, config_real::min, name, PGC_REAL, config_real::reset_val, config_real::show_hook, and config_real::variable.

Referenced by _PG_init().

◆ DefineCustomStringVariable()

void DefineCustomStringVariable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
char **  valueAddr,
const char *  bootValue,
GucContext  context,
int  flags,
GucStringCheckHook  check_hook,
GucStringAssignHook  assign_hook,
GucShowHook  show_hook 
)

Definition at line 5044 of file guc.c.

5054 {
5055  struct config_string *var;
5056 
5057  var = (struct config_string *)
5058  init_custom_variable(name, short_desc, long_desc, context, flags,
5059  PGC_STRING, sizeof(struct config_string));
5060  var->variable = valueAddr;
5061  var->boot_val = bootValue;
5062  var->check_hook = check_hook;
5063  var->assign_hook = assign_hook;
5064  var->show_hook = show_hook;
5065  define_custom_variable(&var->gen);
5066 }
GucShowHook show_hook
Definition: guc_tables.h:251
const char * boot_val
Definition: guc_tables.h:248

References config_string::assign_hook, config_string::boot_val, config_string::check_hook, define_custom_variable(), config_string::gen, init_custom_variable(), name, PGC_STRING, config_string::show_hook, and config_string::variable.

Referenced by _PG_init().

◆ discard_stack_value()

static void discard_stack_value ( struct config_generic gconf,
config_var_value val 
)
static

Definition at line 839 of file guc.c.

840 {
841  switch (gconf->vartype)
842  {
843  case PGC_BOOL:
844  case PGC_INT:
845  case PGC_REAL:
846  case PGC_ENUM:
847  /* no need to do anything */
848  break;
849  case PGC_STRING:
850  set_string_field((struct config_string *) gconf,
851  &(val->val.stringval),
852  NULL);
853  break;
854  }
855  set_extra_field(gconf, &(val->extra), NULL);
856 }

References PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, set_extra_field(), set_string_field(), val, and config_generic::vartype.

Referenced by AtEOXact_GUC(), and push_old_value().

◆ do_serialize()

static void do_serialize ( char **  destptr,
Size maxbytes,
const char *  fmt,
  ... 
)
static

Definition at line 5803 of file guc.c.

5804 {
5805  va_list vargs;
5806  int n;
5807 
5808  if (*maxbytes <= 0)
5809  elog(ERROR, "not enough space to serialize GUC state");
5810 
5811  va_start(vargs, fmt);
5812  n = vsnprintf(*destptr, *maxbytes, fmt, vargs);
5813  va_end(vargs);
5814 
5815  if (n < 0)
5816  {
5817  /* Shouldn't happen. Better show errno description. */
5818  elog(ERROR, "vsnprintf failed: %m with format string \"%s\"", fmt);
5819  }
5820  if (n >= *maxbytes)
5821  {
5822  /* This shouldn't happen either, really. */
5823  elog(ERROR, "not enough space to serialize GUC state");
5824  }
5825 
5826  /* Shift the destptr ahead of the null terminator */
5827  *destptr += n + 1;
5828  *maxbytes -= n + 1;
5829 }
static void const char * fmt
va_end(args)
va_start(args, fmt)
#define vsnprintf
Definition: port.h:237

References elog(), ERROR, fmt, va_end(), va_start(), and vsnprintf.

Referenced by serialize_variable().

◆ do_serialize_binary()

static void do_serialize_binary ( char **  destptr,
Size maxbytes,
void *  val,
Size  valsize 
)
static

Definition at line 5833 of file guc.c.

5834 {
5835  if (valsize > *maxbytes)
5836  elog(ERROR, "not enough space to serialize GUC state");
5837 
5838  memcpy(*destptr, val, valsize);
5839  *destptr += valsize;
5840  *maxbytes -= valsize;
5841 }

References elog(), ERROR, and val.

Referenced by serialize_variable().

◆ estimate_variable_size()

static Size estimate_variable_size ( struct config_generic gconf)
static

Definition at line 5672 of file guc.c.

5673 {
5674  Size size;
5675  Size valsize = 0;
5676 
5677  /* Skippable GUCs consume zero space. */
5678  if (can_skip_gucvar(gconf))
5679  return 0;
5680 
5681  /* Name, plus trailing zero byte. */
5682  size = strlen(gconf->name) + 1;
5683 
5684  /* Get the maximum display length of the GUC value. */
5685  switch (gconf->vartype)
5686  {
5687  case PGC_BOOL:
5688  {
5689  valsize = 5; /* max(strlen('true'), strlen('false')) */
5690  }
5691  break;
5692 
5693  case PGC_INT:
5694  {
5695  struct config_int *conf = (struct config_int *) gconf;
5696 
5697  /*
5698  * Instead of getting the exact display length, use max
5699  * length. Also reduce the max length for typical ranges of
5700  * small values. Maximum value is 2147483647, i.e. 10 chars.
5701  * Include one byte for sign.
5702  */
5703  if (abs(*conf->variable) < 1000)
5704  valsize = 3 + 1;
5705  else
5706  valsize = 10 + 1;
5707  }
5708  break;
5709 
5710  case PGC_REAL:
5711  {
5712  /*
5713  * We are going to print it with %e with REALTYPE_PRECISION
5714  * fractional digits. Account for sign, leading digit,
5715  * decimal point, and exponent with up to 3 digits. E.g.
5716  * -3.99329042340000021e+110
5717  */
5718  valsize = 1 + 1 + 1 + REALTYPE_PRECISION + 5;
5719  }
5720  break;
5721 
5722  case PGC_STRING:
5723  {
5724  struct config_string *conf = (struct config_string *) gconf;
5725 
5726  /*
5727  * If the value is NULL, we transmit it as an empty string.
5728  * Although this is not physically the same value, GUC
5729  * generally treats a NULL the same as empty string.
5730  */
5731  if (*conf->variable)
5732  valsize = strlen(*conf->variable);
5733  else
5734  valsize = 0;
5735  }
5736  break;
5737 
5738  case PGC_ENUM:
5739  {
5740  struct config_enum *conf = (struct config_enum *) gconf;
5741 
5742  valsize = strlen(config_enum_lookup_by_value(conf, *conf->variable));
5743  }
5744  break;
5745  }
5746 
5747  /* Allow space for terminating zero-byte for value */
5748  size = add_size(size, valsize + 1);
5749 
5750  if (gconf->sourcefile)
5751  size = add_size(size, strlen(gconf->sourcefile));
5752 
5753  /* Allow space for terminating zero-byte for sourcefile */
5754  size = add_size(size, 1);
5755 
5756  /* Include line whenever file is nonempty. */
5757  if (gconf->sourcefile && gconf->sourcefile[0])
5758  size = add_size(size, sizeof(gconf->sourceline));
5759 
5760  size = add_size(size, sizeof(gconf->source));
5761  size = add_size(size, sizeof(gconf->scontext));
5762  size = add_size(size, sizeof(gconf->srole));
5763 
5764  return size;
5765 }
size_t Size
Definition: c.h:594
static bool can_skip_gucvar(struct config_generic *gconf)
Definition: guc.c:5632
#define REALTYPE_PRECISION
Definition: guc.c:67
Size add_size(Size s1, Size s2)
Definition: shmem.c:502

References add_size(), can_skip_gucvar(), config_enum_lookup_by_value(), config_generic::name, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, REALTYPE_PRECISION, config_generic::scontext, config_generic::source, config_generic::sourcefile, config_generic::sourceline, config_generic::srole, config_int::variable, config_string::variable, config_enum::variable, and config_generic::vartype.

Referenced by EstimateGUCStateSpace().

◆ EstimateGUCStateSpace()

Size EstimateGUCStateSpace ( void  )

Definition at line 5772 of file guc.c.

5773 {
5774  Size size;
5775  dlist_iter iter;
5776 
5777  /* Add space reqd for saving the data size of the guc state */
5778  size = sizeof(Size);
5779 
5780  /*
5781  * Add up the space needed for each GUC variable.
5782  *
5783  * We need only process non-default GUCs.
5784  */
5786  {
5787  struct config_generic *gconf = dlist_container(struct config_generic,
5788  nondef_link, iter.cur);
5789 
5790  size = add_size(size, estimate_variable_size(gconf));
5791  }
5792 
5793  return size;
5794 }
static dlist_head guc_nondef_list
Definition: guc.c:217
static Size estimate_variable_size(struct config_generic *gconf)
Definition: guc.c:5672
#define dlist_foreach(iter, lhead)
Definition: ilist.h:623
#define dlist_container(type, membername, ptr)
Definition: ilist.h:593
dlist_node nondef_link
Definition: guc_tables.h:172
dlist_node * cur
Definition: ilist.h:179

References add_size(), dlist_iter::cur, dlist_container, dlist_foreach, estimate_variable_size(), guc_nondef_list, and config_generic::nondef_link.

Referenced by InitializeParallelDSM().

◆ extra_field_used()

static bool extra_field_used ( struct config_generic gconf,
void *  extra 
)
static

Definition at line 740 of file guc.c.

741 {
742  GucStack *stack;
743 
744  if (extra == gconf->extra)
745  return true;
746  switch (gconf->vartype)
747  {
748  case PGC_BOOL:
749  if (extra == ((struct config_bool *) gconf)->reset_extra)
750  return true;
751  break;
752  case PGC_INT:
753  if (extra == ((struct config_int *) gconf)->reset_extra)
754  return true;
755  break;
756  case PGC_REAL:
757  if (extra == ((struct config_real *) gconf)->reset_extra)
758  return true;
759  break;
760  case PGC_STRING:
761  if (extra == ((struct config_string *) gconf)->reset_extra)
762  return true;
763  break;
764  case PGC_ENUM:
765  if (extra == ((struct config_enum *) gconf)->reset_extra)
766  return true;
767  break;
768  }
769  for (stack = gconf->stack; stack; stack = stack->prev)
770  {
771  if (extra == stack->prior.extra ||
772  extra == stack->masked.extra)
773  return true;
774  }
775 
776  return false;
777 }

References config_var_value::extra, config_generic::extra, guc_stack::masked, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, guc_stack::prev, guc_stack::prior, config_generic::stack, and config_generic::vartype.

Referenced by set_config_option_ext(), and set_extra_field().

◆ find_option()

struct config_generic* find_option ( const char *  name,
bool  create_placeholders,
bool  skip_errors,
int  elevel 
)

Definition at line 1163 of file guc.c.

1165 {
1166  GUCHashEntry *hentry;
1167  int i;
1168 
1169  Assert(name);
1170 
1171  /* Look it up using the hash table. */
1172  hentry = (GUCHashEntry *) hash_search(guc_hashtab,
1173  &name,
1174  HASH_FIND,
1175  NULL);
1176  if (hentry)
1177  return hentry->gucvar;
1178 
1179  /*
1180  * See if the name is an obsolete name for a variable. We assume that the
1181  * set of supported old names is short enough that a brute-force search is
1182  * the best way.
1183  */
1184  for (i = 0; map_old_guc_names[i] != NULL; i += 2)
1185  {
1187  return find_option(map_old_guc_names[i + 1], false,
1188  skip_errors, elevel);
1189  }
1190 
1191  if (create_placeholders)
1192  {
1193  /*
1194  * Check if the name is valid, and if so, add a placeholder. If it
1195  * doesn't contain a separator, don't assume that it was meant to be a
1196  * placeholder.
1197  */
1198  const char *sep = strchr(name, GUC_QUALIFIER_SEPARATOR);
1199 
1200  if (sep != NULL)
1201  {
1202  size_t classLen = sep - name;
1203  ListCell *lc;
1204 
1205  /* The name must be syntactically acceptable ... */
1207  {
1208  if (!skip_errors)
1209  ereport(elevel,
1210  (errcode(ERRCODE_INVALID_NAME),
1211  errmsg("invalid configuration parameter name \"%s\"",
1212  name),
1213  errdetail("Custom parameter names must be two or more simple identifiers separated by dots.")));
1214  return NULL;
1215  }
1216  /* ... and it must not match any previously-reserved prefix */
1217  foreach(lc, reserved_class_prefix)
1218  {
1219  const char *rcprefix = lfirst(lc);
1220 
1221  if (strlen(rcprefix) == classLen &&
1222  strncmp(name, rcprefix, classLen) == 0)
1223  {
1224  if (!skip_errors)
1225  ereport(elevel,
1226  (errcode(ERRCODE_INVALID_NAME),
1227  errmsg("invalid configuration parameter name \"%s\"",
1228  name),
1229  errdetail("\"%s\" is a reserved prefix.",
1230  rcprefix)));
1231  return NULL;
1232  }
1233  }
1234  /* OK, create it */
1235  return add_placeholder_variable(name, elevel);
1236  }
1237  }
1238 
1239  /* Unknown name */
1240  if (!skip_errors)
1241  ereport(elevel,
1242  (errcode(ERRCODE_UNDEFINED_OBJECT),
1243  errmsg("unrecognized configuration parameter \"%s\"",
1244  name)));
1245  return NULL;
1246 }
int errdetail(const char *fmt,...)
Definition: elog.c:1202
static List * reserved_class_prefix
Definition: guc.c:71
static struct config_generic * add_placeholder_variable(const char *name, int elevel)
Definition: guc.c:1105
#define GUC_QUALIFIER_SEPARATOR
Definition: guc.h:202
#define lfirst(lc)
Definition: pg_list.h:172

References add_placeholder_variable(), Assert(), ereport, errcode(), errdetail(), errmsg(), guc_hashtab, guc_name_compare(), GUC_QUALIFIER_SEPARATOR, GUCHashEntry::gucvar, HASH_FIND, hash_search(), i, lfirst, map_old_guc_names, name, reserved_class_prefix, and valid_custom_variable_name().

Referenced by AlterSystemSetConfigFile(), check_GUC_name_for_parameter_acl(), flatten_set_variable_args(), GetConfigOption(), GetConfigOptionByName(), GetConfigOptionFlags(), GetConfigOptionResetString(), GUCArrayAdd(), GUCArrayDelete(), InitializeWalConsistencyChecking(), pg_settings_get_flags(), ProcessConfigFileInternal(), SelectConfigFiles(), set_config_option_ext(), set_config_sourcefile(), and validate_option_array_item().

◆ get_config_unit_name()

const char* get_config_unit_name ( int  flags)

Definition at line 2767 of file guc.c.

2768 {
2769  switch (flags & GUC_UNIT)
2770  {
2771  case 0:
2772  return NULL; /* GUC has no units */
2773  case GUC_UNIT_BYTE:
2774  return "B";
2775  case GUC_UNIT_KB:
2776  return "kB";
2777  case GUC_UNIT_MB:
2778  return "MB";
2779  case GUC_UNIT_BLOCKS:
2780  {
2781  static char bbuf[8];
2782 
2783  /* initialize if first time through */
2784  if (bbuf[0] == '\0')
2785  snprintf(bbuf, sizeof(bbuf), "%dkB", BLCKSZ / 1024);
2786  return bbuf;
2787  }
2788  case GUC_UNIT_XBLOCKS:
2789  {
2790  static char xbuf[8];
2791 
2792  /* initialize if first time through */
2793  if (xbuf[0] == '\0')
2794  snprintf(xbuf, sizeof(xbuf), "%dkB", XLOG_BLCKSZ / 1024);
2795  return xbuf;
2796  }
2797  case GUC_UNIT_MS:
2798  return "ms";
2799  case GUC_UNIT_S:
2800  return "s";
2801  case GUC_UNIT_MIN:
2802  return "min";
2803  default:
2804  elog(ERROR, "unrecognized GUC units value: %d",
2805  flags & GUC_UNIT);
2806  return NULL;
2807  }
2808 }
#define GUC_UNIT_MB
Definition: guc.h:228
#define GUC_UNIT
Definition: guc.h:237
#define GUC_UNIT_MS
Definition: guc.h:232
#define GUC_UNIT_BLOCKS
Definition: guc.h:226
#define GUC_UNIT_XBLOCKS
Definition: guc.h:227
#define GUC_UNIT_BYTE
Definition: guc.h:229
#define GUC_UNIT_S
Definition: guc.h:233
#define GUC_UNIT_KB
Definition: guc.h:225
#define GUC_UNIT_MIN
Definition: guc.h:234

References elog(), ERROR, config_generic::flags, GUC_UNIT, GUC_UNIT_BLOCKS, GUC_UNIT_BYTE, GUC_UNIT_KB, GUC_UNIT_MB, GUC_UNIT_MIN, GUC_UNIT_MS, GUC_UNIT_S, GUC_UNIT_XBLOCKS, and snprintf.

Referenced by GetConfigOptionValues(), and parse_and_validate_value().

◆ get_explain_guc_options()

struct config_generic** get_explain_guc_options ( int *  num)

Definition at line 5157 of file guc.c.

5158 {
5159  struct config_generic **result;
5160  dlist_iter iter;
5161 
5162  *num = 0;
5163 
5164  /*
5165  * While only a fraction of all the GUC variables are marked GUC_EXPLAIN,
5166  * it doesn't seem worth dynamically resizing this array.
5167  */
5168  result = palloc(sizeof(struct config_generic *) * hash_get_num_entries(guc_hashtab));
5169 
5170  /* We need only consider GUCs with source not PGC_S_DEFAULT */
5172  {
5173  struct config_generic *conf = dlist_container(struct config_generic,
5174  nondef_link, iter.cur);
5175  bool modified;
5176 
5177  /* return only parameters marked for inclusion in explain */
5178  if (!(conf->flags & GUC_EXPLAIN))
5179  continue;
5180 
5181  /* return only options visible to the current user */
5182  if (!ConfigOptionIsVisible(conf))
5183  continue;
5184 
5185  /* return only options that are different from their boot values */
5186  modified = false;
5187 
5188  switch (conf->vartype)
5189  {
5190  case PGC_BOOL:
5191  {
5192  struct config_bool *lconf = (struct config_bool *) conf;
5193 
5194  modified = (lconf->boot_val != *(lconf->variable));
5195  }
5196  break;
5197 
5198  case PGC_INT:
5199  {
5200  struct config_int *lconf = (struct config_int *) conf;
5201 
5202  modified = (lconf->boot_val != *(lconf->variable));
5203  }
5204  break;
5205 
5206  case PGC_REAL:
5207  {
5208  struct config_real *lconf = (struct config_real *) conf;
5209 
5210  modified = (lconf->boot_val != *(lconf->variable));
5211  }
5212  break;
5213 
5214  case PGC_STRING:
5215  {
5216  struct config_string *lconf = (struct config_string *) conf;
5217 
5218  modified = (strcmp(lconf->boot_val, *(lconf->variable)) != 0);
5219  }
5220  break;
5221 
5222  case PGC_ENUM:
5223  {
5224  struct config_enum *lconf = (struct config_enum *) conf;
5225 
5226  modified = (lconf->boot_val != *(lconf->variable));
5227  }
5228  break;
5229 
5230  default:
5231  elog(ERROR, "unexpected GUC type: %d", conf->vartype);
5232  }
5233 
5234  if (!modified)
5235  continue;
5236 
5237  /* OK, report it */
5238  result[*num] = conf;
5239  *num = *num + 1;
5240  }
5241 
5242  return result;
5243 }
#define GUC_EXPLAIN
Definition: guc.h:213
bool ConfigOptionIsVisible(struct config_generic *conf)
Definition: guc_funcs.c:581
void * palloc(Size size)
Definition: mcxt.c:1226

References config_bool::boot_val, config_int::boot_val, config_real::boot_val, config_string::boot_val, config_enum::boot_val, ConfigOptionIsVisible(), dlist_iter::cur, dlist_container, dlist_foreach, elog(), ERROR, config_generic::flags, GUC_EXPLAIN, guc_hashtab, guc_nondef_list, hash_get_num_entries(), config_generic::nondef_link, palloc(), PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, config_bool::variable, config_int::variable, config_real::variable, config_string::variable, config_enum::variable, and config_generic::vartype.

Referenced by ExplainPrintSettings().

◆ get_guc_variables()

struct config_generic** get_guc_variables ( int *  num_vars)

Definition at line 865 of file guc.c.

866 {
867  struct config_generic **result;
869  GUCHashEntry *hentry;
870  int i;
871 
872  *num_vars = hash_get_num_entries(guc_hashtab);
873  result = palloc(sizeof(struct config_generic *) * *num_vars);
874 
875  /* Extract pointers from the hash table */
876  i = 0;
878  while ((hentry = (GUCHashEntry *) hash_seq_search(&status)) != NULL)
879  result[i++] = hentry->gucvar;
880  Assert(i == *num_vars);
881 
882  /* Sort by name */
883  qsort(result, *num_vars,
884  sizeof(struct config_generic *), guc_var_compare);
885 
886  return result;
887 }
static int guc_var_compare(const void *a, const void *b)
Definition: guc.c:1253
#define qsort(a, b, c, d)
Definition: port.h:445

References Assert(), guc_hashtab, guc_var_compare(), GUCHashEntry::gucvar, hash_get_num_entries(), hash_seq_init(), hash_seq_search(), i, palloc(), qsort, and config_generic::status.

Referenced by GucInfoMain(), show_all_settings(), and ShowAllGUCConfig().

◆ GetConfigOption()

const char* GetConfigOption ( const char *  name,
bool  missing_ok,
bool  restrict_privileged 
)

Definition at line 4200 of file guc.c.

4201 {
4202  struct config_generic *record;
4203  static char buffer[256];
4204 
4205  record = find_option(name, false, missing_ok, ERROR);
4206  if (record == NULL)
4207  return NULL;
4208  if (restrict_privileged &&
4209  !ConfigOptionIsVisible(record))
4210  ereport(ERROR,
4211  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4212  errmsg("permission denied to examine \"%s\"", name),
4213  errdetail("Only roles with privileges of the \"%s\" role may examine this parameter.",
4214  "pg_read_all_settings")));
4215 
4216  switch (record->vartype)
4217  {
4218  case PGC_BOOL:
4219  return *((struct config_bool *) record)->variable ? "on" : "off";
4220 
4221  case PGC_INT:
4222  snprintf(buffer, sizeof(buffer), "%d",
4223  *((struct config_int *) record)->variable);
4224  return buffer;
4225 
4226  case PGC_REAL:
4227  snprintf(buffer, sizeof(buffer), "%g",
4228  *((struct config_real *) record)->variable);
4229  return buffer;
4230 
4231  case PGC_STRING:
4232  return *((struct config_string *) record)->variable;
4233 
4234  case PGC_ENUM:
4235  return config_enum_lookup_by_value((struct config_enum *) record,
4236  *((struct config_enum *) record)->variable);
4237  }
4238  return NULL;
4239 }

References config_enum_lookup_by_value(), ConfigOptionIsVisible(), ereport, errcode(), errdetail(), errmsg(), ERROR, find_option(), name, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, snprintf, and config_generic::vartype.

Referenced by applyRemoteGucs(), be_tls_init(), CreateSharedMemoryAndSemaphores(), PostmasterMain(), and ProcessConfigFileInternal().

◆ GetConfigOptionByName()

char* GetConfigOptionByName ( const char *  name,
const char **  varname,
bool  missing_ok 
)

Definition at line 5251 of file guc.c.

5252 {
5253  struct config_generic *record;
5254 
5255  record = find_option(name, false, missing_ok, ERROR);
5256  if (record == NULL)
5257  {
5258  if (varname)
5259  *varname = NULL;
5260  return NULL;
5261  }
5262 
5263  if (!ConfigOptionIsVisible(record))
5264  ereport(ERROR,
5265  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
5266  errmsg("permission denied to examine \"%s\"", name),
5267  errdetail("Only roles with privileges of the \"%s\" role may examine this parameter.",
5268  "pg_read_all_settings")));
5269 
5270  if (varname)
5271  *varname = record->name;
5272 
5273  return ShowGUCOption(record, true);
5274 }
char * ShowGUCOption(struct config_generic *record, bool use_units)
Definition: guc.c:5284

References ConfigOptionIsVisible(), ereport, errcode(), errdetail(), errmsg(), ERROR, find_option(), name, config_generic::name, and ShowGUCOption().

Referenced by ExplainPrintSettings(), ExtractSetVariableArgs(), GetPGVariableResultDesc(), set_config_by_name(), show_config_by_name(), show_config_by_name_missing_ok(), and ShowGUCConfigOption().

◆ GetConfigOptionFlags()

int GetConfigOptionFlags ( const char *  name,
bool  missing_ok 
)

Definition at line 4295 of file guc.c.

4296 {
4297  struct config_generic *record;
4298 
4299  record = find_option(name, false, missing_ok, ERROR);
4300  if (record == NULL)
4301  return 0;
4302  return record->flags;
4303 }

References ERROR, find_option(), config_generic::flags, and name.

Referenced by pg_get_functiondef(), and PostmasterMain().

◆ GetConfigOptionResetString()

const char* GetConfigOptionResetString ( const char *  name)

Definition at line 4249 of file guc.c.

4250 {
4251  struct config_generic *record;
4252  static char buffer[256];
4253 
4254  record = find_option(name, false, false, ERROR);
4255  Assert(record != NULL);
4256  if (!ConfigOptionIsVisible(record))
4257  ereport(ERROR,
4258  (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
4259  errmsg("permission denied to examine \"%s\"", name),
4260  errdetail("Only roles with privileges of the \"%s\" role may examine this parameter.",
4261  "pg_read_all_settings")));
4262 
4263  switch (record->vartype)
4264  {
4265  case PGC_BOOL:
4266  return ((struct config_bool *) record)->reset_val ? "on" : "off";
4267 
4268  case PGC_INT:
4269  snprintf(buffer, sizeof(buffer), "%d",
4270  ((struct config_int *) record)->reset_val);
4271  return buffer;
4272 
4273  case PGC_REAL:
4274  snprintf(buffer, sizeof(buffer), "%g",
4275  ((struct config_real *) record)->reset_val);
4276  return buffer;
4277 
4278  case PGC_STRING:
4279  return ((struct config_string *) record)->reset_val;
4280 
4281  case PGC_ENUM:
4282  return config_enum_lookup_by_value((struct config_enum *) record,
4283  ((struct config_enum *) record)->reset_val);
4284  }
4285  return NULL;
4286 }

References Assert(), config_enum_lookup_by_value(), ConfigOptionIsVisible(), ereport, errcode(), errdetail(), errmsg(), ERROR, find_option(), name, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, snprintf, and config_generic::vartype.

Referenced by check_datestyle().

◆ GUC_check_errcode()

◆ guc_free()

void guc_free ( void *  ptr)

Definition at line 682 of file guc.c.

683 {
684  /*
685  * Historically, GUC-related code has relied heavily on the ability to do
686  * free(NULL), so we allow that here even though pfree() doesn't.
687  */
688  if (ptr != NULL)
689  {
690  /* This is to help catch old code that malloc's GUC data. */
692  pfree(ptr);
693  }
694 }
MemoryContext GetMemoryChunkContext(void *pointer)
Definition: mcxt.c:616

References Assert(), GetMemoryChunkContext(), GUCMemoryContext, and pfree().

Referenced by add_placeholder_variable(), AlterSystemSetConfigFile(), call_string_check_hook(), check_client_encoding(), check_datestyle(), check_default_text_search_config(), define_custom_variable(), parse_and_validate_value(), ReportGUCOption(), RestoreGUCState(), SelectConfigFiles(), set_config_option_ext(), set_config_sourcefile(), set_extra_field(), and set_string_field().

◆ guc_malloc()

◆ guc_name_compare()

int guc_name_compare ( const char *  namea,
const char *  nameb 
)

Definition at line 1265 of file guc.c.

1266 {
1267  /*
1268  * The temptation to use strcasecmp() here must be resisted, because the
1269  * hash mapping has to remain stable across setlocale() calls. So, build
1270  * our own with a simple ASCII-only downcasing.
1271  */
1272  while (*namea && *nameb)
1273  {
1274  char cha = *namea++;
1275  char chb = *nameb++;
1276 
1277  if (cha >= 'A' && cha <= 'Z')
1278  cha += 'a' - 'A';
1279  if (chb >= 'A' && chb <= 'Z')
1280  chb += 'a' - 'A';
1281  if (cha != chb)
1282  return cha - chb;
1283  }
1284  if (*namea)
1285  return 1; /* a is longer */
1286  if (*nameb)
1287  return -1; /* b is longer */
1288  return 0;
1289 }

Referenced by convert_GUC_name_for_parameter_acl(), find_option(), GetPGVariable(), GetPGVariableResultDesc(), guc_name_match(), guc_var_compare(), and replace_auto_config_value().

◆ guc_name_hash()

static uint32 guc_name_hash ( const void *  key,
Size  keysize 
)
static

Definition at line 1295 of file guc.c.

1296 {
1297  uint32 result = 0;
1298  const char *name = *(const char *const *) key;
1299 
1300  while (*name)
1301  {
1302  char ch = *name++;
1303 
1304  /* Case-fold in the same way as guc_name_compare */
1305  if (ch >= 'A' && ch <= 'Z')
1306  ch += 'a' - 'A';
1307 
1308  /* Merge into hash ... not very bright, but it needn't be */
1309  result = pg_rotate_left32(result, 5);
1310  result ^= (uint32) ch;
1311  }
1312  return result;
1313 }
unsigned int uint32
Definition: c.h:495
static uint32 pg_rotate_left32(uint32 word, int n)
Definition: pg_bitutils.h:326

References sort-test::key, name, and pg_rotate_left32().

Referenced by build_guc_variables().

◆ guc_name_match()

static int guc_name_match ( const void *  key1,
const void *  key2,
Size  keysize 
)
static

Definition at line 1319 of file guc.c.

1320 {
1321  const char *name1 = *(const char *const *) key1;
1322  const char *name2 = *(const char *const *) key2;
1323 
1324  return guc_name_compare(name1, name2);
1325 }

References guc_name_compare().

Referenced by build_guc_variables().

◆ guc_realloc()

void* guc_realloc ( int  elevel,
void *  old,
size_t  size 
)

Definition at line 645 of file guc.c.

646 {
647  void *data;
648 
649  if (old != NULL)
650  {
651  /* This is to help catch old code that malloc's GUC data. */
653  data = repalloc_extended(old, size,
655  }
656  else
657  {
658  /* Like realloc(3), but not like repalloc(), we allow old == NULL. */
661  }
662  if (unlikely(data == NULL))
663  ereport(elevel,
664  (errcode(ERRCODE_OUT_OF_MEMORY),
665  errmsg("out of memory")));
666  return data;
667 }
void * repalloc_extended(void *pointer, Size size, int flags)
Definition: mcxt.c:1521

References Assert(), data, ereport, errcode(), errmsg(), GetMemoryChunkContext(), GUCMemoryContext, MCXT_ALLOC_NO_OOM, MemoryContextAllocExtended(), repalloc_extended(), and unlikely.

◆ guc_restore_error_context_callback()

static void guc_restore_error_context_callback ( void *  arg)
static

Definition at line 5995 of file guc.c.

5996 {
5997  char **error_context_name_and_value = (char **) arg;
5998 
5999  if (error_context_name_and_value)
6000  errcontext("while setting parameter \"%s\" to \"%s\"",
6001  error_context_name_and_value[0],
6002  error_context_name_and_value[1]);
6003 }
#define errcontext
Definition: elog.h:196
void * arg

References arg, and errcontext.

Referenced by RestoreGUCState().

◆ guc_strdup()

char* guc_strdup ( int  elevel,
const char *  src 
)

Definition at line 670 of file guc.c.

671 {
672  char *data;
673  size_t len = strlen(src) + 1;
674 
675  data = guc_malloc(elevel, len);
676  if (likely(data != NULL))
677  memcpy(data, src, len);
678  return data;
679 }
#define likely(x)
Definition: c.h:299
const void size_t len

References data, guc_malloc(), len, and likely.

Referenced by add_placeholder_variable(), check_application_name(), check_client_encoding(), check_cluster_name(), check_datestyle(), check_default_text_search_config(), init_custom_variable(), InitializeOneGUCOption(), parse_and_validate_value(), ReportGUCOption(), set_config_option_ext(), and set_config_sourcefile().

◆ guc_var_compare()

static int guc_var_compare ( const void *  a,
const void *  b 
)
static

Definition at line 1253 of file guc.c.

1254 {
1255  const struct config_generic *confa = *(struct config_generic *const *) a;
1256  const struct config_generic *confb = *(struct config_generic *const *) b;
1257 
1258  return guc_name_compare(confa->name, confb->name);
1259 }
int b
Definition: isn.c:70
int a
Definition: isn.c:69

References a, b, guc_name_compare(), and config_generic::name.

Referenced by get_guc_variables().

◆ GUCArrayAdd()

ArrayType* GUCArrayAdd ( ArrayType array,
const char *  name,
const char *  value 
)

Definition at line 6312 of file guc.c.

6313 {
6314  struct config_generic *record;
6315  Datum datum;
6316  char *newval;
6317  ArrayType *a;
6318 
6319  Assert(name);
6320  Assert(value);
6321 
6322  /* test if the option is valid and we're allowed to set it */
6323  (void) validate_option_array_item(name, value, false);
6324 
6325  /* normalize name (converts obsolete GUC names to modern spellings) */
6326  record = find_option(name, false, true, WARNING);
6327  if (record)
6328  name = record->name;
6329 
6330  /* build new item for array */
6331  newval = psprintf("%s=%s", name, value);
6332  datum = CStringGetTextDatum(newval);
6333 
6334  if (array)
6335  {
6336  int index;
6337  bool isnull;
6338  int i;
6339 
6340  Assert(ARR_ELEMTYPE(array) == TEXTOID);
6341  Assert(ARR_NDIM(array) == 1);
6342  Assert(ARR_LBOUND(array)[0] == 1);
6343 
6344  index = ARR_DIMS(array)[0] + 1; /* add after end */
6345 
6346  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6347  {
6348  Datum d;
6349  char *current;
6350 
6351  d = array_ref(array, 1, &i,
6352  -1 /* varlenarray */ ,
6353  -1 /* TEXT's typlen */ ,
6354  false /* TEXT's typbyval */ ,
6355  TYPALIGN_INT /* TEXT's typalign */ ,
6356  &isnull);
6357  if (isnull)
6358  continue;
6359  current = TextDatumGetCString(d);
6360 
6361  /* check for match up through and including '=' */
6362  if (strncmp(current, newval, strlen(name) + 1) == 0)
6363  {
6364  index = i;
6365  break;
6366  }
6367  }
6368 
6369  a = array_set(array, 1, &index,
6370  datum,
6371  false,
6372  -1 /* varlena array */ ,
6373  -1 /* TEXT's typlen */ ,
6374  false /* TEXT's typbyval */ ,
6375  TYPALIGN_INT /* TEXT's typalign */ );
6376  }
6377  else
6378  a = construct_array_builtin(&datum, 1, TEXTOID);
6379 
6380  return a;
6381 }
#define ARR_NDIM(a)
Definition: array.h:283
#define ARR_ELEMTYPE(a)
Definition: array.h:285
#define ARR_DIMS(a)
Definition: array.h:287
#define ARR_LBOUND(a)
Definition: array.h:289
ArrayType * construct_array_builtin(Datum *elems, int nelems, Oid elmtype)
Definition: arrayfuncs.c:3340
ArrayType * array_set(ArrayType *array, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3122
Datum array_ref(ArrayType *array, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
Definition: arrayfuncs.c:3105
#define CStringGetTextDatum(s)
Definition: builtins.h:94
#define TextDatumGetCString(d)
Definition: builtins.h:95
static bool validate_option_array_item(const char *name, const char *value, bool skipIfNoPermissions)
Definition: guc.c:6532
uintptr_t Datum
Definition: postgres.h:64
char * psprintf(const char *fmt,...)
Definition: psprintf.c:46
Definition: type.h:95

References a, ARR_DIMS, ARR_ELEMTYPE, ARR_LBOUND, ARR_NDIM, array_ref(), array_set(), Assert(), construct_array_builtin(), CStringGetTextDatum, find_option(), i, name, config_generic::name, newval, psprintf(), TextDatumGetCString, validate_option_array_item(), value, and WARNING.

Referenced by AlterSetting(), and update_proconfig_value().

◆ GUCArrayDelete()

ArrayType* GUCArrayDelete ( ArrayType array,
const char *  name 
)

Definition at line 6390 of file guc.c.

6391 {
6392  struct config_generic *record;
6393  ArrayType *newarray;
6394  int i;
6395  int index;
6396 
6397  Assert(name);
6398 
6399  /* test if the option is valid and we're allowed to set it */
6400  (void) validate_option_array_item(name, NULL, false);
6401 
6402  /* normalize name (converts obsolete GUC names to modern spellings) */
6403  record = find_option(name, false, true, WARNING);
6404  if (record)
6405  name = record->name;
6406 
6407  /* if array is currently null, then surely nothing to delete */
6408  if (!array)
6409  return NULL;
6410 
6411  newarray = NULL;
6412  index = 1;
6413 
6414  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6415  {
6416  Datum d;
6417  char *val;
6418  bool isnull;
6419 
6420  d = array_ref(array, 1, &i,
6421  -1 /* varlenarray */ ,
6422  -1 /* TEXT's typlen */ ,
6423  false /* TEXT's typbyval */ ,
6424  TYPALIGN_INT /* TEXT's typalign */ ,
6425  &isnull);
6426  if (isnull)
6427  continue;
6428  val = TextDatumGetCString(d);
6429 
6430  /* ignore entry if it's what we want to delete */
6431  if (strncmp(val, name, strlen(name)) == 0
6432  && val[strlen(name)] == '=')
6433  continue;
6434 
6435  /* else add it to the output array */
6436  if (newarray)
6437  newarray = array_set(newarray, 1, &index,
6438  d,
6439  false,
6440  -1 /* varlenarray */ ,
6441  -1 /* TEXT's typlen */ ,
6442  false /* TEXT's typbyval */ ,
6443  TYPALIGN_INT /* TEXT's typalign */ );
6444  else
6445  newarray = construct_array_builtin(&d, 1, TEXTOID);
6446 
6447  index++;
6448  }
6449 
6450  return newarray;
6451 }

References ARR_DIMS, array_ref(), array_set(), Assert(), construct_array_builtin(), find_option(), i, name, config_generic::name, TextDatumGetCString, val, validate_option_array_item(), and WARNING.

Referenced by AlterSetting(), and update_proconfig_value().

◆ GUCArrayReset()

ArrayType* GUCArrayReset ( ArrayType array)

Definition at line 6460 of file guc.c.

6461 {
6462  ArrayType *newarray;
6463  int i;
6464  int index;
6465 
6466  /* if array is currently null, nothing to do */
6467  if (!array)
6468  return NULL;
6469 
6470  /* if we're superuser, we can delete everything, so just do it */
6471  if (superuser())
6472  return NULL;
6473 
6474  newarray = NULL;
6475  index = 1;
6476 
6477  for (i = 1; i <= ARR_DIMS(array)[0]; i++)
6478  {
6479  Datum d;
6480  char *val;
6481  char *eqsgn;
6482  bool isnull;
6483 
6484  d = array_ref(array, 1, &i,
6485  -1 /* varlenarray */ ,
6486  -1 /* TEXT's typlen */ ,
6487  false /* TEXT's typbyval */ ,
6488  TYPALIGN_INT /* TEXT's typalign */ ,
6489  &isnull);
6490  if (isnull)
6491  continue;
6492  val = TextDatumGetCString(d);
6493 
6494  eqsgn = strchr(val, '=');
6495  *eqsgn = '\0';
6496 
6497  /* skip if we have permission to delete it */
6498  if (validate_option_array_item(val, NULL, true))
6499  continue;
6500 
6501  /* else add it to the output array */
6502  if (newarray)
6503  newarray = array_set(newarray, 1, &index,
6504  d,
6505  false,
6506  -1 /* varlenarray */ ,
6507  -1 /* TEXT's typlen */ ,
6508  false /* TEXT's typbyval */ ,
6509  TYPALIGN_INT /* TEXT's typalign */ );
6510  else
6511  newarray = construct_array_builtin(&d, 1, TEXTOID);
6512 
6513  index++;
6514  pfree(val);
6515  }
6516 
6517  return newarray;
6518 }

References ARR_DIMS, array_ref(), array_set(), construct_array_builtin(), i, pfree(), superuser(), TextDatumGetCString, val, and validate_option_array_item().

Referenced by AlterSetting().

◆ init_custom_variable()

static struct config_generic* init_custom_variable ( const char *  name,
const char *  short_desc,
const char *  long_desc,
GucContext  context,
int  flags,
enum config_type  type,
size_t  sz 
)
static

Definition at line 4697 of file guc.c.

4704 {
4705  struct config_generic *gen;
4706 
4707  /*
4708  * Only allow custom PGC_POSTMASTER variables to be created during shared
4709  * library preload; any later than that, we can't ensure that the value
4710  * doesn't change after startup. This is a fatal elog if it happens; just
4711  * erroring out isn't safe because we don't know what the calling loadable
4712  * module might already have hooked into.
4713  */
4714  if (context == PGC_POSTMASTER &&
4716  elog(FATAL, "cannot create PGC_POSTMASTER variables after startup");
4717 
4718  /*
4719  * We can't support custom GUC_LIST_QUOTE variables, because the wrong
4720  * things would happen if such a variable were set or pg_dump'd when the
4721  * defining extension isn't loaded. Again, treat this as fatal because
4722  * the loadable module may be partly initialized already.
4723  */
4724  if (flags & GUC_LIST_QUOTE)
4725  elog(FATAL, "extensions cannot define GUC_LIST_QUOTE variables");
4726 
4727  /*
4728  * Before pljava commit 398f3b876ed402bdaec8bc804f29e2be95c75139
4729  * (2015-12-15), two of that module's PGC_USERSET variables facilitated
4730  * trivial escalation to superuser privileges. Restrict the variables to
4731  * protect sites that have yet to upgrade pljava.
4732  */
4733  if (context == PGC_USERSET &&
4734  (strcmp(name, "pljava.classpath") == 0 ||
4735  strcmp(name, "pljava.vmoptions") == 0))
4736  context = PGC_SUSET;
4737 
4738  gen = (struct config_generic *) guc_malloc(ERROR, sz);
4739  memset(gen, 0, sz);
4740 
4741  gen->name = guc_strdup(ERROR, name);
4742  gen->context = context;
4743  gen->group = CUSTOM_OPTIONS;
4744  gen->short_desc = short_desc;
4745  gen->long_desc = long_desc;
4746  gen->flags = flags;
4747  gen->vartype = type;
4748 
4749  return gen;
4750 }
#define FATAL
Definition: elog.h:41
#define GUC_LIST_QUOTE
Definition: guc.h:209
@ PGC_SUSET
Definition: guc.h:74
bool process_shared_preload_libraries_in_progress
Definition: miscinit.c:1764
const char * long_desc
Definition: guc_tables.h:159
const char * type

References config_generic::context, CUSTOM_OPTIONS, elog(), ERROR, FATAL, config_generic::flags, config_generic::group, GUC_LIST_QUOTE, guc_malloc(), guc_strdup(), config_generic::long_desc, name, config_generic::name, PGC_POSTMASTER, PGC_SUSET, PGC_USERSET, process_shared_preload_libraries_in_progress, config_generic::short_desc, type, and config_generic::vartype.

Referenced by DefineCustomBoolVariable(), DefineCustomEnumVariable(), DefineCustomIntVariable(), DefineCustomRealVariable(), and DefineCustomStringVariable().

◆ InitializeGUCOptions()

void InitializeGUCOptions ( void  )

Definition at line 1495 of file guc.c.

1496 {
1497  HASH_SEQ_STATUS status;
1498  GUCHashEntry *hentry;
1499 
1500  /*
1501  * Before log_line_prefix could possibly receive a nonempty setting, make
1502  * sure that timezone processing is minimally alive (see elog.c).
1503  */
1505 
1506  /*
1507  * Create GUCMemoryContext and build hash table of all GUC variables.
1508  */
1510 
1511  /*
1512  * Load all variables with their compiled-in defaults, and initialize
1513  * status fields as needed.
1514  */
1515  hash_seq_init(&status, guc_hashtab);
1516  while ((hentry = (GUCHashEntry *) hash_seq_search(&status)) != NULL)
1517  {
1518  /* Check mapping between initial and default value */
1519  Assert(check_GUC_init(hentry->gucvar));
1520 
1521  InitializeOneGUCOption(hentry->gucvar);
1522  }
1523 
1524  reporting_enabled = false;
1525 
1526  /*
1527  * Prevent any attempt to override the transaction modes from
1528  * non-interactive sources.
1529  */
1530  SetConfigOption("transaction_isolation", "read committed",
1532  SetConfigOption("transaction_read_only", "no",
1534  SetConfigOption("transaction_deferrable", "no",
1536 
1537  /*
1538  * For historical reasons, some GUC parameters can receive defaults from
1539  * environment variables. Process those settings.
1540  */
1542 }
void build_guc_variables(void)
Definition: guc.c:896
static void InitializeGUCOptionsFromEnvironment(void)
Definition: guc.c:1554
void pg_timezone_initialize(void)
Definition: pgtz.c:361

References Assert(), build_guc_variables(), guc_hashtab, GUCHashEntry::gucvar, hash_seq_init(), hash_seq_search(), InitializeGUCOptionsFromEnvironment(), InitializeOneGUCOption(), pg_timezone_initialize(), PGC_POSTMASTER, PGC_S_OVERRIDE, reporting_enabled, and SetConfigOption().

Referenced by BootstrapModeMain(), PostgresSingleUserMain(), and PostmasterMain().

◆ InitializeGUCOptionsFromEnvironment()

static void InitializeGUCOptionsFromEnvironment ( void  )
static

Definition at line 1554 of file guc.c.

1555 {
1556  char *env;
1557  long stack_rlimit;
1558 
1559  env = getenv("PGPORT");
1560  if (env != NULL)
1562 
1563  env = getenv("PGDATESTYLE");
1564  if (env != NULL)
1565  SetConfigOption("datestyle", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
1566 
1567  env = getenv("PGCLIENTENCODING");
1568  if (env != NULL)
1569  SetConfigOption("client_encoding", env, PGC_POSTMASTER, PGC_S_ENV_VAR);
1570 
1571  /*
1572  * rlimit isn't exactly an "environment variable", but it behaves about
1573  * the same. If we can identify the platform stack depth rlimit, increase
1574  * default stack depth setting up to whatever is safe (but at most 2MB).
1575  * Report the value's source as PGC_S_DYNAMIC_DEFAULT if it's 2MB, or as
1576  * PGC_S_ENV_VAR if it's reflecting the rlimit limit.
1577  */
1578  stack_rlimit = get_stack_depth_rlimit();
1579  if (stack_rlimit > 0)
1580  {
1581  long new_limit = (stack_rlimit - STACK_DEPTH_SLOP) / 1024L;
1582 
1583  if (new_limit > 100)
1584  {
1585  GucSource source;
1586  char limbuf[16];
1587 
1588  if (new_limit < 2048)
1590  else
1591  {
1592  new_limit = 2048;
1594  }
1595  snprintf(limbuf, sizeof(limbuf), "%ld", new_limit);
1596  SetConfigOption("max_stack_depth", limbuf,
1598  }
1599  }
1600 }
@ PGC_S_DYNAMIC_DEFAULT
Definition: guc.h:110
@ PGC_S_ENV_VAR
Definition: guc.h:111
long get_stack_depth_rlimit(void)
Definition: postgres.c:4933
#define STACK_DEPTH_SLOP
Definition: tcopprot.h:26

References get_stack_depth_rlimit(), PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT, PGC_S_ENV_VAR, SetConfigOption(), snprintf, source, and STACK_DEPTH_SLOP.

Referenced by InitializeGUCOptions(), and ProcessConfigFileInternal().

◆ InitializeOneGUCOption()

static void InitializeOneGUCOption ( struct config_generic gconf)
static

Definition at line 1609 of file guc.c.

1610 {
1611  gconf->status = 0;
1612  gconf->source = PGC_S_DEFAULT;
1613  gconf->reset_source = PGC_S_DEFAULT;
1614  gconf->scontext = PGC_INTERNAL;
1615  gconf->reset_scontext = PGC_INTERNAL;
1616  gconf->srole = BOOTSTRAP_SUPERUSERID;
1617  gconf->reset_srole = BOOTSTRAP_SUPERUSERID;
1618  gconf->stack = NULL;
1619  gconf->extra = NULL;
1620  gconf->last_reported = NULL;
1621  gconf->sourcefile = NULL;
1622  gconf->sourceline = 0;
1623 
1624  switch (gconf->vartype)
1625  {
1626  case PGC_BOOL:
1627  {
1628  struct config_bool *conf = (struct config_bool *) gconf;
1629  bool newval = conf->boot_val;
1630  void *extra = NULL;
1631 
1632  if (!call_bool_check_hook(conf, &newval, &extra,
1633  PGC_S_DEFAULT, LOG))
1634  elog(FATAL, "failed to initialize %s to %d",
1635  conf->gen.name, (int) newval);
1636  if (conf->assign_hook)
1637  conf->assign_hook(newval, extra);
1638  *conf->variable = conf->reset_val = newval;
1639  conf->gen.extra = conf->reset_extra = extra;
1640  break;
1641  }
1642  case PGC_INT:
1643  {
1644  struct config_int *conf = (struct config_int *) gconf;
1645  int newval = conf->boot_val;
1646  void *extra = NULL;
1647 
1648  Assert(newval >= conf->min);
1649  Assert(newval <= conf->max);
1650  if (!call_int_check_hook(conf, &newval, &extra,
1651  PGC_S_DEFAULT, LOG))
1652  elog(FATAL, "failed to initialize %s to %d",
1653  conf->gen.name, newval);
1654  if (conf->assign_hook)
1655  conf->assign_hook(newval, extra);
1656  *conf->variable = conf->reset_val = newval;
1657  conf->gen.extra = conf->reset_extra = extra;
1658  break;
1659  }
1660  case PGC_REAL:
1661  {
1662  struct config_real *conf = (struct config_real *) gconf;
1663  double newval = conf->boot_val;
1664  void *extra = NULL;
1665 
1666  Assert(newval >= conf->min);
1667  Assert(newval <= conf->max);
1668  if (!call_real_check_hook(conf, &newval, &extra,
1669  PGC_S_DEFAULT, LOG))
1670  elog(FATAL, "failed to initialize %s to %g",
1671  conf->gen.name, newval);
1672  if (conf->assign_hook)
1673  conf->assign_hook(newval, extra);
1674  *conf->variable = conf->reset_val = newval;
1675  conf->gen.extra = conf->reset_extra = extra;
1676  break;
1677  }
1678  case PGC_STRING:
1679  {
1680  struct config_string *conf = (struct config_string *) gconf;
1681  char *newval;
1682  void *extra = NULL;
1683 
1684  /* non-NULL boot_val must always get strdup'd */
1685  if (conf->boot_val != NULL)
1686  newval = guc_strdup(FATAL, conf->boot_val);
1687  else
1688  newval = NULL;
1689 
1690  if (!call_string_check_hook(conf, &newval, &extra,
1691  PGC_S_DEFAULT, LOG))
1692  elog(FATAL, "failed to initialize %s to \"%s\"",
1693  conf->gen.name, newval ? newval : "");
1694  if (conf->assign_hook)
1695  conf->assign_hook(newval, extra);
1696  *conf->variable = conf->reset_val = newval;
1697  conf->gen.extra = conf->reset_extra = extra;
1698  break;
1699  }
1700  case PGC_ENUM:
1701  {
1702  struct config_enum *conf = (struct config_enum *) gconf;
1703  int newval = conf->boot_val;
1704  void *extra = NULL;
1705 
1706  if (!call_enum_check_hook(conf, &newval, &extra,
1707  PGC_S_DEFAULT, LOG))
1708  elog(FATAL, "failed to initialize %s to %d",
1709  conf->gen.name, newval);
1710  if (conf->assign_hook)
1711  conf->assign_hook(newval, extra);
1712  *conf->variable = conf->reset_val = newval;
1713  conf->gen.extra = conf->reset_extra = extra;
1714  break;
1715  }
1716  }
1717 }
static bool call_string_check_hook(struct config_string *conf, char **newval, void **extra, GucSource source, int elevel)
Definition: guc.c:6724
static void static bool call_bool_check_hook(struct config_bool *conf, bool *newval, void **extra, GucSource source, int elevel)
Definition: guc.c:6622
static bool call_int_check_hook(struct config_int *conf, int *newval, void **extra, GucSource source, int elevel)
Definition: guc.c:6656
static bool call_real_check_hook(struct config_real *conf, double *newval, void **extra, GucSource source, int elevel)
Definition: guc.c:6690
static bool call_enum_check_hook(struct config_enum *conf, int *newval, void **extra, GucSource source, int elevel)
Definition: guc.c:6774
void * reset_extra
Definition: guc_tables.h:208
void * reset_extra
Definition: guc_tables.h:269
char * last_reported
Definition: guc_tables.h:178
void * reset_extra
Definition: guc_tables.h:224
void * reset_extra
Definition: guc_tables.h:240
void * reset_extra
Definition: guc_tables.h:254

References Assert(), config_bool::assign_hook, config_int::assign_hook, config_real::assign_hook, config_string::assign_hook, config_enum::assign_hook, config_bool::boot_val, config_int::boot_val, config_real::boot_val, config_string::boot_val, config_enum::boot_val, call_bool_check_hook(), call_enum_check_hook(), call_int_check_hook(), call_real_check_hook(), call_string_check_hook(), elog(), config_generic::extra, FATAL, config_bool::gen, config_int::gen, config_real::gen, config_string::gen, config_enum::gen, guc_strdup(), config_generic::last_reported, LOG, config_int::max, config_real::max, config_int::min, config_real::min, config_generic::name, newval, PGC_BOOL, PGC_ENUM, PGC_INT, PGC_INTERNAL, PGC_REAL, PGC_S_DEFAULT, PGC_STRING, config_bool::reset_extra, config_int::reset_extra, config_real::reset_extra, config_string::reset_extra, config_enum::reset_extra, config_generic::reset_scontext, config_generic::reset_source, config_generic::reset_srole, config_bool::reset_val, config_int::reset_val, config_real::reset_val, config_string::reset_val, config_enum::reset_val, config_generic::scontext, config_generic::source, config_generic::sourcefile, config_generic::sourceline, config_generic::srole, config_generic::stack, config_generic::status, config_bool::variable, config_int::variable, config_real::variable, config_string::variable, config_enum::variable, and config_generic::vartype.

Referenced by define_custom_variable(), InitializeGUCOptions(), and RestoreGUCState().

◆ MarkGUCPrefixReserved()

void MarkGUCPrefixReserved ( const char *  className)

Definition at line 5105 of file guc.c.

5106 {
5107  int classLen = strlen(className);
5108  HASH_SEQ_STATUS status;
5109  GUCHashEntry *hentry;
5110  MemoryContext oldcontext;
5111 
5112  /*
5113  * Check for existing placeholders. We must actually remove invalid
5114  * placeholders, else future parallel worker startups will fail. (We
5115  * don't bother trying to free associated memory, since this shouldn't
5116  * happen often.)
5117  */
5118  hash_seq_init(&status, guc_hashtab);
5119  while ((hentry = (GUCHashEntry *) hash_seq_search(&status)) != NULL)
5120  {
5121  struct config_generic *var = hentry->gucvar;
5122 
5123  if ((var->flags & GUC_CUSTOM_PLACEHOLDER) != 0 &&
5124  strncmp(className, var->name, classLen) == 0 &&
5125  var->name[classLen] == GUC_QUALIFIER_SEPARATOR)
5126  {
5127  ereport(WARNING,
5128  (errcode(ERRCODE_INVALID_NAME),
5129  errmsg("invalid configuration parameter name \"%s\", removing it",
5130  var->name),
5131  errdetail("\"%s\" is now a reserved prefix.",
5132  className)));
5133  /* Remove it from the hash table */
5135  &var->name,
5136  HASH_REMOVE,
5137  NULL);
5138  /* Remove it from any lists it's in, too */
5139  RemoveGUCFromLists(var);
5140  }
5141  }
5142 
5143  /* And remember the name so we can prevent future mistakes. */
5146  MemoryContextSwitchTo(oldcontext);
5147 }
@ HASH_REMOVE
Definition: hsearch.h:115
List * lappend(List *list, void *datum)
Definition: list.c:338
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138

References ereport, errcode(), errdetail(), errmsg(), config_generic::flags, GUC_CUSTOM_PLACEHOLDER, guc_hashtab, GUC_QUALIFIER_SEPARATOR, GUCMemoryContext, GUCHashEntry::gucvar, HASH_REMOVE, hash_search(), hash_seq_init(), hash_seq_search(), lappend(), MemoryContextSwitchTo(), config_generic::name, pstrdup(), RemoveGUCFromLists(), reserved_class_prefix, and WARNING.

Referenced by _PG_init().

◆ NewGUCNestLevel()

◆ parse_and_validate_value()

static bool parse_and_validate_value ( struct config_generic record,
const char *  name,
const char *  value,
GucSource  source,
int  elevel,
union config_var_val newval,
void **  newextra 
)
static

Definition at line 3083 of file guc.c.

3087 {
3088  switch (record->vartype)
3089  {
3090  case PGC_BOOL:
3091  {
3092  struct config_bool *conf = (struct config_bool *) record;
3093 
3094  if (!parse_bool(value, &newval->boolval))
3095  {
3096  ereport(elevel,
3097  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3098  errmsg("parameter \"%s\" requires a Boolean value",
3099  name)));
3100  return false;
3101  }
3102 
3103  if (!call_bool_check_hook(conf, &newval->boolval, newextra,
3104  source, elevel))
3105  return false;
3106  }
3107  break;
3108  case PGC_INT:
3109  {
3110  struct config_int *conf = (struct config_int *) record;
3111  const char *hintmsg;
3112 
3113  if (!parse_int(value, &newval->intval,
3114  conf->gen.flags, &hintmsg))
3115  {
3116  ereport(elevel,
3117  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3118  errmsg("invalid value for parameter \"%s\": \"%s\"",
3119  name, value),
3120  hintmsg ? errhint("%s", _(hintmsg)) : 0));
3121  return false;
3122  }
3123 
3124  if (newval->intval < conf->min || newval->intval > conf->max)
3125  {
3126  const char *unit = get_config_unit_name(conf->gen.flags);
3127 
3128  ereport(elevel,
3129  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3130  errmsg("%d%s%s is outside the valid range for parameter \"%s\" (%d .. %d)",
3131  newval->intval,
3132  unit ? " " : "",
3133  unit ? unit : "",
3134  name,
3135  conf->min, conf->max)));
3136  return false;
3137  }
3138 
3139  if (!call_int_check_hook(conf, &newval->intval, newextra,
3140  source, elevel))
3141  return false;
3142  }
3143  break;
3144  case PGC_REAL:
3145  {
3146  struct config_real *conf = (struct config_real *) record;
3147  const char *hintmsg;
3148 
3149  if (!parse_real(value, &newval->realval,
3150  conf->gen.flags, &hintmsg))
3151  {
3152  ereport(elevel,
3153  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3154  errmsg("invalid value for parameter \"%s\": \"%s\"",
3155  name, value),
3156  hintmsg ? errhint("%s", _(hintmsg)) : 0));
3157  return false;
3158  }
3159 
3160  if (newval->realval < conf->min || newval->realval > conf->max)
3161  {
3162  const char *unit = get_config_unit_name(conf->gen.flags);
3163 
3164  ereport(elevel,
3165  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3166  errmsg("%g%s%s is outside the valid range for parameter \"%s\" (%g .. %g)",
3167  newval->realval,
3168  unit ? " " : "",
3169  unit ? unit : "",
3170  name,
3171  conf->min, conf->max)));
3172  return false;
3173  }
3174 
3175  if (!call_real_check_hook(conf, &newval->realval, newextra,
3176  source, elevel))
3177  return false;
3178  }
3179  break;
3180  case PGC_STRING:
3181  {
3182  struct config_string *conf = (struct config_string *) record;
3183 
3184  /*
3185  * The value passed by the caller could be transient, so we
3186  * always strdup it.
3187  */
3188  newval->stringval = guc_strdup(elevel, value);
3189  if (newval->stringval == NULL)
3190  return false;
3191 
3192  /*
3193  * The only built-in "parsing" check we have is to apply
3194  * truncation if GUC_IS_NAME.
3195  */
3196  if (conf->gen.flags & GUC_IS_NAME)
3197  truncate_identifier(newval->stringval,
3198  strlen(newval->stringval),
3199  true);
3200 
3201  if (!call_string_check_hook(conf, &newval->stringval, newextra,
3202  source, elevel))
3203  {
3204  guc_free(newval->stringval);
3205  newval->stringval = NULL;
3206  return false;
3207  }
3208  }
3209  break;
3210  case PGC_ENUM:
3211  {
3212  struct config_enum *conf = (struct config_enum *) record;
3213 
3214  if (!config_enum_lookup_by_name(conf, value, &newval->enumval))
3215  {
3216  char *hintmsg;
3217 
3218  hintmsg = config_enum_get_options(conf,
3219  "Available values: ",
3220  ".", ", ");
3221 
3222  ereport(elevel,
3223  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
3224  errmsg("invalid value for parameter \"%s\": \"%s\"",
3225  name, value),
3226  hintmsg ? errhint("%s", _(hintmsg)) : 0));
3227 
3228  if (hintmsg)
3229  pfree(hintmsg);
3230  return false;
3231  }
3232 
3233  if (!call_enum_check_hook(conf, &newval->enumval, newextra,
3234  source, elevel))
3235  return false;
3236  }
3237  break;
3238  }
3239 
3240  return true;
3241 }
bool parse_bool(const char *value, bool *result)
Definition: bool.c:30
#define _(x)
Definition: elog.c:91
bool parse_int(const char *value, int *result, int flags, const char **hintmsg)
Definition: guc.c:2824
bool config_enum_lookup_by_name(struct config_enum *record, const char *value, int *retval)
Definition: guc.c:2999
bool parse_real(const char *value, double *result, int flags, const char **hintmsg)
Definition: guc.c:2914
const char * get_config_unit_name(int flags)
Definition: guc.c:2767
char * config_enum_get_options(struct config_enum *record, const char *prefix, const char *suffix, const char *separator)
Definition: guc.c:3025
#define GUC_IS_NAME
Definition: guc.h:219
void truncate_identifier(char *ident, int len, bool warn)
Definition: scansup.c:93

References _, call_bool_check_hook(), call_enum_check_hook(), call_int_check_hook(), call_real_check_hook(), call_string_check_hook(), config_enum_get_options(), config_enum_lookup_by_name(), ereport, errcode(), errhint(), errmsg(), config_generic::flags, config_int::gen, config_real::gen, config_string::gen, get_config_unit_name(), guc_free(), GUC_IS_NAME, guc_strdup(), config_int::max, config_real::max, config_int::min, config_real::min, name, newval, parse_bool(), parse_int(), parse_real(), pfree(), PGC_BOOL, PGC_ENUM, PGC_INT, PGC_REAL, PGC_STRING, source, truncate_identifier(), value, and config_generic::vartype.

Referenced by AlterSystemSetConfigFile(), and set_config_option_ext().

◆ parse_int()

bool parse_int ( const char *  value,
int *  result,
int  flags,
const char **  hintmsg 
)

Definition at line 2824 of file guc.c.

2825 {
2826  /*
2827  * We assume here that double is wide enough to represent any integer
2828  * value with adequate precision.
2829  */
2830  double val;
2831  char *endptr;
2832 
2833  /* To suppress compiler warnings, always set output params */
2834  if (result)
2835  *result = 0;
2836  if (hintmsg)
2837  *hintmsg = NULL;
2838 
2839  /*
2840  * Try to parse as an integer (allowing octal or hex input). If the
2841  * conversion stops at a decimal point or 'e', or overflows, re-parse as
2842  * float. This should work fine as long as we have no unit names starting
2843  * with 'e'. If we ever do, the test could be extended to check for a
2844  * sign or digit after 'e', but for now that's unnecessary.
2845  */
2846  errno = 0;
2847  val = strtol(value, &endptr, 0);
2848  if (*endptr == '.' || *endptr == 'e' || *endptr == 'E' ||
2849  errno == ERANGE)
2850  {
2851  errno = 0;
2852  val = strtod(value, &endptr);
2853  }
2854 
2855  if (endptr == value || errno == ERANGE)
2856  return false; /* no HINT for these cases */
2857 
2858  /* reject NaN (infinities will fail range check below) */
2859  if (isnan(val))
2860  return false; /* treat same as syntax error; no HINT */
2861 
2862  /* allow whitespace between number and unit */
2863  while (isspace((unsigned char) *endptr))
2864  endptr++;
2865 
2866  /* Handle possible unit */
2867  if (*endptr != '\0')
2868  {
2869  if ((flags & GUC_UNIT) == 0)
2870  return false; /* this setting does not accept a unit */
2871 
2873  endptr, (flags & GUC_UNIT),
2874  &val))
2875  {
2876  /* invalid unit, or garbage after the unit; set hint and fail. */
2877  if (hintmsg)
2878  {
2879  if (flags & GUC_UNIT_MEMORY)
2880  *hintmsg = memory_units_hint;
2881  else
2882  *hintmsg = time_units_hint;
2883  }
2884  return false;
2885  }
2886  }
2887 
2888  /* Round to int, then check for overflow */
2889  val = rint(val);
2890 
2891  if (val > INT_MAX || val < INT_MIN)
2892  {
2893  if (hintmsg)
2894  *hintmsg = gettext_noop("Value exceeds integer range.");
2895  return false;
2896  }
2897 
2898  if (result)
2899  *result = (int) val;
2900  return true;
2901 }
#define gettext_noop(x)
Definition: c.h:1209
static bool convert_to_base_unit(double value, const char *unit, int base_unit, double *base_value)
Definition: guc.c:2624
static const char *const memory_units_hint
Definition: guc.c:115
static const char *const time_units_hint
Definition: guc.c:152

References convert_to_base_unit(), config_generic::flags, gettext_noop, GUC_UNIT, GUC_UNIT_MEMORY, memory_units_hint, time_units_hint, val, and value.

Referenced by apply_server_options(), apply_table_options(), ExecVacuum(), get_batch_size_option(), parse_and_validate_value(), parse_one_reloption(), postgres_fdw_validator(), and postgresAcquireSampleRowsFunc().

◆ parse_real()

bool parse_real ( const char *  value,
double *  result,
int  flags,
const char **  hintmsg 
)

Definition at line 2914 of file guc.c.

2915 {
2916  double val;
2917  char *endptr;
2918 
2919  /* To suppress compiler warnings, always set output params */
2920  if (result)
2921  *result = 0;
2922  if (hintmsg)
2923  *hintmsg = NULL;
2924 
2925  errno = 0;
2926  val = strtod(value, &endptr);
2927 
2928  if (endptr == value || errno == ERANGE)
2929  return false; /* no HINT for these cases */
2930 
2931  /* reject NaN (infinities will fail range checks later) */
2932  if (isnan(val))
2933  return false; /* treat same as syntax error; no HINT */
2934 
2935  /* allow whitespace between number and unit */
2936  while (isspace((unsigned char) *endptr))
2937  endptr++;
2938 
2939  /* Handle possible unit */
2940  if (*endptr != '\0')
2941  {
2942  if ((flags & GUC_UNIT) == 0)
2943  return false; /* this setting does not accept a unit */
2944 
2946  endptr, (flags & GUC_UNIT),
2947  &val))
2948  {
2949  /* invalid unit, or garbage after the unit; set hint and fail. */
2950  if (hintmsg)
2951  {
2952  if (flags & GUC_UNIT_MEMORY)
2953  *hintmsg = memory_units_hint;
2954  else
2955  *hintmsg = time_units_hint;
2956  }
2957  return false;
2958  }
2959  }
2960 
2961  if (result)
2962  *result = val;
2963  return true;
2964 }

References convert_to_base_unit(), config_generic::flags, GUC_UNIT, GUC_UNIT_MEMORY, memory_units_hint, time_units_hint, val, and value.

Referenced by apply_server_options(), parse_and_validate_value(), parse_one_reloption(), and postgres_fdw_validator().

◆ ParseLongOption()

void ParseLongOption ( const char *  string,
char **  name,
char **  value 
)

Definition at line 6186 of file guc.c.

6187 {
6188  size_t equal_pos;
6189  char *cp;
6190 
6191  Assert(string);
6192  Assert(name);
6193  Assert(value);
6194 
6195  equal_pos = strcspn(string, "=");
6196 
6197  if (string[equal_pos] == '=')
6198  {
6199  *name = palloc(equal_pos + 1);
6200  strlcpy(*name, string, equal_pos + 1);
6201 
6202  *value = pstrdup(&string[equal_pos + 1]);
6203  }
6204  else
6205  {
6206  /* no equal sign in string */
6207  *name = pstrdup(string);
6208  *value = NULL;
6209  }
6210 
6211  for (cp = *name; *cp; cp++)
6212  if (*cp == '-')
6213  *cp = '_';
6214 }
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: strlcpy.c:45

References Assert(), name, palloc(), pstrdup(), strlcpy(), and value.

Referenced by BootstrapModeMain(), PostmasterMain(), process_postgres_switches(), and TransformGUCArray().

◆ pg_timezone_abbrev_initialize()

static void pg_timezone_abbrev_initialize ( void  )
static

Definition at line 1958 of file guc.c.

1959 {
1960  SetConfigOption("timezone_abbreviations", "Default",
1962 }

References PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT, and SetConfigOption().

Referenced by ProcessConfigFileInternal(), and SelectConfigFiles().

◆ ProcessConfigFileInternal()

ConfigVariable* ProcessConfigFileInternal ( GucContext  context,
bool  applySettings,
int  elevel 
)

Definition at line 275 of file guc.c.

276 {
277  bool error = false;
278  bool applying = false;
279  const char *ConfFileWithError;
280  ConfigVariable *item,
281  *head,
282  *tail;
283  HASH_SEQ_STATUS status;
284  GUCHashEntry *hentry;
285 
286  /* Parse the main config file into a list of option names and values */
287  ConfFileWithError = ConfigFileName;
288  head = tail = NULL;
289 
290  if (!ParseConfigFile(ConfigFileName, true,
291  NULL, 0, CONF_FILE_START_DEPTH, elevel,
292  &head, &tail))
293  {
294  /* Syntax error(s) detected in the file, so bail out */
295  error = true;
296  goto bail_out;
297  }
298 
299  /*
300  * Parse the PG_AUTOCONF_FILENAME file, if present, after the main file to
301  * replace any parameters set by ALTER SYSTEM command. Because this file
302  * is in the data directory, we can't read it until the DataDir has been
303  * set.
304  */
305  if (DataDir)
306  {
308  NULL, 0, CONF_FILE_START_DEPTH, elevel,
309  &head, &tail))
310  {
311  /* Syntax error(s) detected in the file, so bail out */
312  error = true;
313  ConfFileWithError = PG_AUTOCONF_FILENAME;
314  goto bail_out;
315  }
316  }
317  else
318  {
319  /*
320  * If DataDir is not set, the PG_AUTOCONF_FILENAME file cannot be
321  * read. In this case, we don't want to accept any settings but
322  * data_directory from postgresql.conf, because they might be
323  * overwritten with settings in the PG_AUTOCONF_FILENAME file which
324  * will be read later. OTOH, since data_directory isn't allowed in the
325  * PG_AUTOCONF_FILENAME file, it will never be overwritten later.
326  */
327  ConfigVariable *newlist = NULL;
328 
329  /*
330  * Prune all items except the last "data_directory" from the list.
331  */
332  for (item = head; item; item = item->next)
333  {
334  if (!item->ignore &&
335  strcmp(item->name, "data_directory") == 0)
336  newlist = item;
337  }
338 
339  if (newlist)
340  newlist->next = NULL;
341  head = tail = newlist;
342 
343  /*
344  * Quick exit if data_directory is not present in file.
345  *
346  * We need not do any further processing, in particular we don't set
347  * PgReloadTime; that will be set soon by subsequent full loading of
348  * the config file.
349  */
350  if (head == NULL)
351  goto bail_out;
352  }
353 
354  /*
355  * Mark all extant GUC variables as not present in the config file. We
356  * need this so that we can tell below which ones have been removed from
357  * the file since we last processed it.
358  */
359  hash_seq_init(&status, guc_hashtab);
360  while ((hentry = (GUCHashEntry *) hash_seq_search(&status)) != NULL)
361  {
362  struct config_generic *gconf = hentry->gucvar;
363 
364  gconf->status &= ~GUC_IS_IN_FILE;
365  }
366 
367  /*
368  * Check if all the supplied option names are valid, as an additional
369  * quasi-syntactic check on the validity of the config file. It is
370  * important that the postmaster and all backends agree on the results of
371  * this phase, else we will have strange inconsistencies about which
372  * processes accept a config file update and which don't. Hence, unknown
373  * custom variable names have to be accepted without complaint. For the
374  * same reason, we don't attempt to validate the options' values here.
375  *
376  * In addition, the GUC_IS_IN_FILE flag is set on each existing GUC
377  * variable mentioned in the file; and we detect duplicate entries in the
378  * file and mark the earlier occurrences as ignorable.
379  */
380  for (item = head; item; item = item->next)
381  {
382  struct config_generic *record;
383 
384  /* Ignore anything already marked as ignorable */
385  if (item->ignore)
386  continue;
387 
388  /*
389  * Try to find the variable; but do not create a custom placeholder if
390  * it's not there already.
391  */
392  record = find_option(item->name, false, true, elevel);
393 
394  if (record)
395  {
396  /* If it's already marked, then this is a duplicate entry */
397  if (record->status & GUC_IS_IN_FILE)
398  {
399  /*
400  * Mark the earlier occurrence(s) as dead/ignorable. We could
401  * avoid the O(N^2) behavior here with some additional state,
402  * but it seems unlikely to be worth the trouble.
403  */
404  ConfigVariable *pitem;
405 
406  for (pitem = head; pitem != item; pitem = pitem->next)
407  {
408  if (!pitem->ignore &&
409  strcmp(pitem->name, item->name) == 0)
410  pitem->ignore = true;
411  }
412  }
413  /* Now mark it as present in file */
414  record->status |= GUC_IS_IN_FILE;
415  }
416  else if (!valid_custom_variable_name(item->name))
417  {
418  /* Invalid non-custom variable, so complain */
419  ereport(elevel,
420  (errcode(ERRCODE_UNDEFINED_OBJECT),
421  errmsg("unrecognized configuration parameter \"%s\" in file \"%s\" line %d",
422  item->name,
423  item->filename, item->sourceline)));
424  item->errmsg = pstrdup("unrecognized configuration parameter");
425  error = true;
426  ConfFileWithError = item->filename;
427  }
428  }
429 
430  /*
431  * If we've detected any errors so far, we don't want to risk applying any
432  * changes.
433  */
434  if (error)
435  goto bail_out;
436 
437  /* Otherwise, set flag that we're beginning to apply changes */
438  applying = true;
439 
440  /*
441  * Check for variables having been removed from the config file, and
442  * revert their reset values (and perhaps also effective values) to the
443  * boot-time defaults. If such a variable can't be changed after startup,
444  * report that and continue.
445  */
447  while ((hentry = (GUCHashEntry *) hash_seq_search(&status)) != NULL)
448  {
449  struct config_generic *gconf = hentry->gucvar;
450  GucStack *stack;
451 
452  if (gconf->reset_source != PGC_S_FILE ||
453  (gconf->status & GUC_IS_IN_FILE))
454  continue;
455  if (gconf->context < PGC_SIGHUP)
456  {
457  /* The removal can't be effective without a restart */
458  gconf->status |= GUC_PENDING_RESTART;
459  ereport(elevel,
460  (errcode(ERRCODE_CANT_CHANGE_RUNTIME_PARAM),
461  errmsg("parameter \"%s\" cannot be changed without restarting the server",
462  gconf->name)));
463  record_config_file_error(psprintf("parameter \"%s\" cannot be changed without restarting the server",
464  gconf->name),
465  NULL, 0,
466  &head, &tail);
467  error = true;
468  continue;
469  }
470 
471  /* No more to do if we're just doing show_all_file_settings() */
472  if (!applySettings)
473  continue;
474 
475  /*
476  * Reset any "file" sources to "default", else set_config_option will
477  * not override those settings.
478  */
479  if (gconf->reset_source == PGC_S_FILE)
480  gconf->reset_source = PGC_S_DEFAULT;
481  if (gconf->source == PGC_S_FILE)
483  for (stack = gconf->stack; stack; stack = stack->prev)
484  {
485  if (stack->source == PGC_S_FILE)
487  }
488 
489  /* Now we can re-apply the wired-in default (i.e., the boot_val) */
490  if (set_config_option(gconf->name, NULL,
492  GUC_ACTION_SET, true, 0, false) > 0)
493  {
494  /* Log the change if appropriate */
495  if (context == PGC_SIGHUP)
496  ereport(elevel,
497  (errmsg("parameter \"%s\" removed from configuration file, reset to default",
498  gconf->name)));
499  }
500  }
501 
502  /*
503  * Restore any variables determined by environment variables or
504  * dynamically-computed defaults. This is a no-op except in the case
505  * where one of these had been in the config file and is now removed.
506  *
507  * In particular, we *must not* do this during the postmaster's initial
508  * loading of the file, since the timezone functions in particular should
509  * be run only after initialization is complete.
510  *
511  * XXX this is an unmaintainable crock, because we have to know how to set
512  * (or at least what to call to set) every non-PGC_INTERNAL variable that
513  * could potentially have PGC_S_DYNAMIC_DEFAULT or PGC_S_ENV_VAR source.
514  */
515  if (context == PGC_SIGHUP && applySettings)
516  {
519  /* this selects SQL_ASCII in processes not connected to a database */
520  SetConfigOption("client_encoding", GetDatabaseEncodingName(),
522  }
523 
524  /*
525  * Now apply the values from the config file.
526  */
527  for (item = head; item; item = item->next)
528  {
529  char *pre_value = NULL;
530  int scres;
531 
532  /* Ignore anything marked as ignorable */
533  if (item->ignore)
534  continue;
535 
536  /* In SIGHUP cases in the postmaster, we want to report changes */
537  if (context == PGC_SIGHUP && applySettings && !IsUnderPostmaster)
538  {
539  const char *preval = GetConfigOption(item->name, true, false);
540 
541  /* If option doesn't exist yet or is NULL, treat as empty string */
542  if (!preval)
543  preval = "";
544  /* must dup, else might have dangling pointer below */
545  pre_value = pstrdup(preval);
546  }
547 
548  scres = set_config_option(item->name, item->value,
550  GUC_ACTION_SET, applySettings, 0, false);
551  if (scres > 0)
552  {
553  /* variable was updated, so log the change if appropriate */
554  if (pre_value)
555  {
556  const char *post_value = GetConfigOption(item->name, true, false);
557 
558  if (!post_value)
559  post_value = "";
560  if (strcmp(pre_value, post_value) != 0)
561  ereport(elevel,
562  (errmsg("parameter \"%s\" changed to \"%s\"",
563  item->name, item->value)));
564  }
565  item->applied = true;
566  }
567  else if (scres == 0)
568  {
569  error = true;
570  item->errmsg = pstrdup("setting could not be applied");
571  ConfFileWithError = item->filename;
572  }
573  else
574  {
575  /* no error, but variable's active value was not changed */
576  item->applied = true;
577  }
578 
579  /*
580  * We should update source location unless there was an error, since
581  * even if the active value didn't change, the reset value might have.
582  * (In the postmaster, there won't be a difference, but it does matter
583  * in backends.)
584  */
585  if (scres != 0 && applySettings)
586  set_config_sourcefile(item->name, item->filename,
587  item->sourceline);
588 
589  if (pre_value)
590  pfree(pre_value);
591  }
592 
593  /* Remember when we last successfully loaded the config file. */
594  if (applySettings)
596 
597 bail_out:
598  if (error && applySettings)
599  {
600  /* During postmaster startup, any error is fatal */
601  if (context == PGC_POSTMASTER)
602  ereport(ERROR,
603  (errcode(ERRCODE_CONFIG_FILE_ERROR),
604  errmsg("configuration file \"%s\" contains errors",
605  ConfFileWithError)));
606  else if (applying)
607  ereport(elevel,
608  (errcode(ERRCODE_CONFIG_FILE_ERROR),
609  errmsg("configuration file \"%s\" contains errors; unaffected changes were applied",
610  ConfFileWithError)));
611  else
612  ereport(elevel,
613  (errcode(ERRCODE_CONFIG_FILE_ERROR),
614  errmsg("configuration file \"%s\" contains errors; no changes were applied",
615  ConfFileWithError)));
616  }
617 
618  /* Successful or otherwise, return the collected data list */
619  return head;
620 }
TimestampTz PgReloadTime
Definition: timestamp.c:56
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1583
bool IsUnderPostmaster
Definition: globals.c:113
char * DataDir
Definition: globals.c:66
static void pg_timezone_abbrev_initialize(void)
Definition: guc.c:1958
const char * GetConfigOption(const char *name, bool missing_ok, bool restrict_privileged)
Definition: guc.c:4200
int set_config_option(const char *name, const char *value, GucContext context, GucSource source, GucAction action, bool changeVal, int elevel, bool is_reload)
Definition: guc.c:3284
bool ParseConfigFile(const char *config_file, bool strict, const char *calling_file, int calling_lineno, int depth, int elevel, ConfigVariable **head_p, ConfigVariable **tail_p)
@ PGC_SIGHUP
Definition: guc.h:71
@ PGC_BACKEND
Definition: guc.h:73
void record_config_file_error(const char *errmsg, const char *config_file, int lineno, ConfigVariable **head_p, ConfigVariable **tail_p)
char * ConfigFileName
Definition: guc_tables.c:536
#define GUC_IS_IN_FILE
Definition: guc_tables.h:186
#define GUC_PENDING_RESTART
Definition: guc_tables.h:191
const char * GetDatabaseEncodingName(void)
Definition: mbutils.c:1274
static void bail_out(bool noatexit, const char *fmt,...) pg_attribute_printf(2
Definition: pg_regress.c:246
static void error(void)
Definition: sql-dyntest.c:147
char * name
Definition: guc.h:137
bool ignore
Definition: guc.h:142
struct ConfigVariable * next
Definition: guc.h:144
bool applied
Definition: guc.h:143
char * filename
Definition: guc.h:140
int sourceline
Definition: guc.h:141
char * value
Definition: guc.h:138
char * errmsg
Definition: guc.h:139

References ConfigVariable::applied, bail_out(), CONF_FILE_START_DEPTH, ConfigFileName, config_generic::context, DataDir, ereport, errcode(), errmsg(), ConfigVariable::errmsg, ERROR, error(), ConfigVariable::filename, find_option(), GetConfigOption(), GetCurrentTimestamp(), GetDatabaseEncodingName(), GUC_ACTION_SET, guc_hashtab, GUC_IS_IN_FILE, GUC_PENDING_RESTART, GUCHashEntry::gucvar, hash_seq_init(), hash_seq_search(), ConfigVariable::ignore, InitializeGUCOptionsFromEnvironment(), IsUnderPostmaster, ConfigVariable::name, config_generic::name, ConfigVariable::next, ParseConfigFile(), pfree(), PG_AUTOCONF_FILENAME, pg_timezone_abbrev_initialize(), PGC_BACKEND, PGC_POSTMASTER, PGC_S_DEFAULT, PGC_S_DYNAMIC_DEFAULT, PGC_S_FILE, PGC_SIGHUP, PgReloadTime, guc_stack::prev, psprintf(), pstrdup(), record_config_file_error(), config_generic::reset_source, set_config_option(), set_config_sourcefile(), set_guc_source(), SetConfigOption(), guc_stack::source, config_generic::source, ConfigVariable::sourceline, config_generic::stack, config_generic::status, valid_custom_variable_name(), and ConfigVariable::value.

Referenced by show_all_file_settings().

◆ ProcessGUCArray()

void ProcessGUCArray ( ArrayType array,
GucContext  context,
GucSource  source,
GucAction  action 
)

Definition at line 6280 of file guc.c.

6282 {
6283  List *gucNames;
6284  List *gucValues;
6285  ListCell *lc1;
6286  ListCell *lc2;
6287 
6288  TransformGUCArray(array, &gucNames, &gucValues);
6289  forboth(lc1, gucNames, lc2, gucValues)
6290  {
6291  char *name = lfirst(lc1);
6292  char *value = lfirst(lc2);
6293 
6294  (void) set_config_option(name, value,
6295  context, source,
6296  action, true, 0, false);
6297 
6298  pfree(name);
6299  pfree(value);
6300  }
6301 
6302  list_free(gucNames);
6303  list_free(gucValues);
6304 }
void TransformGUCArray(ArrayType *array, List **names, List **values)
Definition: guc.c:6223
void list_free(List *list)
Definition: list.c:1545
#define forboth(cell1, list1, cell2, list2)
Definition: pg_list.h:467
Definition: pg_list.h:54

References generate_unaccent_rules::action, forboth, lfirst, list_free(), name, pfree(), set_config_option(), source, TransformGUCArray(), and value.

Referenced by ApplySetting(), and ProcedureCreate().

◆ push_old_value()

static void push_old_value ( struct config_generic gconf,
GucAction  action 
)
static

Definition at line 2100 of file guc.c.

2101 {
2102  GucStack *stack;
2103 
2104  /* If we're not inside a nest level, do nothing */
2105  if (GUCNestLevel == 0)
2106  return;
2107 
2108  /* Do we already have a stack entry of the current nest level? */
2109  stack = gconf->stack;
2110  if (stack && stack->nest_level >= GUCNestLevel)
2111  {
2112  /* Yes, so adjust its state if necessary */
2113  Assert(stack->nest_level == GUCNestLevel);
2114  switch (action)
2115  {
2116  case GUC_ACTION_SET:
2117  /* SET overrides any prior action at same nest level */
2118  if (stack->state == GUC_SET_LOCAL)
2119  {
2120  /* must discard old masked value */
2121  discard_stack_value(gconf, &stack->masked);
2122  }
2123  stack->state = GUC_SET;
2124  break;
2125  case GUC_ACTION_LOCAL:
2126  if (stack->state == GUC_SET)
2127  {
2128  /* SET followed by SET LOCAL, remember SET's value */
2129  stack->masked_scontext = gconf->scontext;
2130  stack->masked_srole = gconf->srole;
2131  set_stack_value(gconf, &stack->masked);
2132  stack->state = GUC_SET_LOCAL;
2133  }
2134  /* in all other cases, no change to stack entry */
2135  break;
2136  case GUC_ACTION_SAVE:
2137  /* Could only have a prior SAVE of same variable */
2138  Assert(stack->state == GUC_SAVE);
2139  break;
2140  }
2141  return;
2142  }
2143 
2144  /*
2145  * Push a new stack entry
2146  *
2147  * We keep all the stack entries in TopTransactionContext for simplicity.
2148  */
2150  sizeof(GucStack));
2151 
2152  stack->prev = gconf->stack;
2153  stack->nest_level = GUCNestLevel;
2154  switch (action)
2155  {
2156  case GUC_ACTION_SET:
2157  stack->state = GUC_SET;
2158  break;
2159  case GUC_ACTION_LOCAL:
2160  stack->state = GUC_LOCAL;
2161  break;
2162  case GUC_ACTION_SAVE:
2163  stack->state = GUC_SAVE;
2164  break;
2165  }
2166  stack->source = gconf->source;
2167  stack->scontext = gconf->scontext;
2168  stack->srole = gconf->srole;
2169  set_stack_value(gconf, &stack->prior);
2170 
2171  if (gconf->stack == NULL)
2173  gconf->stack = stack;
2174 }
static void set_stack_value(struct config_generic *gconf, config_var_value *val)
Definition: guc.c:805
@ GUC_ACTION_SAVE
Definition: guc.h:199
@ GUC_ACTION_LOCAL
Definition: guc.h:198
MemoryContext TopTransactionContext
Definition: mcxt.c:146
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:1064

References generate_unaccent_rules::action, Assert(), discard_stack_value(), GUC_ACTION_LOCAL, GUC_ACTION_SAVE, GUC_ACTION_SET, GUC_LOCAL, GUC_SAVE, GUC_SET, GUC_SET_LOCAL, guc_stack_list, GUCNestLevel, guc_stack::masked, guc_stack::masked_scontext, guc_stack::masked_srole, MemoryContextAllocZero(), guc_stack::nest_level, guc_stack::prev, guc_stack::prior, guc_stack::scontext, config_generic::scontext, set_stack_value(), slist_push_head(), guc_stack::source, config_generic::source, guc_stack::srole, config_generic::srole, config_generic::stack, config_generic::stack_link, guc_stack::state, and TopTransactionContext.

Referenced by ResetAllOptions(), and set_config_option_ext().

◆ read_gucstate()

static char* read_gucstate ( char **  srcptr,
char *  srcend 
)
static

Definition at line 5958 of file guc.c.

5959 {
5960  char *retptr = *srcptr;
5961  char *ptr;
5962 
5963  if (*srcptr >= srcend)
5964  elog(ERROR, "incomp