89 |
p->prio = prio; |
p->prio = prio; |
90 |
} |
} |
91 |
|
|
92 |
|
/* A structure uniquely identifying a file */ |
93 |
|
struct file_id { |
94 |
|
dev_t dev; /* Device number */ |
95 |
|
ino_t ino; /* I-node number */ |
96 |
|
}; |
97 |
|
|
98 |
|
/* A list of struct file_id used to prevent duplicate parsing of the |
99 |
|
same file */ |
100 |
|
static LIST *file_id_list; |
101 |
|
|
102 |
|
/* Comparator for two struct file_id */ |
103 |
|
static int |
104 |
|
cmp_fid(void *a, void *b) |
105 |
|
{ |
106 |
|
struct file_id *fid_a = a, |
107 |
|
*fid_b = b; |
108 |
|
return !(fid_a->dev == fid_b->dev && fid_a->ino == fid_b->ino); |
109 |
|
} |
110 |
|
|
111 |
|
/* Adds the `filename' to file_id_list. |
112 |
|
Returns 0 if the operation passed successfully, 1 -- if the file |
113 |
|
is already present in the list, and -1 on error */ |
114 |
|
static int |
115 |
|
file_id_add (char *filename) |
116 |
|
{ |
117 |
|
struct stat st; |
118 |
|
struct file_id *fid; |
119 |
|
if (stat(filename, &st)) { |
120 |
|
anubis_error(SOFT, |
121 |
|
_("cannot stat file `%s': %s"), filename, |
122 |
|
strerror(errno)); |
123 |
|
return -1; |
124 |
|
} |
125 |
|
fid = xmalloc(sizeof(*fid)); |
126 |
|
fid->dev = st.st_dev; |
127 |
|
fid->ino = st.st_ino; |
128 |
|
if (list_locate(file_id_list, fid, cmp_fid)) { |
129 |
|
free(fid); |
130 |
|
info(DEBUG, |
131 |
|
_("File `%s' has already been read"), |
132 |
|
filename); |
133 |
|
return 1; |
134 |
|
} |
135 |
|
if (!file_id_list) |
136 |
|
file_id_list = list_create(); |
137 |
|
list_append(file_id_list, fid); |
138 |
|
return 0; |
139 |
|
} |
140 |
|
|
141 |
|
static void |
142 |
|
file_id_destroy() |
143 |
|
{ |
144 |
|
list_destroy(&file_id_list, anubis_free_list_item, NULL); |
145 |
|
} |
146 |
|
|
147 |
void |
void |
148 |
open_rcfile(int method) |
open_rcfile(int method) |
149 |
{ |
{ |
150 |
char homedir[MAXPATHLEN+1]; |
char homedir[MAXPATHLEN+1]; |
151 |
char *rcfile = 0; |
char *rcfile = 0; |
152 |
RC_SECTION *sec; |
RC_SECTION *sec; |
153 |
|
static int ctr = 0; |
154 |
|
if (ctr++ > 0) |
155 |
|
return; |
156 |
switch (method) { |
switch (method) { |
157 |
case CF_SUPERVISOR: |
case CF_SUPERVISOR: |
158 |
case CF_INIT: |
case CF_INIT: |
174 |
return; |
return; |
175 |
} |
} |
176 |
rc_section_list_destroy(&parse_tree); |
rc_section_list_destroy(&parse_tree); |
177 |
|
file_id_destroy(); |
178 |
info(DEBUG, |
info(DEBUG, |
179 |
_("Reading system configuration file %s..."), rcfile); |
_("Reading system configuration file %s..."), rcfile); |
180 |
break; |
break; |
200 |
return; |
return; |
201 |
} |
} |
202 |
|
|
203 |
sec = rc_parse(rcfile); |
if (file_id_add(rcfile) == 0) { |
204 |
/* FIXME: check 'sec' against anubis_rc_sections and remove the |
sec = rc_parse(rcfile); |
205 |
erroneous statements */ |
if (sec) |
206 |
|
rc_section_link(&parse_tree, sec); |
207 |
|
} |
208 |
free(rcfile); |
free(rcfile); |
|
|
|
|
if (sec) |
|
|
rc_section_link(&parse_tree, sec); |
|
209 |
} |
} |
210 |
|
|
211 |
void |
void |