From 895bbcf04fd40f0de31c1a8e3da6a5ff867e68ab Mon Sep 17 00:00:00 2001 From: Jeonghoon Park Date: Thu, 28 Jun 2018 17:53:22 +0900 Subject: [PATCH] add command function to upload log Change-Id: Ifdedcbd08a96721297800449d879fed30096a995 --- daemon/src/ttd-cmd-func.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/daemon/src/ttd-cmd-func.c b/daemon/src/ttd-cmd-func.c index e5c75d9..282b035 100644 --- a/daemon/src/ttd-cmd-func.c +++ b/daemon/src/ttd-cmd-func.c @@ -15,10 +15,14 @@ */ #include +#include #include "ttd-log.h" #include "ttd-cmd.h" #include "ttd-config.h" #include "ttd-worker-handle.h" +#include "ttd-diag.h" +#include "ttd-http.h" +#include "ttd-cmd-mgr.h" static int __config_write(ttd_cmd_data *c_data) { @@ -53,6 +57,9 @@ static int __config_write(ttd_cmd_data *c_data) break; } + ttd_cmd_mgr_push_result( + ttd_cmd_get_id(c_data), TTD_CMD_RESULT_SUCCESS, NULL); + return 0; } @@ -76,6 +83,49 @@ static int __worker_launch(ttd_cmd_data *c_data) return ret; } +static int __diagnosis_run(ttd_cmd_data *c_data) +{ + int ret = 0; + ttd_cmd_diagnosis_e diag_type; + char *zip_file = NULL; + long res_code = 0; + char *res_msg = NULL; + char *result_json = NULL; + + retv_if(!c_data, -1); + + diag_type = ttd_cmd_get_command(c_data); + + if (diag_type != TTD_CMD_DIAGNOSIS_GET_LOG) + return -1; + + zip_file = ttd_diag_collect_log_to_zip(); + retv_if(!zip_file, -1); + + ret = ttd_http_logfile_post(zip_file, &res_code, &res_msg); + if (ret || (res_code != TTD_HTTP_OK)) { + _E("failed to upload logfile[%s]", zip_file); + _E("res_code [%ls] with res_msg[%s]", res_code, res_msg); + g_free(res_msg); + g_remove(zip_file); + g_free(zip_file); + return -1; + } + + result_json = g_strdup_printf("{ \"url\" : \"%s\" }", res_msg); + g_free(res_msg); + res_msg = NULL; + + ttd_cmd_mgr_push_result( + ttd_cmd_get_id(c_data), TTD_CMD_RESULT_SUCCESS, result_json); + + g_free(result_json); + g_remove(zip_file); + g_free(zip_file); + + return ret; +} + ttd_cmd_launch_func ttd_cmd_get_launch_func(ttd_cmd_type_e type) { ttd_cmd_launch_func func = NULL; @@ -91,6 +141,7 @@ ttd_cmd_launch_func ttd_cmd_get_launch_func(ttd_cmd_type_e type) func = __worker_launch; break; case TTD_CMD_TYPE_DIAGNOSIS: + func = __diagnosis_run; break; case TTD_CMD_TYPE_LOCAL: break; -- 2.7.4