subsys/mgmt/hawkbit: Prevent multiple instances of hawkbit_probe
Use a semaphore to prevent the hawkbit_probe from running more than once at the same time since it reset the hawkbit context on entry and will affect other running instance. Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
This commit is contained in:
parent
17dd9f4928
commit
eaa29d9d71
|
@ -32,6 +32,7 @@ enum hawkbit_response {
|
|||
HAWKBIT_UPDATE_INSTALLED,
|
||||
HAWKBIT_NO_UPDATE,
|
||||
HAWKBIT_CANCEL_UPDATE,
|
||||
HAWKBIT_PROBE_IN_PROGRESS,
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,6 +71,10 @@ void main(void)
|
|||
LOG_INF("Update installed");
|
||||
break;
|
||||
|
||||
case HAWKBIT_PROBE_IN_PROGRESS:
|
||||
LOG_INF("Hawkbit is already running");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -94,6 +94,8 @@ static union {
|
|||
|
||||
static struct k_work_delayable hawkbit_work_handle;
|
||||
|
||||
static struct k_sem probe_sem;
|
||||
|
||||
static const struct json_obj_descr json_href_descr[] = {
|
||||
JSON_OBJ_DESCR_PRIM(struct hawkbit_href, href, JSON_TOK_STRING),
|
||||
};
|
||||
|
@ -640,6 +642,8 @@ int hawkbit_init(void)
|
|||
}
|
||||
}
|
||||
|
||||
k_sem_init(&probe_sem, 1, 1);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -1022,6 +1026,10 @@ enum hawkbit_response hawkbit_probe(void)
|
|||
deployment_base[DEPLOYMENT_BASE_SIZE] = { 0 },
|
||||
firmware_version[BOOT_IMG_VER_STRLEN_MAX] = { 0 };
|
||||
|
||||
if (k_sem_take(&probe_sem, K_NO_WAIT) != 0) {
|
||||
return HAWKBIT_PROBE_IN_PROGRESS;
|
||||
}
|
||||
|
||||
memset(&hb_context, 0, sizeof(hb_context));
|
||||
hb_context.response_data = malloc(RESPONSE_BUFFER_SIZE);
|
||||
|
||||
|
@ -1228,6 +1236,7 @@ cleanup:
|
|||
|
||||
error:
|
||||
free(hb_context.response_data);
|
||||
k_sem_give(&probe_sem);
|
||||
return hb_context.code_status;
|
||||
}
|
||||
|
||||
|
@ -1267,6 +1276,10 @@ static void autohandler(struct k_work *work)
|
|||
case HAWKBIT_METADATA_ERROR:
|
||||
LOG_INF("Metadata error");
|
||||
break;
|
||||
|
||||
case HAWKBIT_PROBE_IN_PROGRESS:
|
||||
LOG_INF("Hawkbit is already running");
|
||||
break;
|
||||
}
|
||||
|
||||
k_work_reschedule(&hawkbit_work_handle, K_MSEC(poll_sleep));
|
||||
|
|
Loading…
Reference in a new issue