From 0850783a17fb39e744fed779b77ad46ac5a4ed54 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 15 Sep 2018 18:45:28 +0200 Subject: [PATCH] warn better if config option is invalid, allow second and seconds as time units --- src/include/gnunet_common.h | 2 +- src/util/configuration.c | 18 ++++++++++++++---- src/util/strings.c | 2 ++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 1b982cc15..1e9152bbf 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -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 . */ diff --git a/src/util/configuration.c b/src/util/configuration.c index 9a583dfdb..e00bbd64a 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.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 . */ @@ -233,7 +233,7 @@ GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_asprintf (&fn, "%s/%s", basedir, - value); + value); if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, fn)) @@ -953,12 +953,22 @@ GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *c struct GNUNET_TIME_Relative *time) { struct ConfigEntry *e; + int ret; - if (NULL == (e = find_entry (cfg, section, option))) + if (NULL == (e = find_entry (cfg, + section, + option))) return GNUNET_SYSERR; if (NULL == e->val) return GNUNET_SYSERR; - return GNUNET_STRINGS_fancy_time_to_relative (e->val, time); + ret = GNUNET_STRINGS_fancy_time_to_relative (e->val, + time); + if (GNUNET_OK != ret) + GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, + section, + option, + _("Not a valid relative time specification")); + return ret; } diff --git a/src/util/strings.c b/src/util/strings.c index ea3c8cfb9..e3bdadd39 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -331,6 +331,8 @@ GNUNET_STRINGS_fancy_time_to_relative (const char *fancy_time, { "us", 1}, { "ms", 1000 }, { "s", 1000 * 1000LL }, + { "second", 1000 * 1000LL }, + { "seconds", 1000 * 1000LL }, { "\"", 1000 * 1000LL }, { "m", 60 * 1000 * 1000LL}, { "min", 60 * 1000 * 1000LL}, -- 2.25.1