Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6d09b21

Browse files
committed
include_if_exists facility for config file.
This works the same as include, except that an error is not thrownif the file is missing. Instead the fact that it's missing islogged.Greg Smith, reviewed by Euler Taveira de Oliveira.
1 parent1da5c11 commit6d09b21

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

‎doc/src/sgml/config.sgml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ include 'filename'
8989
Inclusions can be nested.
9090
</para>
9191

92+
<para>
93+
<indexterm>
94+
<primary><literal>include_if_exists</></primary>
95+
<secondary>in configuration file</secondary>
96+
</indexterm>
97+
Use the same approach as the <literal>include</> directive, continuing
98+
normally if the file does not exist. A regular <literal>include</>
99+
will stop with an error if the referenced file is missing, while
100+
<literal>include_if_exists</> does not. A warning about the missing
101+
file will be logged.
102+
</para>
103+
92104
<para>
93105
<indexterm>
94106
<primary>SIGHUP</primary>

‎src/backend/utils/misc/guc-file.l

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ ProcessConfigFile(GucContext context)
129129
/* Parse the file into a list of option names and values */
130130
head = tail = NULL;
131131
132-
if (!ParseConfigFile(ConfigFileName, NULL, 0, elevel, &head, &tail))
132+
if (!ParseConfigFile(ConfigFileName, NULL,true,0, elevel, &head, &tail))
133133
{
134134
/* Syntax error(s) detected in the file, so bail out */
135135
error = true;
@@ -363,7 +363,7 @@ ProcessConfigFile(GucContext context)
363363
* and absolute-ifying the path name if necessary.
364364
*/
365365
bool
366-
ParseConfigFile(constchar *config_file,constchar *calling_file,
366+
ParseConfigFile(constchar *config_file,constchar *calling_file,bool strict,
367367
int depth,int elevel,
368368
ConfigVariable **head_p,
369369
ConfigVariable **tail_p)
@@ -414,11 +414,19 @@ ParseConfigFile(const char *config_file, const char *calling_file,
414414
fp =AllocateFile(config_file,"r");
415415
if (!fp)
416416
{
417-
ereport(elevel,
418-
(errcode_for_file_access(),
419-
errmsg("could not open configuration file\"%s\": %m",
417+
if (strict)
418+
{
419+
ereport(elevel,
420+
(errcode_for_file_access(),
421+
errmsg("could not open configuration file\"%s\": %m",
422+
config_file)));
423+
returnfalse;
424+
}
425+
426+
ereport(LOG,
427+
(errmsg("skipping missing configuration file\"%s\"",
420428
config_file)));
421-
returnfalse;
429+
returnOK;
422430
}
423431

424432
OK =ParseConfigFp(fp, config_file, depth, elevel, head_p, tail_p);
@@ -512,15 +520,32 @@ ParseConfigFp(FILE *fp, const char *config_file, int depth, int elevel,
512520
}
513521

514522
/* OK, process the option name and value */
515-
if (guc_name_compare(opt_name,"include") ==0)
523+
if (guc_name_compare(opt_name,"include_if_exists") ==0)
524+
{
525+
/*
526+
* An include_if_exists directive isn't a variable and should be
527+
* processed immediately.
528+
*/
529+
unsignedint save_ConfigFileLineno = ConfigFileLineno;
530+
531+
if (!ParseConfigFile(opt_value, config_file,false,
532+
depth +1, elevel,
533+
head_p, tail_p))
534+
OK =false;
535+
yy_switch_to_buffer(lex_buffer);
536+
ConfigFileLineno = save_ConfigFileLineno;
537+
pfree(opt_name);
538+
pfree(opt_value);
539+
}
540+
elseif (guc_name_compare(opt_name,"include") ==0)
516541
{
517542
/*
518543
* An include directive isn't a variable and should be processed
519544
* immediately.
520545
*/
521546
unsignedint save_ConfigFileLineno = ConfigFileLineno;
522547

523-
if (!ParseConfigFile(opt_value, config_file,
548+
if (!ParseConfigFile(opt_value, config_file,true,
524549
depth +1, elevel,
525550
head_p, tail_p))
526551
OK =false;

‎src/include/utils/guc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ typedef struct ConfigVariable
111111
}ConfigVariable;
112112

113113
externboolParseConfigFile(constchar*config_file,constchar*calling_file,
114-
intdepth,intelevel,
114+
boolstrict,intdepth,intelevel,
115115
ConfigVariable**head_p,ConfigVariable**tail_p);
116116
externboolParseConfigFp(FILE*fp,constchar*config_file,
117117
intdepth,intelevel,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp