system_api: return error on repeated registration of shutdown handler

This commit is contained in:
Ivan Grokhotkov
2019-04-08 19:30:07 +08:00
parent bd309a133f
commit b1a722b2ca
2 changed files with 14 additions and 8 deletions

View File

@@ -211,14 +211,15 @@ esp_err_t esp_read_mac(uint8_t* mac, esp_mac_type_t type)
esp_err_t esp_register_shutdown_handler(shutdown_handler_t handler)
{
int i;
for (i = 0; i < SHUTDOWN_HANDLERS_NO; i++) {
if (shutdown_handlers[i] == NULL) {
shutdown_handlers[i] = handler;
return ESP_OK;
}
}
return ESP_FAIL;
for (int i = 0; i < SHUTDOWN_HANDLERS_NO; i++) {
if (shutdown_handlers[i] == handler) {
return ESP_ERR_INVALID_STATE;
} else if (shutdown_handlers[i] == NULL) {
shutdown_handlers[i] = handler;
return ESP_OK;
}
}
return ESP_ERR_NO_MEM;
}
esp_err_t esp_unregister_shutdown_handler(shutdown_handler_t handler)