diff options
author | Florian Dold <florian@dold.me> | 2021-07-29 14:59:10 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-07-29 14:59:10 +0200 |
commit | b41bca63173d3c27fe3ba51612df20da9a795aea (patch) | |
tree | 3eae662d7cade699f0dabe474199913d957230d2 /src/util/configuration.c | |
parent | cadca90cafc76aaf55ea8d8e165d7c94aa3e9fef (diff) | |
download | gnunet-b41bca63173d3c27fe3ba51612df20da9a795aea.tar.gz gnunet-b41bca63173d3c27fe3ba51612df20da9a795aea.zip |
fall back to /etc for default configuration entry point
Diffstat (limited to 'src/util/configuration.c')
-rw-r--r-- | src/util/configuration.c | 67 |
1 files changed, 65 insertions, 2 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c index 875a811b3..776cfc7ea 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c | |||
@@ -1155,7 +1155,7 @@ GNUNET_CONFIGURATION_serialize_diagnostics (const struct | |||
1155 | GNUNET_buffer_write_fstr (&buf, | 1155 | GNUNET_buffer_write_fstr (&buf, |
1156 | "# Entry point: %s\n", | 1156 | "# Entry point: %s\n", |
1157 | cfg->main_filename ? cfg->main_filename : | 1157 | cfg->main_filename ? cfg->main_filename : |
1158 | "<input>"); | 1158 | "<none>"); |
1159 | GNUNET_buffer_write_fstr (&buf, | 1159 | GNUNET_buffer_write_fstr (&buf, |
1160 | "#\n# Files Loaded:\n"); | 1160 | "#\n# Files Loaded:\n"); |
1161 | 1161 | ||
@@ -2253,6 +2253,58 @@ GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2253 | return fun_ret; | 2253 | return fun_ret; |
2254 | } | 2254 | } |
2255 | 2255 | ||
2256 | char * | ||
2257 | GNUNET_CONFIGURATION_default_filename (void) | ||
2258 | { | ||
2259 | char *cfg_fn; | ||
2260 | const struct GNUNET_OS_ProjectData *pd = GNUNET_OS_project_data_get (); | ||
2261 | const char *xdg = getenv ("XDG_CONFIG_HOME"); | ||
2262 | |||
2263 | if (NULL != xdg) | ||
2264 | GNUNET_asprintf (&cfg_fn, | ||
2265 | "%s%s%s", | ||
2266 | xdg, | ||
2267 | DIR_SEPARATOR_STR, | ||
2268 | pd->config_file); | ||
2269 | else | ||
2270 | cfg_fn = GNUNET_strdup (pd->user_config_file); | ||
2271 | |||
2272 | if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn)) | ||
2273 | return cfg_fn; | ||
2274 | |||
2275 | GNUNET_free (cfg_fn); | ||
2276 | |||
2277 | /* Fall back to /etc/ for the default configuration. | ||
2278 | Should be okay to use forward slashes here. */ | ||
2279 | |||
2280 | GNUNET_asprintf (&cfg_fn, | ||
2281 | "/etc/%s", | ||
2282 | pd->config_file); | ||
2283 | |||
2284 | if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn)) | ||
2285 | return cfg_fn; | ||
2286 | |||
2287 | GNUNET_free (cfg_fn); | ||
2288 | |||
2289 | GNUNET_asprintf (&cfg_fn, | ||
2290 | "/etc/%s", | ||
2291 | pd->config_file); | ||
2292 | |||
2293 | if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn)) | ||
2294 | return cfg_fn; | ||
2295 | |||
2296 | GNUNET_asprintf (&cfg_fn, | ||
2297 | "/etc/%s/%s", | ||
2298 | pd->project_dirname, | ||
2299 | pd->config_file); | ||
2300 | |||
2301 | if (GNUNET_OK == GNUNET_DISK_file_test_read (cfg_fn)) | ||
2302 | return cfg_fn; | ||
2303 | |||
2304 | GNUNET_free (cfg_fn); | ||
2305 | return NULL; | ||
2306 | } | ||
2307 | |||
2256 | 2308 | ||
2257 | struct GNUNET_CONFIGURATION_Handle * | 2309 | struct GNUNET_CONFIGURATION_Handle * |
2258 | GNUNET_CONFIGURATION_default (void) | 2310 | GNUNET_CONFIGURATION_default (void) |
@@ -2284,7 +2336,9 @@ GNUNET_CONFIGURATION_default (void) | |||
2284 | if (GNUNET_OK != GNUNET_DISK_file_test (cfgname)) | 2336 | if (GNUNET_OK != GNUNET_DISK_file_test (cfgname)) |
2285 | { | 2337 | { |
2286 | GNUNET_free (cfgname); | 2338 | GNUNET_free (cfgname); |
2287 | GNUNET_asprintf (&cfgname, "/etc/%s/%s", pd->project_dirname, | 2339 | GNUNET_asprintf (&cfgname, |
2340 | "/etc/%s/%s", | ||
2341 | pd->project_dirname, | ||
2288 | pd->config_file); | 2342 | pd->config_file); |
2289 | } | 2343 | } |
2290 | if (GNUNET_OK != GNUNET_DISK_file_test (cfgname)) | 2344 | if (GNUNET_OK != GNUNET_DISK_file_test (cfgname)) |
@@ -2353,7 +2407,10 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2353 | 2407 | ||
2354 | ipath = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); | 2408 | ipath = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); |
2355 | if (NULL == ipath) | 2409 | if (NULL == ipath) |
2410 | { | ||
2411 | GNUNET_break (0); | ||
2356 | return GNUNET_SYSERR; | 2412 | return GNUNET_SYSERR; |
2413 | } | ||
2357 | GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d"); | 2414 | GNUNET_asprintf (&baseconfig, "%s%s", ipath, "config.d"); |
2358 | GNUNET_free (ipath); | 2415 | GNUNET_free (ipath); |
2359 | } | 2416 | } |
@@ -2364,6 +2421,9 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2364 | if ((GNUNET_YES == GNUNET_DISK_directory_test (dname, GNUNET_YES))&& | 2421 | if ((GNUNET_YES == GNUNET_DISK_directory_test (dname, GNUNET_YES))&& |
2365 | (GNUNET_SYSERR == GNUNET_CONFIGURATION_load_from (cfg, dname))) | 2422 | (GNUNET_SYSERR == GNUNET_CONFIGURATION_load_from (cfg, dname))) |
2366 | { | 2423 | { |
2424 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
2425 | "Failed to load base configuration from '%s'\n", | ||
2426 | filename); | ||
2367 | GNUNET_free (dname); | 2427 | GNUNET_free (dname); |
2368 | return GNUNET_SYSERR; /* no configuration at all found */ | 2428 | return GNUNET_SYSERR; /* no configuration at all found */ |
2369 | } | 2429 | } |
@@ -2372,6 +2432,9 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2372 | (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename))) | 2432 | (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, filename))) |
2373 | { | 2433 | { |
2374 | /* specified configuration not found */ | 2434 | /* specified configuration not found */ |
2435 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
2436 | "Failed to load configuration from file '%s'\n", | ||
2437 | filename); | ||
2375 | return GNUNET_SYSERR; | 2438 | return GNUNET_SYSERR; |
2376 | } | 2439 | } |
2377 | if (((GNUNET_YES != | 2440 | if (((GNUNET_YES != |