From be2adced3edc62e74884ea7cc2f262a85193fc83 Mon Sep 17 00:00:00 2001 From: Jeon Sang-Heon Date: Fri, 3 Jul 2020 17:02:30 +0000 Subject: [PATCH] Save fota result to fota status checker - To reuse fota upgrade result, save result to fota status checker Change-Id: I54b856159d52e5b770973ec10ed146012617bd26 Signed-off-by: Jeon Sang-Heon --- update-manager/fota-status-checker.c | 66 ++++++++++++++++++++++------ update-manager/main.c | 4 ++ update-manager/update-manager.h | 2 + 3 files changed, 59 insertions(+), 13 deletions(-) diff --git a/update-manager/fota-status-checker.c b/update-manager/fota-status-checker.c index 8536739..7091ba5 100644 --- a/update-manager/fota-status-checker.c +++ b/update-manager/fota-status-checker.c @@ -1,25 +1,23 @@ #include "update-manager.h" -int fota_status_checker_init() +static char *fota_result = NULL; + +char *fota_status_get_result() +{ + return fota_result; +} + +int fota_status_checker_process() { int ret = 0; - char buf[MAX_BUFFER_SIZE] = {0,}; - bool exist = false; - exist = g_file_test(STATUS_FLAG_PATH, G_FILE_TEST_EXISTS) && g_file_test(STATUS_RESULT_PATH, G_FILE_TEST_EXISTS); - if (exist) { + if (g_file_test(STATUS_FLAG_PATH, G_FILE_TEST_EXISTS)) { _I("This boot is triggered with fota, start process to send result to client"); - ret = util_file_read_line(STATUS_RESULT_PATH, buf); - if (ret < 0) { - _E("Failed to read fota result : %d", ret); - return -1; - } - - ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_REBOOT_KEY, buf); + ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_REBOOT_KEY, fota_result); if (ret < 0) { _E("Failed to add launch request : %d, key : %s, value : %s", - ret, CLIENT_APP_CTRL_REBOOT_KEY, buf); + ret, CLIENT_APP_CTRL_REBOOT_KEY, fota_result); return -1; } @@ -36,3 +34,45 @@ int fota_status_checker_init() return 0; } + +int fota_status_checker_init() +{ + int ret = 0; + char buf[MAX_BUFFER_SIZE] = {0, }; + + if (g_file_test(STATUS_RESULT_PATH, G_FILE_TEST_EXISTS)) { + _I("This boot have fota status, start process to get fota result"); + + ret = util_file_read_line(STATUS_RESULT_PATH, buf); + if (ret < 0) { + _E("Failed to read fota result : %d", ret); + return -1; + } + + fota_result = strndup(buf, strlen(buf)); + if (fota_result == NULL) { + _E("Failed to strndup value (%s) : %m", buf); + return -1; + } + + _I("Success to read fota result : %s", fota_result); + + ret = fota_status_checker_process(); + if (ret < 0) { + _E("Failed to process fota reboot result : %d", ret); + return -1; + } + } else { + _I("This boot doesn't have fota result"); + } + + return 0; +} + +int fota_status_checker_fini() +{ + if (fota_result) + free(fota_result); + + return 0; +} \ No newline at end of file diff --git a/update-manager/main.c b/update-manager/main.c index 61b0ee0..0d0fafd 100644 --- a/update-manager/main.c +++ b/update-manager/main.c @@ -70,6 +70,10 @@ main_destroy: if (ret < 0) _W("Failed to finalize fota storage checker : %d", ret); + ret = fota_status_checker_fini(); + if (ret < 0) + _E("Failed to finalize fota status checker : %d", ret); + ret = fota_controller_fini(); if (ret < 0) _W("Failed to finalize fota controller : %d", ret); diff --git a/update-manager/update-manager.h b/update-manager/update-manager.h index c0ac2a2..d99b6ac 100644 --- a/update-manager/update-manager.h +++ b/update-manager/update-manager.h @@ -93,6 +93,8 @@ int fota_storage_checker_init(void); int fota_storage_checker_fini(void); int fota_status_checker_init(void); +int fota_status_checker_fini(void); +char *fota_status_get_result(void); int fota_controller_init(void); int fota_controller_fini(void); -- 2.34.1