PostgreSQL Source Code git master
Loading...
Searching...
No Matches
conffiles.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define CONF_FILE_START_DEPTH   0
 
#define CONF_FILE_MAX_DEPTH   10
 

Functions

charAbsoluteConfigLocation (const char *location, const char *calling_file)
 
char ** GetConfFilesInDir (const char *includedir, const char *calling_file, int elevel, int *num_filenames, char **err_msg)
 

Macro Definition Documentation

◆ CONF_FILE_MAX_DEPTH

#define CONF_FILE_MAX_DEPTH   10

Definition at line 18 of file conffiles.h.

◆ CONF_FILE_START_DEPTH

#define CONF_FILE_START_DEPTH   0

Definition at line 17 of file conffiles.h.

Function Documentation

◆ AbsoluteConfigLocation()

char * AbsoluteConfigLocation ( const char location,
const char calling_file 
)
extern

Definition at line 36 of file conffiles.c.

37{
38 if (is_absolute_path(location))
39 return pstrdup(location);
40 else
41 {
42 char abs_path[MAXPGPATH];
43
44 if (calling_file != NULL)
45 {
50 }
51 else
52 {
56 }
57 return pstrdup(abs_path);
58 }
59}
#define Assert(condition)
Definition c.h:873
char * DataDir
Definition globals.c:71
char * pstrdup(const char *in)
Definition mcxt.c:1781
#define MAXPGPATH
void join_path_components(char *ret_path, const char *head, const char *tail)
Definition path.c:286
#define is_absolute_path(filename)
Definition port.h:104
void canonicalize_path(char *path)
Definition path.c:337
void get_parent_directory(char *path)
Definition path.c:1068
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition strlcpy.c:45
static int fb(int x)

References Assert, canonicalize_path(), DataDir, fb(), get_parent_directory(), is_absolute_path, join_path_components(), MAXPGPATH, pstrdup(), and strlcpy().

Referenced by GetConfFilesInDir(), ParseConfigFile(), tokenize_expand_file(), and tokenize_include_file().

◆ GetConfFilesInDir()

char ** GetConfFilesInDir ( const char includedir,
const char calling_file,
int  elevel,
int num_filenames,
char **  err_msg 
)
extern

Definition at line 70 of file conffiles.c.

72{
73 char *directory;
74 DIR *d;
75 struct dirent *de;
76 char **filenames = NULL;
78
79 /*
80 * Reject directory name that is all-blank (including empty), as that
81 * leads to confusion --- we'd read the containing directory, typically
82 * resulting in recursive inclusion of the same file(s).
83 */
84 if (strspn(includedir, " \t\r\n") == strlen(includedir))
85 {
86 ereport(elevel,
88 errmsg("empty configuration directory name: \"%s\"",
89 includedir)));
90 *err_msg = "empty configuration directory name";
91 return NULL;
92 }
93
96 if (d == NULL)
97 {
98 ereport(elevel,
100 errmsg("could not open configuration directory \"%s\": %m",
101 directory)));
102 *err_msg = psprintf("could not open directory \"%s\"", directory);
103 goto cleanup;
104 }
105
106 /*
107 * Read the directory and put the filenames in an array, so we can sort
108 * them prior to caller processing the contents.
109 */
110 size_filenames = 32;
112 *num_filenames = 0;
113
114 while ((de = ReadDir(d, directory)) != NULL)
115 {
117 char filename[MAXPGPATH];
118
119 /*
120 * Only parse files with names ending in ".conf". Explicitly reject
121 * files starting with ".". This excludes things like "." and "..",
122 * as well as typical hidden files, backup files, and editor debris.
123 */
124 if (strlen(de->d_name) < 6)
125 continue;
126 if (de->d_name[0] == '.')
127 continue;
128 if (strcmp(de->d_name + strlen(de->d_name) - 5, ".conf") != 0)
129 continue;
130
133 de_type = get_dirent_type(filename, de, true, elevel);
135 {
136 *err_msg = psprintf("could not stat file \"%s\"", filename);
138 filenames = NULL;
139 goto cleanup;
140 }
141 else if (de_type != PGFILETYPE_DIR)
142 {
143 /* Add file to array, increasing its size in blocks of 32 */
145 {
146 size_filenames += 32;
147 filenames = (char **) repalloc(filenames,
148 size_filenames * sizeof(char *));
149 }
151 (*num_filenames)++;
152 }
153 }
154
155 /* Sort the files by name before leaving */
156 if (*num_filenames > 0)
157 qsort(filenames, *num_filenames, sizeof(char *), pg_qsort_strcmp);
158
159cleanup:
160 if (d)
161 FreeDir(d);
163 return filenames;
164}
static void cleanup(void)
Definition bootstrap.c:717
char * AbsoluteConfigLocation(const char *location, const char *calling_file)
Definition conffiles.c:36
int errcode_for_file_access(void)
Definition elog.c:886
int errcode(int sqlerrcode)
Definition elog.c:863
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define ereport(elevel,...)
Definition elog.h:150
int FreeDir(DIR *dir)
Definition fd.c:3005
DIR * AllocateDir(const char *dirname)
Definition fd.c:2887
struct dirent * ReadDir(DIR *dir, const char *dirname)
Definition fd.c:2953
#define palloc_array(type, count)
Definition fe_memutils.h:76
PGFileType get_dirent_type(const char *path, const struct dirent *de, bool look_through_symlinks, int elevel)
Definition file_utils.c:547
PGFileType
Definition file_utils.h:19
@ PGFILETYPE_DIR
Definition file_utils.h:23
@ PGFILETYPE_ERROR
Definition file_utils.h:20
void * repalloc(void *pointer, Size size)
Definition mcxt.c:1632
void pfree(void *pointer)
Definition mcxt.c:1616
static char * filename
Definition pg_dumpall.c:120
int pg_qsort_strcmp(const void *a, const void *b)
Definition qsort.c:19
#define qsort(a, b, c, d)
Definition port.h:495
char * psprintf(const char *fmt,...)
Definition psprintf.c:43
Definition dirent.c:26
static const char * directory
Definition zic.c:648

References AbsoluteConfigLocation(), AllocateDir(), canonicalize_path(), cleanup(), directory, ereport, errcode(), errcode_for_file_access(), errmsg(), fb(), filename, FreeDir(), get_dirent_type(), join_path_components(), MAXPGPATH, palloc_array, pfree(), pg_qsort_strcmp(), PGFILETYPE_DIR, PGFILETYPE_ERROR, psprintf(), pstrdup(), qsort, ReadDir(), and repalloc().

Referenced by ParseConfigDirectory(), and tokenize_auth_file().