From: Jeon Sang-Heon Date: Thu, 11 Jun 2020 12:08:58 +0000 (+0900) Subject: Fix code to follow tizen coding rule X-Git-Tag: submit/tizen/20200706.142233~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5140358f4df9589e8aa80ff4c1f6755c51bee7f0;p=platform%2Fcore%2Fsystem%2Fupdate-control.git Fix code to follow tizen coding rule Change-Id: I6c95c4841f2727be5d796ce2e1f95074f1cd4350 Signed-off-by: Jeon Sang-Heon --- diff --git a/update-manager/client-controller.c b/update-manager/client-controller.c index ed24aac..0d5d064 100644 --- a/update-manager/client-controller.c +++ b/update-manager/client-controller.c @@ -1,122 +1,120 @@ #include "update-manager.h" typedef struct _request_data { - char *key; - char *value; + char *key; + char *value; } request_data; static request_data request_stack[MAX_STACK_SIZE]; static int top = -1; int client_controller_process_launch_request() { - int ret = 0, status = 0; - char *appid = NULL; - bundle *bundle_data = NULL; - - appid = client_info_get_appid(); - if (appid == NULL) { - _I("Failed to launch client, client app id not found, current top : %d", top); - goto request_destroy; - } - - if (!client_status_checker_is_success()) { - _I("Failed to launch client, user session is unset, current top : %d", top); - goto request_destroy; - } - - while (top > -1) { - _I("Success to ready process launch client, top : %d, key : %s, value : %s", - top, request_stack[top].key, request_stack[top].value); - - bundle_data = bundle_create(); - if (bundle_data == NULL) { - _E("bundle_create failed"); - status = -1; - goto request_destroy; - } - - ret = aul_svc_set_operation(bundle_data, AUL_SVC_OPERATION_DEFAULT); - if (ret != AUL_R_OK) { - _E("aul_svc_set_operation failed : %d", ret); - status = -1; - goto request_destroy; - } - - ret = aul_svc_add_data(bundle_data, request_stack[top].key, request_stack[top].value); - if (ret != AUL_R_OK) { - _E("aul_svc_add_data failed : %d", ret); - status = -1; - goto request_destroy; - } - - ret = aul_launch_app_for_uid(appid, bundle_data, OWNER_UID); - if (ret < AUL_R_OK) { - _E("aul_launch_app_for_uid failed : %d", ret); - status = -1; - goto request_destroy; - } - - _I("Success to launch client with, key : %s, value : %s", - request_stack[top].key, request_stack[top].value); - - ret = bundle_free(bundle_data); - if (ret != BUNDLE_ERROR_NONE) { - _W("bundle_free failed : %d", ret); - } - bundle_data = NULL; - - free(request_stack[top].key); - free(request_stack[top].value); - top--; - } + int ret = 0, status = 0; + char *appid = NULL; + bundle *bundle_data = NULL; + + appid = client_info_get_appid(); + if (appid == NULL) { + _I("Failed to launch client, client app id not found, current top : %d", top); + goto request_destroy; + } + + if (!client_status_checker_is_success()) { + _I("Failed to launch client, user session is unset, current top : %d", top); + goto request_destroy; + } + + while (top > -1) { + _I("Success to ready process launch client, top : %d, key : %s, value : %s", + top, request_stack[top].key, request_stack[top].value); + + bundle_data = bundle_create(); + if (bundle_data == NULL) { + _E("bundle_create failed"); + status = -1; + goto request_destroy; + } + + ret = aul_svc_set_operation(bundle_data, AUL_SVC_OPERATION_DEFAULT); + if (ret != AUL_R_OK) { + _E("aul_svc_set_operation failed : %d", ret); + status = -1; + goto request_destroy; + } + + ret = aul_svc_add_data(bundle_data, request_stack[top].key, request_stack[top].value); + if (ret != AUL_R_OK) { + _E("aul_svc_add_data failed : %d", ret); + status = -1; + goto request_destroy; + } + + ret = aul_launch_app_for_uid(appid, bundle_data, OWNER_UID); + if (ret < AUL_R_OK) { + _E("aul_launch_app_for_uid failed : %d", ret); + status = -1; + goto request_destroy; + } + + _I("Success to launch client with, key : %s, value : %s", + request_stack[top].key, request_stack[top].value); + + ret = bundle_free(bundle_data); + if (ret != BUNDLE_ERROR_NONE) + _W("bundle_free failed : %d", ret); + bundle_data = NULL; + + free(request_stack[top].key); + free(request_stack[top].value); + top--; + } request_destroy: - if (bundle_data) { - ret = bundle_free(bundle_data); - if (ret != BUNDLE_ERROR_NONE) { - _W("bundle_free failed : %d", ret); - } - } - - return status; + if (bundle_data) { + ret = bundle_free(bundle_data); + if (ret != BUNDLE_ERROR_NONE) + _W("bundle_free failed : %d", ret); + } + + return status; } int client_controller_add_launch_request_with_data(char *key, char *value) { - int ret = 0; - char *mem = NULL; - - if (top == MAX_STACK_SIZE - 1) { - _E("Failed to add launch request, Current top : %d", top); - return -1; - } - - mem = strndup(key, strlen(key)); - if (mem == NULL) { - _E("Failed to strndup key (%s) : %m", key); - return -1; - } - top++; - request_stack[top].key = mem; - - mem = strndup(value, strlen(value)); - if (mem == NULL) { - _E("Failed to strndup value (%s) : %m", value); - - /* Rollback */ - free(request_stack[top].key); - top--; - return -1; - } - request_stack[top].value = mem; - - _I("Success to add launch request, top : %d, key : %s, value : %s", - top, request_stack[top].key, request_stack[top].value); - ret = client_controller_process_launch_request(); - if (ret < 0) { - _E("Failed to process launch client : %d", ret); - return -1; - } - - return 0; -} \ No newline at end of file + int ret = 0; + char *mem = NULL; + + if (top == MAX_STACK_SIZE - 1) { + _E("Failed to add launch request, Current top : %d", top); + return -1; + } + + mem = strndup(key, strlen(key)); + if (mem == NULL) { + _E("Failed to strndup key (%s) : %m", key); + return -1; + } + top++; + request_stack[top].key = mem; + + mem = strndup(value, strlen(value)); + if (mem == NULL) { + _E("Failed to strndup value (%s) : %m", value); + + /* Rollback */ + free(request_stack[top].key); + top--; + return -1; + } + request_stack[top].value = mem; + + _I("Success to add launch request, top : %d, key : %s, value : %s", + top, request_stack[top].key, request_stack[top].value); + ret = client_controller_process_launch_request(); + if (ret < 0) { + _E("Failed to process launch client : %d", ret); + return -1; + } + + return 0; +} diff --git a/update-manager/client-info-checker.c b/update-manager/client-info-checker.c index 85afce7..9bb2cc7 100644 --- a/update-manager/client-info-checker.c +++ b/update-manager/client-info-checker.c @@ -4,101 +4,97 @@ static char *client_app_id = NULL; char *client_info_get_appid() { - return client_app_id; + return client_app_id; } int client_info_checker_callback(pkgmgrinfo_appinfo_h handle, void *user_data) { - int ret = 0, status = 0; - pkgmgrinfo_appinfo_h appinfo_h = NULL; + int ret = 0, status = 0; + pkgmgrinfo_appinfo_h appinfo_h = NULL; - if (client_app_id != NULL) { - _E("Client app id already exists : %s", client_app_id); - status = -1; - goto callback_destroy; - } + if (client_app_id != NULL) { + _E("Client app id already exists : %s", client_app_id); + status = -1; + goto callback_destroy; + } - ret = pkgmgrinfo_appinfo_clone_appinfo(handle, &appinfo_h); - if (ret != PMINFO_R_OK) { + ret = pkgmgrinfo_appinfo_clone_appinfo(handle, &appinfo_h); + if (ret != PMINFO_R_OK) { _E("pkgmgrinfo_appinfo_clone_appinfo failed : %d", ret); status = -1; - goto callback_destroy; + goto callback_destroy; } - ret = pkgmgrinfo_appinfo_get_appid(appinfo_h, &client_app_id); - if (ret != PMINFO_R_OK) { + ret = pkgmgrinfo_appinfo_get_appid(appinfo_h, &client_app_id); + if (ret != PMINFO_R_OK) { _E("app_info_get_app_id failed : %d", ret); status = -1; - goto callback_destroy; + goto callback_destroy; } - client_app_id = strndup(client_app_id, strlen(client_app_id)); - if (client_app_id == NULL) { - _E("Failed strndup : %m"); - status = -1; - goto callback_destroy; - } + client_app_id = strndup(client_app_id, strlen(client_app_id)); + if (client_app_id == NULL) { + _E("Failed strndup : %m"); + status = -1; + goto callback_destroy; + } - _I("Success to find client id : %s", client_app_id); - ret = client_controller_process_launch_request(); - if (ret < 0) { - _E("Failed to process launch client : %d", ret); - } + _I("Success to find client id : %s", client_app_id); + ret = client_controller_process_launch_request(); + if (ret < 0) + _E("Failed to process launch client : %d", ret); callback_destroy: - if (appinfo_h) { - ret = pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h); - if (ret != PMINFO_R_OK) { - _W("pkgmgrinfo_appinfo_destroy_appinfo failed : %d ", ret); - } - } - - return status; + if (appinfo_h) { + ret = pkgmgrinfo_appinfo_destroy_appinfo(appinfo_h); + if (ret != PMINFO_R_OK) + _W("pkgmgrinfo_appinfo_destroy_appinfo failed : %d ", ret); + } + + return status; } int client_info_checker_init() { - int ret = 0, status = 0; - pkgmgrinfo_appinfo_metadata_filter_h filter_h = NULL; + int ret = 0, status = 0; + pkgmgrinfo_appinfo_metadata_filter_h filter_h = NULL; - _I("Start process to get client app information"); - ret = pkgmgrinfo_appinfo_metadata_filter_create(&filter_h); - if (ret != PMINFO_R_OK) { + _I("Start process to get client app information"); + ret = pkgmgrinfo_appinfo_metadata_filter_create(&filter_h); + if (ret != PMINFO_R_OK) { _E("pkgmgrinfo_appinfo_metadata_filter_create failed : %d", ret); - status = -1; + status = -1; goto init_destroy; } - ret = pkgmgrinfo_appinfo_metadata_filter_add(filter_h, CLIENT_METADATA_KEY, CLIENT_METADATA_VALUE); - if (ret != PMINFO_R_OK) { + ret = pkgmgrinfo_appinfo_metadata_filter_add(filter_h, CLIENT_METADATA_KEY, CLIENT_METADATA_VALUE); + if (ret != PMINFO_R_OK) { _E("pkgmgrinfo_appinfo_metadata_filter_add failed : %d", ret); status = -1; goto init_destroy; } - ret = pkgmgrinfo_appinfo_metadata_filter_foreach(filter_h, client_info_checker_callback, NULL); - if (ret != PMINFO_R_OK) { + ret = pkgmgrinfo_appinfo_metadata_filter_foreach(filter_h, client_info_checker_callback, NULL); + if (ret != PMINFO_R_OK) { _E("pkgmgrinfo_appinfo_usr_metadata_filter_foreach failed : %d", ret); status = -1; goto init_destroy; } init_destroy: - if (filter_h) { + if (filter_h) { ret = pkgmgrinfo_appinfo_metadata_filter_destroy(filter_h); - if (ret != PMINFO_R_OK) { - _W("pkgmgrinfo_appinfo_metadata_filter_destroy failed : %d", ret); - } - } + if (ret != PMINFO_R_OK) + _W("pkgmgrinfo_appinfo_metadata_filter_destroy failed : %d", ret); + } - return status; + return status; } int client_info_checker_fini() { - if (client_app_id) { - free(client_app_id); - } + if (client_app_id) + free(client_app_id); - return 0; -} \ No newline at end of file + return 0; +} diff --git a/update-manager/client-status-checker.c b/update-manager/client-status-checker.c index 439f813..edb01b4 100644 --- a/update-manager/client-status-checker.c +++ b/update-manager/client-status-checker.c @@ -4,57 +4,55 @@ static int boot_status = -1; bool client_status_checker_is_success() { - return (boot_status == VCONFKEY_SYSMAN_BOOTING_SUCCESS); + return (boot_status == VCONFKEY_SYSMAN_BOOTING_SUCCESS); } void client_status_checker_callback(keynode_t *node, void *user_data) { - int ret = 0; - - ret = vconf_keynode_get_type(node); - if (ret == VCONF_TYPE_INT) { - boot_status = vconf_keynode_get_int(node); - if (client_status_checker_is_success()) { - _I("Success to get bootstatus : success"); - - ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BOOTINGSTATUS, client_status_checker_callback); - if (ret == VCONF_OK) { - _I("Success to remove bootstatus callback"); - } else { - _W("vconf_ignore_key_changed for %s failed : %d", VCONFKEY_SYSMAN_BOOTINGSTATUS, ret); - } - - ret = client_controller_process_launch_request(); - if (ret < 0) { - _E("Failed to process launch client : %d", ret); - } - } - } else { - _E("Invalid vconf key type : %d", ret); - } + int ret = 0; + + ret = vconf_keynode_get_type(node); + if (ret == VCONF_TYPE_INT) { + boot_status = vconf_keynode_get_int(node); + if (client_status_checker_is_success()) { + _I("Success to get bootstatus : success"); + + ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_BOOTINGSTATUS, client_status_checker_callback); + if (ret == VCONF_OK) + _I("Success to remove bootstatus callback"); + else + _W("vconf_ignore_key_changed for %s failed : %d", VCONFKEY_SYSMAN_BOOTINGSTATUS, ret); + + ret = client_controller_process_launch_request(); + if (ret < 0) + _E("Failed to process launch client : %d", ret); + } + } else { + _E("Invalid vconf key type : %d", ret); + } } int client_status_checker_init() { - int ret = 0; - - _I("Start process to get boot status"); - ret = vconf_get_int(VCONFKEY_SYSMAN_BOOTINGSTATUS, &boot_status); - if (ret != VCONF_OK) { - _E("vconf_get_int for %s failed: %d", VCONFKEY_SYSMAN_BOOTINGSTATUS, ret); - return -1; - } - - if (client_status_checker_is_success()) { - _I("Success to get boot status : success"); - } else { - ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_BOOTINGSTATUS, client_status_checker_callback, NULL); - if (ret != VCONF_OK) { - _E("vconf_notify_key_changed for %s failed : %d", VCONFKEY_SYSMAN_BOOTINGSTATUS, ret); - return -1; - } - _I("Success to register boot status callback"); - } - - return 0; -} \ No newline at end of file + int ret = 0; + + _I("Start process to get boot status"); + ret = vconf_get_int(VCONFKEY_SYSMAN_BOOTINGSTATUS, &boot_status); + if (ret != VCONF_OK) { + _E("vconf_get_int for %s failed: %d", VCONFKEY_SYSMAN_BOOTINGSTATUS, ret); + return -1; + } + + if (client_status_checker_is_success()) { + _I("Success to get boot status : success"); + } else { + ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_BOOTINGSTATUS, client_status_checker_callback, NULL); + if (ret != VCONF_OK) { + _E("vconf_notify_key_changed for %s failed : %d", VCONFKEY_SYSMAN_BOOTINGSTATUS, ret); + return -1; + } + _I("Success to register boot status callback"); + } + + return 0; +} diff --git a/update-manager/fota-controller.c b/update-manager/fota-controller.c index 6d000c5..9961366 100644 --- a/update-manager/fota-controller.c +++ b/update-manager/fota-controller.c @@ -4,244 +4,237 @@ static guint owner_id; int fota_controller_verify_delta(const char *delta_path) { - int ret = 0, status = 0; - char buf[MAX_BUFFER_SIZE] = {0, }; - char *current_release_version = NULL; - - if (g_file_test(delta_path, G_FILE_TEST_EXISTS)) { - _I("Found delta in %s, start process to verify", delta_path); - - ret = util_file_untar(delta_path, RELEASE_VERSION_DIR, RELEASE_VERSION_FILE); - if (ret < 0) { - _E("Failed to fetch version.txt from delta : %d", ret); - status = -1; - goto verify_destroy; - } - - ret = system_info_get_platform_string(RELEASE_INFO_KEY, ¤t_release_version); - if (ret != SYSTEM_INFO_ERROR_NONE) { - _E("system_info_get_platform_string failed : %d", ret); - status = -1; - goto verify_destroy; - } - - ret = util_file_read_line(RELEASE_VERSION_PATH, buf); - if (ret < 0) { - _E("Failed to read delta version : %d", ret); - status = -1; - goto verify_destroy; - } - - if (g_strrstr(buf, current_release_version) != NULL) { - _I("Delta version matched : %s", current_release_version); - } else { - _I("Delta version unmatched, current : %s, delta : %s", - current_release_version, buf); - status = 1; - } - } else { - _I("Not found delta in %s", delta_path); - status = 2; - } + int ret = 0, status = 0; + char buf[MAX_BUFFER_SIZE] = {0, }; + char *current_release_version = NULL; + + if (g_file_test(delta_path, G_FILE_TEST_EXISTS)) { + _I("Found delta in %s, start process to verify", delta_path); + + ret = util_file_untar(delta_path, RELEASE_VERSION_DIR, RELEASE_VERSION_FILE); + if (ret < 0) { + _E("Failed to fetch version.txt from delta : %d", ret); + status = -1; + goto verify_destroy; + } + + ret = system_info_get_platform_string(RELEASE_INFO_KEY, ¤t_release_version); + if (ret != SYSTEM_INFO_ERROR_NONE) { + _E("system_info_get_platform_string failed : %d", ret); + status = -1; + goto verify_destroy; + } + + ret = util_file_read_line(RELEASE_VERSION_PATH, buf); + if (ret < 0) { + _E("Failed to read delta version : %d", ret); + status = -1; + goto verify_destroy; + } + + if (g_strrstr(buf, current_release_version) != NULL) { + _I("Delta version matched : %s", current_release_version); + } else { + _I("Delta version unmatched, current : %s, delta : %s", + current_release_version, buf); + status = 1; + } + } else { + _I("Not found delta in %s", delta_path); + status = 2; + } verify_destroy: - ret = remove(RELEASE_VERSION_PATH); - if (ret < 0) { - _W("Failed to remove version.txt : %m"); - } + ret = remove(RELEASE_VERSION_PATH); + if (ret < 0) + _W("Failed to remove version.txt : %m"); - if (current_release_version) { - free(current_release_version); - } + if (current_release_version) + free(current_release_version); - return status; + return status; } int fota_controller_setup_delta() { - int ret = 0, status = 0; - char *appid = NULL; - gchar *shared_path = NULL; - - ret = util_file_mkdir(FOTA_DIR); - if (ret < 0) { - status = -1; - goto delta_destroy; - } - - appid = client_info_get_appid(); - if (appid == NULL) { - _I("Failed to get client app id"); - status = -1; - goto delta_destroy; - } - - ret = remove(FOTA_DELTA_PATH); - if (ret < 0 && errno != ENOENT) { - _W("Failed to remove exist link : %m"); - } - - shared_path = g_strjoin("/", SHARED_DIR, appid, SHARED_DATA_DIR, FOTA_DELTA_FILE, NULL); - ret = fota_controller_verify_delta(shared_path); - if (ret < 0) { - _E("Failed to verify delta : %d", ret); - status = -1; - goto delta_destroy; - } else if (ret > 0) { - _I("Failed to verify delta : %d", ret); - status = -1; - goto delta_destroy; - } - - ret = symlink(shared_path, FOTA_DELTA_PATH); - if (ret < 0) { - _E("Failed to link delta : %m"); - status = -1; - goto delta_destroy; - } - - ret = util_file_untar(FOTA_DELTA_PATH, FOTA_DIR, FOTA_DELTA_UA_FILE); - if (ret < 0) { - _E("Failed to fetch delta.ua from delta : %d", ret); - status = -1; - goto delta_destroy; - } - - _I("Success to setup delta to %s", FOTA_DIR); + int ret = 0, status = 0; + char *appid = NULL; + gchar *shared_path = NULL; + + ret = util_file_mkdir(FOTA_DIR); + if (ret < 0) { + status = -1; + goto delta_destroy; + } + + appid = client_info_get_appid(); + if (appid == NULL) { + _I("Failed to get client app id"); + status = -1; + goto delta_destroy; + } + + ret = remove(FOTA_DELTA_PATH); + if (ret < 0 && errno != ENOENT) + _W("Failed to remove exist link : %m"); + + shared_path = g_strjoin("/", SHARED_DIR, appid, SHARED_DATA_DIR, FOTA_DELTA_FILE, NULL); + ret = fota_controller_verify_delta(shared_path); + if (ret < 0) { + _E("Failed to verify delta : %d", ret); + status = -1; + goto delta_destroy; + } else if (ret > 0) { + _I("Failed to verify delta : %d", ret); + status = -1; + goto delta_destroy; + } + + ret = symlink(shared_path, FOTA_DELTA_PATH); + if (ret < 0) { + _E("Failed to link delta : %m"); + status = -1; + goto delta_destroy; + } + + ret = util_file_untar(FOTA_DELTA_PATH, FOTA_DIR, FOTA_DELTA_UA_FILE); + if (ret < 0) { + _E("Failed to fetch delta.ua from delta : %d", ret); + status = -1; + goto delta_destroy; + } + + _I("Success to setup delta to %s", FOTA_DIR); delta_destroy: - g_free(shared_path); + g_free(shared_path); - return status; + return status; } int fota_controller_setup_status() { - int ret = 0; + int ret = 0; - ret = util_file_mkdir(STATUS_DIR); - if (ret < 0) { - return -1; - } + ret = util_file_mkdir(STATUS_DIR); + if (ret < 0) + return -1; - ret = util_file_write_line(STATUS_FLAG_PATH, ""); - if (ret < 0) { - return -1; - } + ret = util_file_write_line(STATUS_FLAG_PATH, ""); + if (ret < 0) + return -1; - ret = util_file_write_line(STATUS_FOTA_PATH, FOTA_DIR); - if (ret < 0) { - return -1; - } + ret = util_file_write_line(STATUS_FOTA_PATH, FOTA_DIR); + if (ret < 0) + return -1; - _I("Success to setup fota status to %s", STATUS_DIR); + _I("Success to setup fota status to %s", STATUS_DIR); - return 0; + return 0; } int fota_controller_write_platform_version() { - int ret = 0, status = 0; - char *platform_version = NULL; - gchar *formatted_version = NULL; - - ret = system_info_get_platform_string(PLATFORM_VERSION_KEY, &platform_version); - if (ret != SYSTEM_INFO_ERROR_NONE) { - _E("system_info_get_platform_string failed : %d", ret); - status = -1; - goto version_destroy; - } - - formatted_version = g_strconcat("OLD_VER=", platform_version, ".0.0\n", NULL); - ret = util_file_write_line(PLATFORM_VERSION_PATH, formatted_version); - if (ret < 0) { - status = -1; - goto version_destroy; - } - - _I("Success to write version to %s : %s", PLATFORM_VERSION_PATH, platform_version); + int ret = 0, status = 0; + char *platform_version = NULL; + gchar *formatted_version = NULL; + + ret = system_info_get_platform_string(PLATFORM_VERSION_KEY, &platform_version); + if (ret != SYSTEM_INFO_ERROR_NONE) { + _E("system_info_get_platform_string failed : %d", ret); + status = -1; + goto version_destroy; + } + + formatted_version = g_strconcat("OLD_VER=", platform_version, ".0.0\n", NULL); + ret = util_file_write_line(PLATFORM_VERSION_PATH, formatted_version); + if (ret < 0) { + status = -1; + goto version_destroy; + } + + _I("Success to write version to %s : %s", PLATFORM_VERSION_PATH, platform_version); version_destroy: - if (platform_version) { - free(platform_version); - } + if (platform_version) + free(platform_version); - g_free(formatted_version); + g_free(formatted_version); - return status; + return status; } /* dbus-send --system --dest=org.tizen.update.manager --type=method_call /org/tizen/update/manager org.tizen.update.manager.install */ gboolean fota_controller_install(OrgTizenUpdateManager *skeleton, GDBusMethodInvocation *invocation, gpointer user_data) { - int ret = 0, status = 0; - - ret = fota_controller_setup_delta(); - if (ret < 0) { - _E("Failed to setup delta.tar"); - status = -1; - goto install_destroy; - } - - ret = fota_controller_write_platform_version(); - if (ret < 0) { - _E("Failed to write platform version"); - status = -1; - goto install_destroy; - } - - ret = fota_controller_setup_status(); - if (ret < 0) { - _E("Failed to setup fota update status"); - status = -1; - goto install_destroy; - } - - ret = device_power_reboot(FOTA_REBOOT_REASON); - if (ret != DEVICE_ERROR_NONE) { - _E("Failed to request reboot with reason : %s", FOTA_REBOOT_REASON); - status = -1; - goto install_destroy; - } - - _I("Success to request fota, device will reboot"); + int ret = 0, status = 0; + + ret = fota_controller_setup_delta(); + if (ret < 0) { + _E("Failed to setup delta.tar"); + status = -1; + goto install_destroy; + } + + ret = fota_controller_write_platform_version(); + if (ret < 0) { + _E("Failed to write platform version"); + status = -1; + goto install_destroy; + } + + ret = fota_controller_setup_status(); + if (ret < 0) { + _E("Failed to setup fota update status"); + status = -1; + goto install_destroy; + } + + ret = device_power_reboot(FOTA_REBOOT_REASON); + if (ret != DEVICE_ERROR_NONE) { + _E("Failed to request reboot with reason : %s", FOTA_REBOOT_REASON); + status = -1; + goto install_destroy; + } + + _I("Success to request fota, device will reboot"); install_destroy: - org_tizen_update_manager_complete_install(skeleton, invocation, status); + org_tizen_update_manager_complete_install(skeleton, invocation, status); - return TRUE; + return TRUE; } void fota_controller_on_name_lost(GDBusConnection *conn, const gchar *name, gpointer user_data) { - _D("Dbus status : name lost"); + _D("Dbus status : name lost"); } void fota_controller_on_name_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data) { - _D("Dbus status : name acquired"); + _D("Dbus status : name acquired"); - OrgTizenUpdateManager *skeleton = org_tizen_update_manager_skeleton_new(); - g_signal_connect(skeleton, "handle-install", G_CALLBACK(fota_controller_install), NULL); - g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(skeleton), conn, NODE_NAME, NULL); + OrgTizenUpdateManager *skeleton = org_tizen_update_manager_skeleton_new(); + g_signal_connect(skeleton, "handle-install", G_CALLBACK(fota_controller_install), NULL); + g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(skeleton), conn, NODE_NAME, NULL); } void fota_controller_on_bus_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data) { - _D("Dbus status : bus acquired"); + _D("Dbus status : bus acquired"); } int fota_controller_init() { - owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, INTERFACE_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, - fota_controller_on_bus_acquired, fota_controller_on_name_acquired, fota_controller_on_name_lost, NULL, NULL); + owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, INTERFACE_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, + fota_controller_on_bus_acquired, fota_controller_on_name_acquired, fota_controller_on_name_lost, NULL, NULL); - return 0; + return 0; } int fota_controller_fini() { - g_bus_unown_name(owner_id); + g_bus_unown_name(owner_id); - return 0; -} \ No newline at end of file + return 0; +} diff --git a/update-manager/fota-status-checker.c b/update-manager/fota-status-checker.c index 171eabf..8536739 100644 --- a/update-manager/fota-status-checker.c +++ b/update-manager/fota-status-checker.c @@ -2,37 +2,37 @@ int fota_status_checker_init() { - int ret = 0; - char buf[MAX_BUFFER_SIZE] = {0,}; - bool exist = false; + 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) { - _I("This boot is triggered with fota, start process to send result to client"); + exist = g_file_test(STATUS_FLAG_PATH, G_FILE_TEST_EXISTS) && g_file_test(STATUS_RESULT_PATH, G_FILE_TEST_EXISTS); + if (exist) { + _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 = 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); - if (ret < 0) { - _E("Failed to add launch request : %d, key : %s, value : %s", - ret, CLIENT_APP_CTRL_REBOOT_KEY, buf); - return -1; - } + ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_REBOOT_KEY, buf); + if (ret < 0) { + _E("Failed to add launch request : %d, key : %s, value : %s", + ret, CLIENT_APP_CTRL_REBOOT_KEY, buf); + return -1; + } - ret = remove(STATUS_FLAG_PATH); - if (ret != 0) { - _E("Failed to remove fota flag : %m"); - return -1; - } + ret = remove(STATUS_FLAG_PATH); + if (ret != 0) { + _E("Failed to remove fota flag : %m"); + return -1; + } - _I("Success to process boot triggered with fota"); - } else { - _I("This boot isn't triggered with fota"); - } + _I("Success to process boot triggered with fota"); + } else { + _I("This boot isn't triggered with fota"); + } - return 0; -} \ No newline at end of file + return 0; +} diff --git a/update-manager/fota-storage-checker.c b/update-manager/fota-storage-checker.c index 709c81b..895c638 100644 --- a/update-manager/fota-storage-checker.c +++ b/update-manager/fota-storage-checker.c @@ -2,73 +2,73 @@ void fota_storage_checker_process(const char *mount_path) { - int ret = 0; - gchar *delta_path = NULL; + int ret = 0; + gchar *delta_path = NULL; - _I("Storage mounted with %s, start process to check local delta", mount_path); - delta_path = g_strconcat(mount_path, "/", FOTA_DELTA_FILE, NULL); - ret = fota_controller_verify_delta(delta_path); - if (ret < 0) { - _E("Failed to verify delta : %d", ret); - goto process_destroy; - } else if (ret > 0) { - _I("Failed to verify delta : %d", ret); - goto process_destroy; - } + _I("Storage mounted with %s, start process to check local delta", mount_path); + delta_path = g_strconcat(mount_path, "/", FOTA_DELTA_FILE, NULL); + ret = fota_controller_verify_delta(delta_path); + if (ret < 0) { + _E("Failed to verify delta : %d", ret); + goto process_destroy; + } else if (ret > 0) { + _I("Failed to verify delta : %d", ret); + goto process_destroy; + } - ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_LOCAL_KEY, delta_path); - if (ret < 0) { - _E("Failed to add launch request : %d, key : %s, value : %s", - ret, CLIENT_APP_CTRL_LOCAL_KEY, delta_path); - } + ret = client_controller_add_launch_request_with_data(CLIENT_APP_CTRL_LOCAL_KEY, delta_path); + if (ret < 0) { + _E("Failed to add launch request : %d, key : %s, value : %s", + ret, CLIENT_APP_CTRL_LOCAL_KEY, delta_path); + } process_destroy: - g_free(delta_path); + g_free(delta_path); } void fota_storage_checker_callback(int storage_id, storage_dev_e dev, storage_state_e state, const char *fstype, - const char *fsuuid, const char *mount_path, bool primary, int flags, void *user_data) + const char *fsuuid, const char *mount_path, bool primary, int flags, void *user_data) { - switch (state) { - case STORAGE_STATE_UNMOUNTABLE: - case STORAGE_STATE_REMOVED: - case STORAGE_STATE_MOUNTED_READ_ONLY: - _D("Storage %d status : not mounted", storage_id); - break; - case STORAGE_STATE_MOUNTED: - _I("Storage %d status : mounted", storage_id); - fota_storage_checker_process(mount_path); - break; - default: - _E("Unexpected state : %d", state); - } + switch (state) { + case STORAGE_STATE_UNMOUNTABLE: + case STORAGE_STATE_REMOVED: + case STORAGE_STATE_MOUNTED_READ_ONLY: + _D("Storage %d status : not mounted", storage_id); + break; + case STORAGE_STATE_MOUNTED: + _I("Storage %d status : mounted", storage_id); + fota_storage_checker_process(mount_path); + break; + default: + _E("Unexpected state : %d", state); + } } int fota_storage_checker_init() { - int ret = 0; + int ret = 0; - _I("Start process to get storage status"); - ret = storage_set_changed_cb(STORAGE_TYPE_EXTERNAL, fota_storage_checker_callback, NULL); - if (ret == STORAGE_ERROR_NOT_SUPPORTED) { - _I("External storage is not suppported, so local update will not be supported"); - } else if (ret != STORAGE_ERROR_NONE) { - _E("storage_set_changed_cb failed : %d", ret); - return -1; - } + _I("Start process to get storage status"); + ret = storage_set_changed_cb(STORAGE_TYPE_EXTERNAL, fota_storage_checker_callback, NULL); + if (ret == STORAGE_ERROR_NOT_SUPPORTED) { + _I("External storage is not suppported, so local update will not be supported"); + } else if (ret != STORAGE_ERROR_NONE) { + _E("storage_set_changed_cb failed : %d", ret); + return -1; + } - return 0; + return 0; } int fota_storage_checker_fini() { - int ret = 0; + int ret = 0; - ret = storage_unset_changed_cb(STORAGE_TYPE_EXTERNAL, fota_storage_checker_callback); - if (ret != STORAGE_ERROR_NONE) { - _W("failed storage_unset_changed_cb : %d", ret); - return -1; - } + ret = storage_unset_changed_cb(STORAGE_TYPE_EXTERNAL, fota_storage_checker_callback); + if (ret != STORAGE_ERROR_NONE) { + _W("failed storage_unset_changed_cb : %d", ret); + return -1; + } - return 0; -} \ No newline at end of file + return 0; +} diff --git a/update-manager/main.c b/update-manager/main.c index af6badd..29b0adb 100644 --- a/update-manager/main.c +++ b/update-manager/main.c @@ -2,71 +2,68 @@ int main(int argc, char *argv[]) { - int ret = 0; - GMainLoop *mainloop = NULL; + int ret = 0; + GMainLoop *mainloop = NULL; - mainloop = g_main_loop_new(NULL, FALSE); - if (!mainloop) { - _E("Failed to create mainloop"); - return -ENOMEM; - } + mainloop = g_main_loop_new(NULL, FALSE); + if (!mainloop) { + _E("Failed to create mainloop"); + return -ENOMEM; + } - /* Client */ - ret = client_info_checker_init(); - if (ret < 0) { - _E("Failed to initialize client info checker : %d", ret); - goto main_destroy; - } + /* Client */ + ret = client_info_checker_init(); + if (ret < 0) { + _E("Failed to initialize client info checker : %d", ret); + goto main_destroy; + } - ret = client_status_checker_init(); - if (ret < 0) { - _E("Failed to initialize client status checker : %d", ret); - goto main_destroy; - } + ret = client_status_checker_init(); + if (ret < 0) { + _E("Failed to initialize client status checker : %d", ret); + goto main_destroy; + } - /* Fota */ - ret = fota_storage_checker_init(); - if (ret < 0) { - _E("Failed to initialize fota storage checker : %d", ret); - goto main_destroy; - } + /* Fota */ + ret = fota_storage_checker_init(); + if (ret < 0) { + _E("Failed to initialize fota storage checker : %d", ret); + goto main_destroy; + } - ret = fota_status_checker_init(); - if (ret < 0) { - _E("Failed to initialize fota status checker : %d", ret); - goto main_destroy; - } + ret = fota_status_checker_init(); + if (ret < 0) { + _E("Failed to initialize fota status checker : %d", ret); + goto main_destroy; + } - ret = fota_controller_init(); - if (ret < 0) { - _E("Failed to initialize fota controller : %d", ret); - goto main_destroy; - } + ret = fota_controller_init(); + if (ret < 0) { + _E("Failed to initialize fota controller : %d", ret); + goto main_destroy; + } - g_main_loop_run(mainloop); + g_main_loop_run(mainloop); main_destroy: - /* Client */ - ret = client_info_checker_fini(); - if (ret < 0) { - _W("Failed to finalize client info checker : %d", ret); - } + /* Client */ + ret = client_info_checker_fini(); + if (ret < 0) + _W("Failed to finalize client info checker : %d", ret); - /* Fota */ - ret = fota_storage_checker_fini(); - if (ret < 0) { - _W("Failed to finalize fota storage checker : %d", ret); - } + /* Fota */ + ret = fota_storage_checker_fini(); + if (ret < 0) + _W("Failed to finalize fota storage checker : %d", ret); - ret = fota_controller_fini(); - if (ret < 0) { - _W("Failed to finalize fota controller : %d", ret); - } + ret = fota_controller_fini(); + if (ret < 0) + _W("Failed to finalize fota controller : %d", ret); - if (mainloop) { - g_main_loop_quit(mainloop); - g_main_loop_unref(mainloop); - } + if (mainloop) { + g_main_loop_quit(mainloop); + g_main_loop_unref(mainloop); + } - return EXIT_FAILURE; + return EXIT_FAILURE; } diff --git a/update-manager/update-manager.h b/update-manager/update-manager.h index b774153..2a4a0ca 100644 --- a/update-manager/update-manager.h +++ b/update-manager/update-manager.h @@ -97,4 +97,4 @@ int util_file_read_line(const char *, char []); int util_file_write_line(const char *, const char *); int util_file_untar(const char *, const char *, const char *); -#endif /* __UPDATE_MANAGER_H__ */ \ No newline at end of file +#endif /* __UPDATE_MANAGER_H__ */ diff --git a/update-manager/util.c b/update-manager/util.c index 80b115a..54d6355 100644 --- a/update-manager/util.c +++ b/update-manager/util.c @@ -2,79 +2,79 @@ int util_file_mkdir(const char *path) { - int ret = 0; - gboolean exist = FALSE; + int ret = 0; + gboolean exist = FALSE; - exist = g_file_test(path, G_FILE_TEST_IS_DIR); - if (!exist) { - ret = mkdir(path, 0775); - if (ret < 0) { - _E("Failed to make %s : %m", path); - return -1; - } - } + exist = g_file_test(path, G_FILE_TEST_IS_DIR); + if (!exist) { + ret = mkdir(path, 0775); + if (ret < 0) { + _E("Failed to make %s : %m", path); + return -1; + } + } - return 0; + return 0; } int util_file_read_line(const char *path, char buf[]) { - int status = 0; - FILE *fp = NULL; + int status = 0; + FILE *fp = NULL; - fp = fopen(path, "r"); - if (fp != NULL) { - if (fgets(buf, MAX_BUFFER_SIZE, fp) == NULL) { - _E("Failed to read : %s", path); - status = -1; - } - fclose(fp); - } else { - _E("Failed to open : %s", path); - status = -1; - } + fp = fopen(path, "r"); + if (fp != NULL) { + if (fgets(buf, MAX_BUFFER_SIZE, fp) == NULL) { + _E("Failed to read : %s", path); + status = -1; + } + fclose(fp); + } else { + _E("Failed to open : %s", path); + status = -1; + } - return status; + return status; } int util_file_write_line(const char *path, const char *msg) { - int ret = 0, status = 0; - FILE *fp = NULL; + int ret = 0, status = 0; + FILE *fp = NULL; - fp = fopen(path, "w"); - if (fp != NULL) { - ret = fprintf(fp, "%s", msg); - if (ret < 0) { - _E("Failed to write, path : %s, msg : %s", path, msg); - status = -1; - } - fclose(fp); - } else { - _E("Failed to open : %s", path); - status = -1; - } + fp = fopen(path, "w"); + if (fp != NULL) { + ret = fprintf(fp, "%s", msg); + if (ret < 0) { + _E("Failed to write, path : %s, msg : %s", path, msg); + status = -1; + } + fclose(fp); + } else { + _E("Failed to open : %s", path); + status = -1; + } - return status; + return status; } int util_file_untar(const char *tar_path, const char *dest_path, const char *extract_file_name) { - int ret = 0, status = 0; - char *command = NULL; + int ret = 0, status = 0; + char *command = NULL; - command = g_strjoin(" ", - "tar", "xvfp", tar_path, "-C", dest_path, extract_file_name, NULL); + command = g_strjoin(" ", + "tar", "xvfp", tar_path, "-C", dest_path, extract_file_name, NULL); - ret = system(command); - if (ret < 0) { - _E("Failed to execute untar command : %m"); - status = -1; - } else if (ret > 0) { - _E("Failed to untar : %d", ret); - status = -1; - } - free(command); + ret = system(command); + if (ret < 0) { + _E("Failed to execute untar command : %m"); + status = -1; + } else if (ret > 0) { + _E("Failed to untar : %d", ret); + status = -1; + } + free(command); - return status; -} \ No newline at end of file + return status; +}