Skip to content

Commit

Permalink
addon: configure: fix management of artifact name
Browse files Browse the repository at this point in the history
  • Loading branch information
joelguittet committed Jun 20, 2024
1 parent 55c3edd commit 1b1753e
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions add-ons/src/mender-configure.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ static mender_configure_callbacks_t mender_configure_callbacks;
static mender_keystore_t *mender_configure_keystore = NULL;
static void * mender_configure_mutex = NULL;

/**
* @brief Mender configure artifact name
*/
static char *mender_configure_artifact_name = NULL;

/**
* @brief Mender configure work handle
*/
Expand Down Expand Up @@ -96,6 +101,7 @@ mender_configure_init(void *config, void *callbacks) {
assert(NULL != config);
char * device_config = NULL;
cJSON * json_device_config = NULL;
char * artifact_name;
mender_err_t ret;

/* Save configuration */
Expand Down Expand Up @@ -126,25 +132,36 @@ mender_configure_init(void *config, void *callbacks) {
}
}

/* Set device configuration */
/* Check if configuration is available */
if (NULL != device_config) {

/* Parse configuration */
if (NULL == (json_device_config = cJSON_Parse(device_config))) {
mender_log_error("Unable to set device configuration");
ret = MENDER_FAIL;
goto END;
}

/* Set device configuration */
if (MENDER_OK != (ret = mender_utils_keystore_from_json(&mender_configure_keystore, cJSON_GetObjectItemCaseSensitive(json_device_config, "config")))) {
mender_log_error("Unable to set device configuration");
goto END;
}

/* Retrieve artifact name if it is available */
if (NULL != (artifact_name = cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(json_device_config, "artifact_name")))) {
if (NULL == (mender_configure_artifact_name = strdup(artifact_name))) {
mender_log_error("Unable to allocate memory");
ret = MENDER_FAIL;
goto END;
}
}
}

/* Register mender-configure artifact type */
if (MENDER_OK
!= (ret = mender_client_register_artifact_type("mender-configure",
&mender_configure_download_artifact_callback,
true,
cJSON_GetStringValue(cJSON_GetObjectItemCaseSensitive(json_device_config, "artifact_name"))))) {
!= (ret
= mender_client_register_artifact_type("mender-configure", &mender_configure_download_artifact_callback, true, mender_configure_artifact_name))) {
mender_log_error("Unable to register 'mender-configure' artifact type");
goto END;
}
Expand Down Expand Up @@ -331,6 +348,10 @@ mender_configure_exit(void) {
mender_scheduler_mutex_give(mender_configure_mutex);
mender_scheduler_mutex_delete(mender_configure_mutex);
mender_configure_mutex = NULL;
if (NULL != mender_configure_artifact_name) {
free(mender_configure_artifact_name);
mender_configure_artifact_name = NULL;
}

return ret;
}
Expand Down

0 comments on commit 1b1753e

Please sign in to comment.