diff options
Diffstat (limited to 'src/util/program.c')
-rw-r--r-- | src/util/program.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/util/program.c b/src/util/program.c index aae58db49..73003891e 100644 --- a/src/util/program.c +++ b/src/util/program.c | |||
@@ -145,6 +145,8 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, | |||
145 | #endif | 145 | #endif |
146 | char *loglev; | 146 | char *loglev; |
147 | char *logfile; | 147 | char *logfile; |
148 | char *cfg_fn; | ||
149 | const char *xdg; | ||
148 | int ret; | 150 | int ret; |
149 | unsigned int cnt; | 151 | unsigned int cnt; |
150 | unsigned long long skew_offset; | 152 | unsigned long long skew_offset; |
@@ -195,7 +197,6 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, | |||
195 | cc.task = task; | 197 | cc.task = task; |
196 | cc.task_cls = task_cls; | 198 | cc.task_cls = task_cls; |
197 | cc.cfg = cfg = GNUNET_CONFIGURATION_create (); | 199 | cc.cfg = cfg = GNUNET_CONFIGURATION_create (); |
198 | |||
199 | /* prepare */ | 200 | /* prepare */ |
200 | #if ENABLE_NLS | 201 | #if ENABLE_NLS |
201 | setlocale (LC_ALL, ""); | 202 | setlocale (LC_ALL, ""); |
@@ -223,7 +224,15 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, | |||
223 | qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), | 224 | qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), |
224 | &cmd_sorter); | 225 | &cmd_sorter); |
225 | loglev = NULL; | 226 | loglev = NULL; |
226 | cc.cfgfile = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE); | 227 | xdg = getenv ("XDG_CONFIG_HOME"); |
228 | if (NULL != xdg) | ||
229 | GNUNET_asprintf (&cfg_fn, | ||
230 | "%s%s%s", | ||
231 | xdg, | ||
232 | DIR_SEPARATOR_STR, | ||
233 | "gnunet.config"); | ||
234 | else | ||
235 | cfg_fn = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE); | ||
227 | lpfx = GNUNET_strdup (binaryName); | 236 | lpfx = GNUNET_strdup (binaryName); |
228 | if (NULL != (spc = strstr (lpfx, " "))) | 237 | if (NULL != (spc = strstr (lpfx, " "))) |
229 | *spc = '\0'; | 238 | *spc = '\0'; |
@@ -239,13 +248,15 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, | |||
239 | GNUNET_free (lpfx); | 248 | GNUNET_free (lpfx); |
240 | return (ret == GNUNET_SYSERR) ? GNUNET_SYSERR : GNUNET_OK; | 249 | return (ret == GNUNET_SYSERR) ? GNUNET_SYSERR : GNUNET_OK; |
241 | } | 250 | } |
251 | if (NULL == cc.cfgfile) | ||
252 | cc.cfgfile = GNUNET_strdup (cfg_fn); | ||
242 | if (GNUNET_YES == | 253 | if (GNUNET_YES == |
243 | GNUNET_DISK_file_test (cc.cfgfile)) | 254 | GNUNET_DISK_file_test (cc.cfgfile)) |
244 | (void) GNUNET_CONFIGURATION_load (cfg, cc.cfgfile); | 255 | (void) GNUNET_CONFIGURATION_load (cfg, cc.cfgfile); |
245 | else | 256 | else |
246 | { | 257 | { |
247 | (void) GNUNET_CONFIGURATION_load (cfg, NULL); | 258 | (void) GNUNET_CONFIGURATION_load (cfg, NULL); |
248 | if (0 != strcmp (cc.cfgfile, GNUNET_DEFAULT_USER_CONFIG_FILE)) | 259 | if (0 != strcmp (cc.cfgfile, cfg_fn)) |
249 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 260 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
250 | _("Could not access configuration file `%s'\n"), | 261 | _("Could not access configuration file `%s'\n"), |
251 | cc.cfgfile); | 262 | cc.cfgfile); |
@@ -276,7 +287,8 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, | |||
276 | /* clean up */ | 287 | /* clean up */ |
277 | GNUNET_SPEEDUP_stop_ (); | 288 | GNUNET_SPEEDUP_stop_ (); |
278 | GNUNET_CONFIGURATION_destroy (cfg); | 289 | GNUNET_CONFIGURATION_destroy (cfg); |
279 | GNUNET_free_non_null (cc.cfgfile); | 290 | GNUNET_free (cc.cfgfile); |
291 | GNUNET_free (cfg_fn); | ||
280 | GNUNET_free_non_null (loglev); | 292 | GNUNET_free_non_null (loglev); |
281 | GNUNET_free_non_null (logfile); | 293 | GNUNET_free_non_null (logfile); |
282 | return GNUNET_OK; | 294 | return GNUNET_OK; |
@@ -292,8 +304,8 @@ GNUNET_PROGRAM_run2 (int argc, char *const *argv, const char *binaryName, | |||
292 | * @param binaryHelp help text for the program | 304 | * @param binaryHelp help text for the program |
293 | * @param options command line options | 305 | * @param options command line options |
294 | * @param task main function to run | 306 | * @param task main function to run |
295 | * @param task_cls closure for task | 307 | * @param task_cls closure for @a task |
296 | * @return GNUNET_SYSERR on error, GNUNET_OK on success | 308 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success |
297 | */ | 309 | */ |
298 | int | 310 | int |
299 | GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, | 311 | GNUNET_PROGRAM_run (int argc, char *const *argv, const char *binaryName, |