diff options
Diffstat (limited to 'src/util/program.c')
-rw-r--r-- | src/util/program.c | 89 |
1 files changed, 45 insertions, 44 deletions
diff --git a/src/util/program.c b/src/util/program.c index e34b37370..b9da14572 100644 --- a/src/util/program.c +++ b/src/util/program.c | |||
@@ -140,7 +140,6 @@ GNUNET_PROGRAM_run2 (int argc, | |||
140 | char *loglev; | 140 | char *loglev; |
141 | char *logfile; | 141 | char *logfile; |
142 | char *cfg_fn; | 142 | char *cfg_fn; |
143 | const char *xdg; | ||
144 | enum GNUNET_GenericReturnValue ret; | 143 | enum GNUNET_GenericReturnValue ret; |
145 | int iret; | 144 | int iret; |
146 | unsigned int cnt; | 145 | unsigned int cnt; |
@@ -149,12 +148,13 @@ GNUNET_PROGRAM_run2 (int argc, | |||
149 | long long clock_offset; | 148 | long long clock_offset; |
150 | struct GNUNET_CONFIGURATION_Handle *cfg; | 149 | struct GNUNET_CONFIGURATION_Handle *cfg; |
151 | const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get (); | 150 | const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get (); |
152 | struct GNUNET_GETOPT_CommandLineOption defoptions[] = | 151 | struct GNUNET_GETOPT_CommandLineOption defoptions[] = { |
153 | { GNUNET_GETOPT_option_cfgfile (&cc.cfgfile), | 152 | GNUNET_GETOPT_option_cfgfile (&cc.cfgfile), |
154 | GNUNET_GETOPT_option_help (binaryHelp), | 153 | GNUNET_GETOPT_option_help (binaryHelp), |
155 | GNUNET_GETOPT_option_loglevel (&loglev), | 154 | GNUNET_GETOPT_option_loglevel (&loglev), |
156 | GNUNET_GETOPT_option_logfile (&logfile), | 155 | GNUNET_GETOPT_option_logfile (&logfile), |
157 | GNUNET_GETOPT_option_version (pd->version) }; | 156 | GNUNET_GETOPT_option_version (pd->version) |
157 | }; | ||
158 | struct GNUNET_GETOPT_CommandLineOption *allopts; | 158 | struct GNUNET_GETOPT_CommandLineOption *allopts; |
159 | const char *gargs; | 159 | const char *gargs; |
160 | char *lpfx; | 160 | char *lpfx; |
@@ -219,17 +219,7 @@ GNUNET_PROGRAM_run2 (int argc, | |||
219 | &cmd_sorter); | 219 | &cmd_sorter); |
220 | loglev = NULL; | 220 | loglev = NULL; |
221 | if ((NULL != pd->config_file) && (NULL != pd->user_config_file)) | 221 | if ((NULL != pd->config_file) && (NULL != pd->user_config_file)) |
222 | { | 222 | cfg_fn = GNUNET_CONFIGURATION_default_filename (); |
223 | xdg = getenv ("XDG_CONFIG_HOME"); | ||
224 | if (NULL != xdg) | ||
225 | GNUNET_asprintf (&cfg_fn, | ||
226 | "%s%s%s", | ||
227 | xdg, | ||
228 | DIR_SEPARATOR_STR, | ||
229 | pd->config_file); | ||
230 | else | ||
231 | cfg_fn = GNUNET_strdup (pd->user_config_file); | ||
232 | } | ||
233 | else | 223 | else |
234 | cfg_fn = NULL; | 224 | cfg_fn = NULL; |
235 | lpfx = GNUNET_strdup (binaryName); | 225 | lpfx = GNUNET_strdup (binaryName); |
@@ -251,12 +241,26 @@ GNUNET_PROGRAM_run2 (int argc, | |||
251 | } | 241 | } |
252 | if (NULL != cc.cfgfile) | 242 | if (NULL != cc.cfgfile) |
253 | { | 243 | { |
254 | if ((GNUNET_YES != GNUNET_DISK_file_test (cc.cfgfile)) || | 244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
255 | (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cc.cfgfile))) | 245 | "Loading configuration from entry point specified as option (%s)\n", |
246 | cc.cfgfile); | ||
247 | if (GNUNET_YES != | ||
248 | GNUNET_DISK_file_test (cc.cfgfile)) | ||
256 | { | 249 | { |
257 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 250 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
258 | _ ( | 251 | _ ("Unreadable configuration file `%s', exiting ...\n"), |
259 | "Unreadable or malformed configuration file `%s', exit ...\n"), | 252 | cc.cfgfile); |
253 | ret = GNUNET_SYSERR; | ||
254 | GNUNET_free (allopts); | ||
255 | GNUNET_free (lpfx); | ||
256 | goto cleanup; | ||
257 | } | ||
258 | if (GNUNET_SYSERR == | ||
259 | GNUNET_CONFIGURATION_load (cfg, | ||
260 | cc.cfgfile)) | ||
261 | { | ||
262 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
263 | _ ("Malformed configuration file `%s', exiting ...\n"), | ||
260 | cc.cfgfile); | 264 | cc.cfgfile); |
261 | ret = GNUNET_SYSERR; | 265 | ret = GNUNET_SYSERR; |
262 | GNUNET_free (allopts); | 266 | GNUNET_free (allopts); |
@@ -266,34 +270,31 @@ GNUNET_PROGRAM_run2 (int argc, | |||
266 | } | 270 | } |
267 | else | 271 | else |
268 | { | 272 | { |
269 | if ((NULL != cfg_fn) && (GNUNET_YES == GNUNET_DISK_file_test (cfg_fn))) | 273 | if ( (NULL != cfg_fn) && |
274 | (GNUNET_YES != | ||
275 | GNUNET_DISK_file_test (cfg_fn)) ) | ||
270 | { | 276 | { |
271 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_fn)) | 277 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
272 | { | 278 | _ ("Unreadable configuration file `%s'. Exiting ...\n"), |
273 | GNUNET_log ( | 279 | cfg_fn); |
274 | GNUNET_ERROR_TYPE_ERROR, | 280 | ret = GNUNET_SYSERR; |
275 | _ ( | 281 | GNUNET_free (allopts); |
276 | "Unreadable or malformed default configuration file `%s', exit ...\n"), | 282 | GNUNET_free (lpfx); |
277 | cfg_fn); | 283 | goto cleanup; |
278 | ret = GNUNET_SYSERR; | ||
279 | GNUNET_free (allopts); | ||
280 | GNUNET_free (lpfx); | ||
281 | goto cleanup; | ||
282 | } | ||
283 | } | 284 | } |
284 | else if (NULL != cfg_fn) | 285 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
286 | "Loading configuration from entry point `%s'\n", | ||
287 | cc.cfgfile); | ||
288 | if (GNUNET_SYSERR == | ||
289 | GNUNET_CONFIGURATION_load (cfg, | ||
290 | cfg_fn)) | ||
285 | { | 291 | { |
286 | GNUNET_free (cfg_fn); | 292 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
287 | cfg_fn = NULL; | 293 | _ ("Malformed configuration. Exiting ...\n")); |
288 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, NULL)) | 294 | ret = GNUNET_SYSERR; |
289 | { | 295 | GNUNET_free (allopts); |
290 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 296 | GNUNET_free (lpfx); |
291 | _ ("Unreadable or malformed configuration, exit ...\n")); | 297 | goto cleanup; |
292 | ret = GNUNET_SYSERR; | ||
293 | GNUNET_free (allopts); | ||
294 | GNUNET_free (lpfx); | ||
295 | goto cleanup; | ||
296 | } | ||
297 | } | 298 | } |
298 | } | 299 | } |
299 | GNUNET_free (allopts); | 300 | GNUNET_free (allopts); |