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 | |
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')
-rw-r--r-- | src/util/configuration.c | 67 | ||||
-rw-r--r-- | src/util/gnunet-config.c | 1 | ||||
-rw-r--r-- | src/util/program.c | 31 |
3 files changed, 79 insertions, 20 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 != |
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c index 20fd44c65..4f16332db 100644 --- a/src/util/gnunet-config.c +++ b/src/util/gnunet-config.c | |||
@@ -173,7 +173,6 @@ run (void *cls, | |||
173 | { | 173 | { |
174 | struct GNUNET_CONFIGURATION_Handle *ncfg; | 174 | struct GNUNET_CONFIGURATION_Handle *ncfg; |
175 | /* Re-parse the configuration with diagnostics enabled. */ | 175 | /* Re-parse the configuration with diagnostics enabled. */ |
176 | GNUNET_assert (NULL != cfgfile); | ||
177 | ncfg = GNUNET_CONFIGURATION_create (); | 176 | ncfg = GNUNET_CONFIGURATION_create (); |
178 | GNUNET_CONFIGURATION_enable_diagnostics (ncfg); | 177 | GNUNET_CONFIGURATION_enable_diagnostics (ncfg); |
179 | GNUNET_CONFIGURATION_load (ncfg, cfgfile); | 178 | GNUNET_CONFIGURATION_load (ncfg, cfgfile); |
diff --git a/src/util/program.c b/src/util/program.c index e34b37370..a79e07d19 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,6 +241,9 @@ GNUNET_PROGRAM_run2 (int argc, | |||
251 | } | 241 | } |
252 | if (NULL != cc.cfgfile) | 242 | if (NULL != cc.cfgfile) |
253 | { | 243 | { |
244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
245 | "Loading configuration from entry point specified as option (%s)\n", | ||
246 | cc.cfgfile); | ||
254 | if ((GNUNET_YES != GNUNET_DISK_file_test (cc.cfgfile)) || | 247 | if ((GNUNET_YES != GNUNET_DISK_file_test (cc.cfgfile)) || |
255 | (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cc.cfgfile))) | 248 | (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cc.cfgfile))) |
256 | { | 249 | { |
@@ -266,6 +259,9 @@ GNUNET_PROGRAM_run2 (int argc, | |||
266 | } | 259 | } |
267 | else | 260 | else |
268 | { | 261 | { |
262 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
263 | "Loading configuration default entry point (%s)\n", | ||
264 | cc.cfgfile); | ||
269 | if ((NULL != cfg_fn) && (GNUNET_YES == GNUNET_DISK_file_test (cfg_fn))) | 265 | if ((NULL != cfg_fn) && (GNUNET_YES == GNUNET_DISK_file_test (cfg_fn))) |
270 | { | 266 | { |
271 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_fn)) | 267 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, cfg_fn)) |
@@ -283,8 +279,9 @@ GNUNET_PROGRAM_run2 (int argc, | |||
283 | } | 279 | } |
284 | else if (NULL != cfg_fn) | 280 | else if (NULL != cfg_fn) |
285 | { | 281 | { |
282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
283 | "Loading configuration without entry point\n"); | ||
286 | GNUNET_free (cfg_fn); | 284 | GNUNET_free (cfg_fn); |
287 | cfg_fn = NULL; | ||
288 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, NULL)) | 285 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, NULL)) |
289 | { | 286 | { |
290 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 287 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -349,7 +346,7 @@ GNUNET_PROGRAM_run2 (int argc, | |||
349 | cc.task (cc.task_cls, cc.args, cc.cfgfile, cc.cfg); | 346 | cc.task (cc.task_cls, cc.args, cc.cfgfile, cc.cfg); |
350 | } | 347 | } |
351 | ret = GNUNET_OK; | 348 | ret = GNUNET_OK; |
352 | cleanup: | 349 | cleanup: |
353 | GNUNET_CONFIGURATION_destroy (cfg); | 350 | GNUNET_CONFIGURATION_destroy (cfg); |
354 | GNUNET_free (cc.cfgfile); | 351 | GNUNET_free (cc.cfgfile); |
355 | GNUNET_free (cfg_fn); | 352 | GNUNET_free (cfg_fn); |