From: Kichan Kwon Date: Mon, 8 Jun 2020 02:19:20 +0000 (+0900) Subject: Write current progress to file by itself X-Git-Tag: accepted/tizen/unified/20200616.041013^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F16%2F235616%2F6;p=platform%2Fcore%2Fsystem%2Ftota-ua.git Write current progress to file by itself - To unify with system-rw-update - Write to socket -> Write to file - Remove fota-gui-test Change-Id: I79d26710b171759e40df511a5996a13f6e0e3373 Signed-off-by: Kichan Kwon --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 433cfa7..9890e9a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,6 @@ SET(BINDIR "${PREFIX}/bin") SET(PKGDIR "${PREFIX}/share/fota") SET(RESDIR "${PKGDIR}/res") SET(EXECNAME "delta.ua") -SET(FOTA_GUI_TEST "fota_gui_test") IF("${CMAKE_BUILD_TYPE}" STREQUAL "") SET(CMAKE_BUILD_TYPE "Release") @@ -61,9 +60,6 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--as-needed -pie") ADD_EXECUTABLE(${EXECNAME} ${SRCS}) TARGET_LINK_LIBRARIES(${EXECNAME} ${pkgs_LDFLAGS}) -ADD_EXECUTABLE(${FOTA_GUI_TEST} src/fota_gui_test.c) - INSTALL(TARGETS ${EXECNAME} DESTINATION ${BINDIR}) -INSTALL(TARGETS ${FOTA_GUI_TEST} DESTINATION ${BINDIR}) ADD_SUBDIRECTORY(upg-verifier) diff --git a/packaging/tota-ua.spec b/packaging/tota-ua.spec index 77d2425..515c233 100755 --- a/packaging/tota-ua.spec +++ b/packaging/tota-ua.spec @@ -62,6 +62,5 @@ mkdir -p %{buildroot}%{tota_ca_dir} %{_bindir}/delta.ua %{_bindir}/upgrade-trigger.sh %attr(700,-,-) %{_datadir}/initrd-recovery/initrd.list.d/40-tota-ua.list -%{_bindir}/fota_gui_test %{_sbindir}/upg-verifier %attr(755,root,root) %{tota_ca_dir} diff --git a/src/fota_gui_test.c b/src/fota_gui_test.c deleted file mode 100755 index 5ba53ff..0000000 --- a/src/fota_gui_test.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * tota-ua - * - * Copyright (c) 2017 Samsung Electronics Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define LOG(s, args...) do { printf("FOTA_GUI_TEST" "/(%s): " s, __func__, ##args); } while (0) - - -#define SERV_PATH "/tmp/FotaGuiSocket" - -typedef struct { - char cmd_name[64]; - int argc; - char argv[3][64]; -} sock_cmd; - -typedef struct { - int ack; - char ack_desc[256]; -} sock_ack; - -#define CMD_SUCCESS 0 -#define CMD_ERROR -1 -#define MISSING_PARAM -2 - -int sockfd = 0; -int initcomplete = 0; -sock_cmd *sendbuff = NULL; -sock_ack *recvbuff = NULL; - -int sock_init(void) -{ - int len, ret; - struct sockaddr_un serv_addr; - - LOG("%s\n", __func__); - sendbuff = malloc(sizeof(sock_cmd)); - if (sendbuff == NULL) { - LOG("memory allocation failed:%s\n", __FUNCTION__); - return -1; - } - - recvbuff = malloc(sizeof(sock_ack)); - if (recvbuff == NULL) { - LOG("memory allocation failed:%s\n", __FUNCTION__); - return -1; - } - - sockfd = socket(AF_UNIX, SOCK_STREAM, 0); - if (sockfd < 0) { - perror("\n Error : socket Failed \n"); - return -1; - } - bzero((char *)&serv_addr, sizeof(serv_addr)); - serv_addr.sun_family = AF_UNIX; - strncpy(serv_addr.sun_path, SERV_PATH, sizeof(serv_addr.sun_path) - 1); - len = sizeof(serv_addr); - - ret = connect(sockfd, (struct sockaddr *)&serv_addr, len); - if (ret < 0) { - LOG("\n Error : Connect Failed \n"); - return -1; - } - - initcomplete = 1; - return ret; -} - -void sock_deinit(void) -{ - LOG("%s\n", __func__); - - close(sockfd); - free(sendbuff); - free(recvbuff); - initcomplete = 0; -} - -int sock_cmd_progress(int percent_progress) -{ - int result = 0; - - LOG("%s \n", __func__); - if (!initcomplete) { - LOG("sock_init unsuccessful \n"); - return -1; - } - - memset(sendbuff, 0, sizeof(sock_cmd)); - memset(recvbuff, 0xFF, sizeof(sock_ack)); - - strncpy(sendbuff->cmd_name, "draw_progress", 63); - sendbuff->argc = 1; - snprintf(sendbuff->argv[0], 63, "%d", percent_progress); - LOG("sendbuff->argv[0] = %s \n", sendbuff->argv[0]); - - result = write(sockfd, sendbuff, sizeof(sock_cmd)); - if (result < 0) { - LOG(" Write Failed! \n"); - return -1; - } - - result = read(sockfd, recvbuff, sizeof(sock_ack)); - recvbuff->ack_desc[255] = 0x00; - if (recvbuff->ack != CMD_SUCCESS || result < 0) { - LOG(" Fail %s ret(%d)\n", recvbuff->ack_desc, recvbuff->ack); - return -1; - } else - LOG("%s ret(%d)\n", recvbuff->ack_desc, recvbuff->ack); - - return recvbuff->ack; -} - -int sock_cmd_end(void) -{ - int result = 0; - - LOG("%s \n", __func__); - if (!initcomplete) { - LOG("sock_init unsuccessful \n"); - return -1; - } - - memset(sendbuff, 0, sizeof(sock_cmd)); - memset(recvbuff, 0xFF, sizeof(sock_ack)); - - strncpy(sendbuff->cmd_name, "draw_end", 63); - sendbuff->argc = 0; - - result = write(sockfd, sendbuff, sizeof(sock_cmd)); - if (result < 0) { - LOG(" Write Failed! \n"); - return -1; - } - - result = read(sockfd, recvbuff, sizeof(sock_ack)); - recvbuff->ack_desc[255] = 0x00; - if (recvbuff->ack != CMD_SUCCESS || result < 0) { - LOG(" Fail %s ret(%d)\n", recvbuff->ack_desc, recvbuff->ack); - return -1; - } else - LOG("%s ret(%d)\n", recvbuff->ack_desc, recvbuff->ack); - - return recvbuff->ack; -} - -int main(int argc, char **argv) -{ - int ret; - int percent = 0; - - if (argc != 2) { - LOG("Invalid argc = %d\n", argc); - return -1; - } - - if (sock_init() < 0) { - LOG("sock_init() failed\n"); - return -1; - } - - percent = atoi(argv[1]); - if (percent == -1) - ret = sock_cmd_end(); - else - ret = sock_cmd_progress(percent); - LOG("ret = %d\n", ret); - - sock_deinit(); - - return 0; -} - - diff --git a/src/ua.c b/src/ua.c index 23cd8a5..65e5935 100755 --- a/src/ua.c +++ b/src/ua.c @@ -42,7 +42,6 @@ #define MAX_CFG_LEN 4096 #define RAMDISK_PATH "/opt/usr/data/fota" -#define FOTA_GUI_INTERFACE "/usr/bin/fota_gui_test" #define SYSTEM_LOG_DIR "/opt/var/log" int ua_op_mode = UA_OP_MODE_FG; @@ -76,15 +75,62 @@ static void save_cause(int cause); /*----------------------------------------------------------------------------- fota_gui_update_progress ----------------------------------------------------------------------------*/ +#define TMP_DIR "/tmp/upgrade" +#define PROGRESS_FILE TMP_DIR "/ro_progress" + void fota_gui_update_progress(int percent) { - int ret = 0; - char cmd[1024]; + int ret; + int fd; + struct stat s; + + // Check directory + ret = stat(TMP_DIR, &s); + if (ret == 0) { + // TMP_DIR exists but it is not directory + if (!S_ISDIR(s.st_mode)) + goto remove_file; + else + goto update_progress; + } else if (errno == ENOENT) // TMP_DIR not exists + goto make_directory; + else { + LOG("stat failed : %m\n"); + return; + } + +remove_file: + ret = remove(TMP_DIR); + if (ret != 0) { + LOG("remove failed : %m\n"); + return; + } + +make_directory: + ret = mkdir(TMP_DIR, 0755); + if (ret != 0) { + LOG("mkdir failed : %m\n"); + return; + } + +update_progress: + fd = creat(PROGRESS_FILE, 0644); + if (fd < 0) { + LOG("creat failed : %m\n"); + return; + } - snprintf(cmd, sizeof(cmd)-1, "%s %d", FOTA_GUI_INTERFACE, percent); + ret = dprintf(fd, "%d\n", percent); + if (close(fd) != 0) { + LOG("close failed : %m\n"); + return; + } + if (ret < 2) { + LOG("write failed (%d) : %m\n", ret); + return; + } - ret = _system_cmd_wait(cmd); - LOG("ret = %d\n", ret); + LOG("Succeed to write\n"); } /*-----------------------------------------------------------------------------