Skip to content

Commit fd15453

Browse files
committed
main: Increase pre-reboot robustness
Abort immediately if pre-reboot task cannot be created for any reason.
1 parent 7884ede commit fd15453

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

software/src/main.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ static void pre_reboot_task(void *arg)
153153
esp_system_abort(pre_reboot_message);
154154
}
155155

156+
static void task_creation_failed(int error_code)
157+
{
158+
char msg[48];
159+
msg[0] = 0;
160+
snprintf(msg, ARRAY_SIZE(msg), "Failed to create pre-reboot task: %i", error_code);
161+
esp_system_abort(msg);
162+
}
163+
156164
#endif
157165

158166
static void pre_reboot_helper(void)
@@ -175,14 +183,23 @@ static void pre_reboot(void)
175183
#if MODULE_WATCHDOG_AVAILABLE()
176184
watchdog.add("pre_reboot", pre_reboot_message, PRE_REBOOT_MAX_DURATION, 0, true);
177185
#else
178-
xTaskCreatePinnedToCore(
186+
auto err = xTaskCreatePinnedToCore(
179187
pre_reboot_task,
180188
"pre_reboot_task",
181189
640,
182190
nullptr,
183191
ESP_TASK_PRIO_MAX,
184192
nullptr,
185193
1);
194+
195+
#pragma GCC diagnostic push
196+
#pragma GCC diagnostic ignored "-Wold-style-cast"
197+
#pragma GCC diagnostic ignored "-Wuseless-cast"
198+
// pdPASS expands to an old-style cast that is also useless
199+
if (err != pdPASS) {
200+
task_creation_failed(err);
201+
}
202+
#pragma GCC diagnostic pop
186203
#endif
187204

188205
pre_reboot_helper();

0 commit comments

Comments
 (0)