- loglev = GNUNET_strdup ("WARNING");
- if ((-1 == (ret = GNUNET_GETOPT_run (binaryName,
- allopts,
- (unsigned int) argc, argv))) ||
- ((GNUNET_OK !=
- GNUNET_log_setup (binaryName,
- loglev,
- NULL)) ||
- (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cc.cfgfile))))
-
- {
- GNUNET_free_non_null (cc.cfgfile);
- GNUNET_free (loglev);
- GNUNET_free (allopts);
- return GNUNET_SYSERR;
- }
+ loglev = NULL;
+ xdg = getenv ("XDG_CONFIG_HOME");
+ if (NULL != xdg)
+ GNUNET_asprintf (&cfg_fn,
+ "%s%s%s",
+ xdg,
+ DIR_SEPARATOR_STR,
+ "gnunet.conf");
+ else
+ cfg_fn = GNUNET_strdup (GNUNET_DEFAULT_USER_CONFIG_FILE);
+ lpfx = GNUNET_strdup (binaryName);
+ if (NULL != (spc = strstr (lpfx, " ")))
+ *spc = '\0';
+ ret = GNUNET_GETOPT_run (binaryName, allopts, (unsigned int) argc, argv);
+ if ((GNUNET_OK > ret) ||
+ (GNUNET_OK != GNUNET_log_setup (lpfx, loglev, logfile)))
+ {
+ GNUNET_CONFIGURATION_destroy (cfg);
+ GNUNET_free_non_null (cc.cfgfile);
+ GNUNET_free_non_null (loglev);
+ GNUNET_free_non_null (logfile);
+ GNUNET_free (cfg_fn);
+ GNUNET_free (allopts);
+ GNUNET_free (lpfx);
+ return (ret == GNUNET_SYSERR) ? GNUNET_SYSERR : GNUNET_OK;
+ }
+ if (NULL == cc.cfgfile)
+ cc.cfgfile = GNUNET_strdup (cfg_fn);
+ if (GNUNET_YES ==
+ GNUNET_DISK_file_test (cc.cfgfile))
+ (void) GNUNET_CONFIGURATION_load (cfg, cc.cfgfile);
+ else
+ {
+ (void) GNUNET_CONFIGURATION_load (cfg, NULL);
+ if (0 != strcmp (cc.cfgfile, cfg_fn))
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Could not access configuration file `%s'\n"),
+ cc.cfgfile);
+ }