From ca5131636430b906c42228cb6324af1ec9cf21cc Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Mon, 29 Apr 2019 13:20:03 +0300 Subject: [PATCH] MXS-2329 0 is a valid duration, with or without a suffix --- server/core/config.cc | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/server/core/config.cc b/server/core/config.cc index 736963e97..d39f83bb7 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -5115,7 +5115,28 @@ static bool duration_is_valid(const char* zValue, mxs::config::DurationUnit* pUn { // When the validity is checked, it does not matter how the value // should be interpreted, so any mxs::config::DurationInterpretation is fine. - return get_suffixed_duration(zValue, mxs::config::INTERPRET_AS_SECONDS, nullptr, pUnit); + std::chrono::milliseconds duration; + mxs::config::DurationUnit unit; + bool valid = get_suffixed_duration(zValue, mxs::config::INTERPRET_AS_SECONDS, &duration, &unit); + + if (valid) + { + if (unit == mxs::config::DURATION_IN_DEFAULT) + { + // "0" is a special case, as it means the same regardless of the + // unit and the presence of a unit. + if (duration.count() == 0) + { + // To prevent unnecessary complaints, we claim it was specified in + // seconds which is acceptable in all cases. + unit = mxs::config::DURATION_IN_SECONDS; + } + } + + *pUnit = unit; + } + + return valid; } static bool get_seconds(const char* zName, const char* zValue, std::chrono::seconds* pSeconds)