92 ConfigFile *objectfile = cfgmgr_get_file(vs->objectfile); |
92 ConfigFile *objectfile = cfgmgr_get_file(vs->objectfile); |
93 vs->objects = objectfile->data; |
93 vs->objects = objectfile->data; |
94 return vs; |
94 return vs; |
95 } |
95 } |
96 |
96 |
|
97 int cfgmgr_reload_file(ConfigFile *f, ServerConfiguration *conf, int *reload) { |
|
98 struct stat s; |
|
99 if(stat(f->file.ptr, &s) != 0) { |
|
100 fprintf( |
|
101 stderr, |
|
102 "Error: Cannot get stat of file %s\n", f->file.ptr); |
|
103 perror("cfgmgr_load_config: stat"); |
|
104 return -1; |
|
105 } |
|
106 |
|
107 //printf("1 time: %d - %d\n", f->last_modified, s.st_mtim.tv_sec); |
|
108 if(f->last_modified != s.st_mtim.tv_sec) { |
|
109 /* reload the file */ |
|
110 printf("reload: %s\n", f->file.ptr); |
|
111 log_ereport( |
|
112 LOG_INFORM, |
|
113 "reload configuration file: %s", |
|
114 f->file.ptr); |
|
115 f->reload(f, conf); |
|
116 f->last_modified = s.st_mtim.tv_sec; |
|
117 if(reload) { |
|
118 *reload = 1; |
|
119 } |
|
120 } |
|
121 return 0; |
|
122 } |
97 |
123 |
98 int cfgmgr_load_config() { |
124 int cfgmgr_load_config() { |
99 int cfgreload = 0; |
125 int cfgreload = 0; |
100 |
126 |
101 /* check config files */ |
127 /* check config files */ |
102 UcxMapIterator iter = ucx_map_iterator(config_files); |
128 UcxMapIterator iter = ucx_map_iterator(config_files); |
103 ConfigFile *f; |
129 ConfigFile *f; |
104 UCX_MAP_FOREACH(f, iter) { |
130 UCX_MAP_FOREACH(f, iter) { |
105 struct stat s; |
131 if(cfgmgr_reload_file(f, current_config, &cfgreload) == -1) { |
106 if(stat(f->file.ptr, &s) != 0) { |
|
107 fprintf( |
|
108 stderr, |
|
109 "Error: Cannot get stat of file %s\n", f->file.ptr); |
|
110 perror("cfgmgr_load_config: stat"); |
|
111 return -1; |
132 return -1; |
112 } |
|
113 |
|
114 if(f->last_modified != s.st_mtim.tv_sec) { |
|
115 /* reload the file */ |
|
116 //printf("reload: %s\n", sstrdup(f->file).ptr); |
|
117 log_ereport( |
|
118 LOG_INFORM, |
|
119 "reload configuration file: %s", |
|
120 f->file.ptr); |
|
121 f->reload(f, current_config); |
|
122 cfgreload = 1; |
|
123 } |
133 } |
124 } |
134 } |
125 |
135 |
126 struct stat s; |
136 struct stat s; |
127 if(stat("config/server.conf", &s) != 0) { |
137 if(stat("config/server.conf", &s) != 0) { |
179 |
189 |
180 } else { |
190 } else { |
181 printf("no reconfig required!\n"); |
191 printf("no reconfig required!\n"); |
182 config = current_config; |
192 config = current_config; |
183 } |
193 } |
184 |
194 |
185 |
195 ServerConfiguration *old_conf = NULL; |
|
196 if(current_config != config) { |
|
197 old_conf = current_config; |
|
198 } |
186 current_config = config; |
199 current_config = config; |
|
200 if(old_conf) { |
|
201 cfg_unref(old_conf); |
|
202 } |
187 return 0; |
203 return 0; |
188 } |
204 } |
189 |
205 |
190 ServerConfiguration *cfgmgr_get_server_config() { |
206 ServerConfiguration *cfgmgr_get_server_config() { |
|
207 //cfg_ref(current_config); |
191 return current_config; |
208 return current_config; |
192 } |
209 } |
193 |
210 |
194 |
211 |