Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fail deployment when it's aborted #115

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/mender-api.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,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: 13 additions & 4 deletions core/src/mender-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,9 @@ 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);
if (MENDER_ABORTED == mender_client_publish_deployment_status(deployment->id, MENDER_DEPLOYMENT_STATUS_DOWNLOADING)) {
ret = MENDER_FAIL;
}

/* Set deployment_id */
deployment_id = deployment->id;
Expand Down Expand Up @@ -990,8 +992,10 @@ 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]) {
if (MENDER_ABORTED == mender_client_publish_deployment_status(deployment_id, MENDER_DEPLOYMENT_STATUS_INSTALLING)) {
ret = MENDER_FAIL;
}
if ((MENDER_OK == 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 @@ -1007,7 +1011,11 @@ 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_ABORTED == mender_client_publish_deployment_status(deployment_id, MENDER_DEPLOYMENT_STATUS_REBOOTING)) {
update_state = MENDER_UPDATE_STATE_FAILURE;
set_and_store_state(update_state);
continue;
}
danielskinstad marked this conversation as resolved.
Show resolved Hide resolved
if ((MENDER_OK == 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,
Expand Down Expand Up @@ -1052,6 +1060,7 @@ mender_client_update_work_function(void) {
ret = mender_update_module->callbacks[update_state](update_state, (mender_update_state_data_t)NULL);
}
if (MENDER_OK == ret) {
/* We don't check for MENDER_ABORTED, as it's too late if it has reached this far */
mender_client_publish_deployment_status(deployment_id, MENDER_DEPLOYMENT_STATUS_SUCCESS);
}
NEXT_STATE;
Expand Down
1 change: 1 addition & 0 deletions include/mender-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ typedef enum {
MENDER_NOT_FOUND = -2, /**< Not found */
MENDER_NOT_IMPLEMENTED = -3, /**< Not implemented */
MENDER_LOOP_DETECTED = -4, /**< Loop detected */
MENDER_ABORTED = -5, /**< Aborted */
} mender_err_t;

/**
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 @@ -195,6 +195,9 @@ mender_tls_init_authentication_keys(mender_err_t (*get_user_provided_keys)(char
case MENDER_LOOP_DETECTED:
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