Skip to content

Commit

Permalink
Merge pull request #115 from danielskinstad/abort-deployment
Browse files Browse the repository at this point in the history
fix: fail deployment when it's aborted
  • Loading branch information
danielskinstad authored Nov 29, 2024
2 parents b4dfb98 + 69445a0 commit fd65e00
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 23 deletions.
4 changes: 4 additions & 0 deletions core/src/mender-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,10 @@ mender_api_publish_deployment_status(const char *id, mender_deployment_status_t
if (204 == status) {
/* No response expected */
ret = MENDER_OK;
} else if (409 == status) {
/* Deployment aborted */
mender_api_print_response_error(response, status);
ret = MENDER_ABORTED;
} else {
mender_api_print_response_error(response, status);
ret = MENDER_FAIL;
Expand Down
17 changes: 10 additions & 7 deletions core/src/mender-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,12 +924,13 @@ mender_client_update_work_function(void) {
mender_log_info("Downloading artifact with id '%s', name '%s', uri '%s'", deployment->id, deployment->artifact_name, deployment->uri);
}
#endif
mender_client_publish_deployment_status(deployment->id, MENDER_DEPLOYMENT_STATUS_DOWNLOADING);

/* Set deployment_id */
deployment_id = deployment->id;

if (MENDER_OK == (ret = mender_download_artifact(deployment->uri, mender_client_deployment_data, &mender_update_module))) {
/* Check ret to see if the deployment is aborted */
ret = mender_client_publish_deployment_status(deployment->id, MENDER_DEPLOYMENT_STATUS_DOWNLOADING);
if ((MENDER_ABORTED != ret)
&& (MENDER_OK == (ret = mender_download_artifact(deployment->uri, mender_client_deployment_data, &mender_update_module)))) {
assert(NULL != mender_update_module);

/* Get artifact context if artifact download succeeded */
Expand Down Expand Up @@ -971,8 +972,9 @@ mender_client_update_work_function(void) {

case MENDER_UPDATE_STATE_INSTALL:
mender_log_info("Download done, installing artifact");
mender_client_publish_deployment_status(deployment_id, MENDER_DEPLOYMENT_STATUS_INSTALLING);
if (NULL != mender_update_module->callbacks[update_state]) {
/* Check ret to see if the deployment is aborted */
ret = mender_client_publish_deployment_status(deployment_id, MENDER_DEPLOYMENT_STATUS_INSTALLING);
if ((MENDER_ABORTED != ret) && (NULL != mender_update_module->callbacks[update_state])) {
ret = mender_update_module->callbacks[update_state](update_state, (mender_update_state_data_t)NULL);
}
if ((MENDER_OK == ret) && !mender_update_module->requires_reboot) {
Expand All @@ -988,8 +990,9 @@ mender_client_update_work_function(void) {
case MENDER_UPDATE_STATE_REBOOT:
assert(mender_update_module->requires_reboot);
mender_log_info("Artifact installation done, rebooting");
mender_client_publish_deployment_status(deployment_id, MENDER_DEPLOYMENT_STATUS_REBOOTING);
if ((MENDER_OK == ret) && (NULL != mender_update_module->callbacks[update_state])) {
/* Check ret to see if the deployment is aborted */
ret = mender_client_publish_deployment_status(deployment_id, MENDER_DEPLOYMENT_STATUS_REBOOTING);
if ((MENDER_ABORTED != ret) && (NULL != mender_update_module->callbacks[update_state])) {
/* Save the next state before running the reboot callback --
* if there is an interrupt (power, crash,...) right after,
* it will reboot anyway so after the new boot, reboot
Expand Down
4 changes: 2 additions & 2 deletions core/src/mender-zephyr-image-update-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ mender_zephyr_image_set_pending_image(MENDER_NDEBUG_UNUSED mender_update_state_t
return MENDER_FAIL;
}

if (MENDER_OK != (ret = mender_flash_set_pending_image(mcu_boot_flash_handle))) {
if (MENDER_OK != (ret = mender_flash_set_pending_image(&mcu_boot_flash_handle))) {
mender_log_error("Unable to set boot partition");
return ret;
}
Expand All @@ -153,7 +153,7 @@ mender_zephyr_image_abort_deployment(MENDER_NDEBUG_UNUSED mender_update_state_t
assert(MENDER_UPDATE_STATE_FAILURE == state);
mender_err_t ret;

if (MENDER_OK != (ret = mender_flash_abort_deployment(mcu_boot_flash_handle))) {
if (MENDER_OK != (ret = mender_flash_abort_deployment(&mcu_boot_flash_handle))) {
mender_log_error("Unable to abort deployment");
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions include/mender-flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ mender_err_t mender_flash_close(void *handle);
* @param handle Handle from mender_flash_open
* @return MENDER_OK if the function succeeds, error code otherwise
*/
mender_err_t mender_flash_set_pending_image(void *handle);
mender_err_t mender_flash_set_pending_image(void **handle);

/**
* @brief Abort current deployment
* @param handle Handle from mender_flash_open
* @return MENDER_OK if the function succeeds, error code otherwise
*/
mender_err_t mender_flash_abort_deployment(void *handle);
mender_err_t mender_flash_abort_deployment(void **handle);

/**
* @brief Mark image valid and cancel rollback if this is still pending
Expand Down
1 change: 1 addition & 0 deletions include/mender-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ typedef enum {
MENDER_NOT_IMPLEMENTED = -3, /**< Not implemented */
MENDER_LOOP_DETECTED = -4, /**< Loop detected */
MENDER_LOCK_FAILED = -5, /**< Locking failed */
MENDER_ABORTED = -6, /**< Aborted */
} mender_err_t;

#define MENDER_IS_ERROR(err_t_ret) ((err_t_ret) < 0)
Expand Down
4 changes: 2 additions & 2 deletions platform/flash/generic/weak/src/mender-flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mender_flash_close(void *handle) {
}

__attribute__((weak)) mender_err_t
mender_flash_set_pending_image(void *handle) {
mender_flash_set_pending_image(void **handle) {

(void)handle;

Expand All @@ -62,7 +62,7 @@ mender_flash_set_pending_image(void *handle) {
}

__attribute__((weak)) mender_err_t
mender_flash_abort_deployment(void *handle) {
mender_flash_abort_deployment(void **handle) {

(void)handle;

Expand Down
10 changes: 5 additions & 5 deletions platform/flash/posix/src/mender-flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ mender_flash_close(void *handle) {
}

mender_err_t
mender_flash_set_pending_image(void *handle) {
mender_flash_set_pending_image(void **handle) {

FILE *file;
mender_err_t ret = MENDER_OK;

/* Check flash handle */
if (NULL != handle) {
if (NULL != *handle) {

/* Write request update file */
if (NULL == (file = fopen(MENDER_FLASH_REQUEST_UPGRADE, "wb"))) {
Expand All @@ -122,13 +122,13 @@ mender_flash_set_pending_image(void *handle) {
}

mender_err_t
mender_flash_abort_deployment(void *handle) {
mender_flash_abort_deployment(void **handle) {

/* Check flash handle */
if (NULL != handle) {
if (NULL != *handle) {

/* Release memory */
fclose(handle);
fclose(*handle);
}

return MENDER_OK;
Expand Down
10 changes: 5 additions & 5 deletions platform/flash/zephyr/src/mender-flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ mender_flash_close(void *handle) {
}

mender_err_t
mender_flash_set_pending_image(void *handle) {
mender_flash_set_pending_image(void **handle) {

int result;

/* Check flash handle */
if (NULL != handle) {
if (NULL != *handle) {

/* Set new boot partition */
if (0 != (result = boot_request_upgrade(BOOT_UPGRADE_TEST))) {
Expand All @@ -104,7 +104,7 @@ mender_flash_set_pending_image(void *handle) {
}

/* Release memory */
free(handle);
FREE_AND_NULL(*handle);
} else {

/* This should not happen! */
Expand All @@ -116,10 +116,10 @@ mender_flash_set_pending_image(void *handle) {
}

mender_err_t
mender_flash_abort_deployment(void *handle) {
mender_flash_abort_deployment(void **handle) {

/* Release memory */
free(handle);
FREE_AND_NULL(*handle);

return MENDER_OK;
}
Expand Down
3 changes: 3 additions & 0 deletions platform/tls/generic/mbedtls/src/mender-tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ mender_tls_init_authentication_keys(mender_err_t (*get_user_provided_keys)(char
case MENDER_LOCK_FAILED:
assert(false && "Unexpected return value");
/* fallthrough */
case MENDER_ABORTED:
assert(false && "Unexpected return value");
/* fallthrough */
case MENDER_FAIL:
mender_log_error("Unable to get authentication keys from store");
return MENDER_FAIL;
Expand Down

0 comments on commit fd65e00

Please sign in to comment.