From ee10b40c55c154400bbefd13175bd8b280cb7798 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 11 Dec 2018 10:21:39 +0100 Subject: [PATCH] fail hard if configuration file specified via -c does not exist (in all services and programs) --- src/util/configuration.c | 8 +++++--- src/util/gnunet-config.c | 23 ++++++++++++++--------- src/util/program.c | 9 ++------- src/util/service.c | 7 +++++-- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/util/configuration.c b/src/util/configuration.c index 197c664db..d61b9c27e 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -945,7 +945,7 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle number, dummy)) return GNUNET_SYSERR; - return GNUNET_OK; + return GNUNET_OK; } @@ -966,7 +966,7 @@ GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle { struct ConfigEntry *e; char dummy[2]; - + if (NULL == (e = find_entry (cfg, section, option))) return GNUNET_SYSERR; if (NULL == e->val) @@ -1748,7 +1748,9 @@ GNUNET_CONFIGURATION_load_from (struct GNUNET_CONFIGURATION_Handle *cfg, const char *defaults_d) { if (GNUNET_SYSERR == - GNUNET_DISK_directory_scan (defaults_d, &parse_configuration_file, cfg)) + GNUNET_DISK_directory_scan (defaults_d, + &parse_configuration_file, + cfg)) return GNUNET_SYSERR; /* no configuration at all found */ return GNUNET_OK; } diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c index 4528bbe24..46c523da4 100644 --- a/src/util/gnunet-config.c +++ b/src/util/gnunet-config.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ @@ -82,7 +82,7 @@ print_option (void *cls, { char *value_fn; char *fn; - + GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, section, @@ -167,14 +167,19 @@ run (void *cls, if (! list_sections) { fprintf (stderr, - _("--section argument is required\n")); + _("%s or %s argument is required\n"), + "--section", + "--list-sections"); + ret = 1; + } + else + { + fprintf (stderr, + _("The following sections are available:\n")); + GNUNET_CONFIGURATION_iterate_sections (cfg, + &print_section_name, + NULL); } - fprintf (stderr, - _("The following sections are available:\n")); - GNUNET_CONFIGURATION_iterate_sections (cfg, - &print_section_name, - NULL); - ret = 1; goto cleanup; } diff --git a/src/util/program.c b/src/util/program.c index 2a9b4fac9..da58348d0 100644 --- a/src/util/program.c +++ b/src/util/program.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPROSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ @@ -286,15 +286,10 @@ GNUNET_PROGRAM_run2 (int argc, { if (0 != strcmp (cc.cfgfile, cfg_fn)) + { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not access configuration file `%s'\n"), cc.cfgfile); - if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_load (cfg, - NULL)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Malformed configuration, exit ...\n")); ret = GNUNET_SYSERR; GNUNET_free (allopts); GNUNET_free (lpfx); diff --git a/src/util/service.c b/src/util/service.c index b61168570..2dc7dd576 100644 --- a/src/util/service.c +++ b/src/util/service.c @@ -11,7 +11,7 @@ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. - + You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ @@ -1177,7 +1177,7 @@ setup_service (struct GNUNET_SERVICE_Handle *sh) int flags; char dummy[2]; #endif - + if (GNUNET_CONFIGURATION_have_value (sh->cfg, sh->service_name, @@ -1837,9 +1837,12 @@ GNUNET_SERVICE_run_ (int argc, } if (0 != strcmp (opt_cfg_filename, cfg_filename)) + { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not access configuration file `%s'\n"), opt_cfg_filename); + goto shutdown; + } } if (GNUNET_OK != setup_service (&sh)) goto shutdown; -- 2.25.1