Skip to content

Commit

Permalink
sch: validate time strings on reload and on boot
Browse files Browse the repository at this point in the history
ref. #2626
  • Loading branch information
mcspr committed Nov 29, 2024
1 parent f409248 commit c034766
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion code/espurna/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ Copyright (C) 2019-2024 by Maxim Prokhorov <prokhorov dot max at outlook dot com

namespace espurna {
namespace scheduler {
namespace error {

STRING_VIEW_INLINE(InvalidTime, "Invalid time string");

} // namespace error

enum class Type : int {
Unknown = 0,
Expand Down Expand Up @@ -523,6 +528,21 @@ void setup() {
});
}

void validate() {
#if DEBUG_SUPPORT
for (size_t index = 0; index < build::max(); ++index) {
const auto result = schedule(index);
if (!result.ok) {
DEBUG_MSG_P(PSTR("[SCH] ERROR: #%zu -> %.*s\n"),
index,
error::InvalidTime.length(),
error::InvalidTime.data());
break;
}
}
#endif
}

} // namespace settings

namespace v1 {
Expand Down Expand Up @@ -1060,7 +1080,7 @@ void entrypoint(::terminal::CommandContext&& ctx) {
if (result.ok) {
terminalOK(ctx);
} else {
terminalError(ctx, STRING_VIEW("Invalid schedule string"));
terminalError(ctx, error::InvalidTime);
}

return;
Expand Down Expand Up @@ -2159,6 +2179,7 @@ void tick(NtpTick tick) {
#if SCHEDULER_SUN_SUPPORT
sun::update_before(ctx);
#endif
settings::validate();
}

#if SCHEDULER_SUN_SUPPORT
Expand Down Expand Up @@ -2188,6 +2209,8 @@ void setup() {
migrateVersion(scheduler::settings::migrate);
settings::setup();

espurnaRegisterReload(settings::validate);

#if SCHEDULER_SUN_SUPPORT
sun::setup();
#endif
Expand Down

0 comments on commit c034766

Please sign in to comment.