From 4ceb763946ac70a9d9be1860378e99d8a358c09b Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Fri, 21 Apr 2017 00:09:36 +0300 Subject: [PATCH] Move uihv_data storing to manager Change-Id: I90f2b3dfbbe121dbd315566c114a23917de52155 Signed-off-by: Vyacheslav Cherkashin --- daemon/threads.c | 140 +++++++++++++++++++++----------------------- ui_viewer/ui_viewer_lib.c | 2 +- ui_viewer/ui_viewer_utils.c | 87 ++++++++++++++++++--------- ui_viewer/ui_viewer_utils.h | 2 +- 4 files changed, 128 insertions(+), 103 deletions(-) diff --git a/daemon/threads.c b/daemon/threads.c index e16eeef..b9c8361 100644 --- a/daemon/threads.c +++ b/daemon/threads.c @@ -54,35 +54,6 @@ #include "buffer.h" #include "input_events.h" -static int chsmack(const char *filename) -{ - int res = 1; - pid_t pid; - char cmd[1024]; - int status; - - pid = fork(); - switch (pid) { - case -1: - /* fail to fork */ - LOGE("cannot fork"); - break; - case 0: - /* child */ - snprintf(cmd, sizeof(cmd), "chsmack -a \"*\" \"%s\"", filename); - execl(SHELL_CMD, SHELL_CMD, "-c", cmd, NULL); - - /* exec fail */ - LOGE("exec fail! <%s>\n", cmd); - break; - default: - /* parent */ - waitpid(pid, &status, 0); - res = 0; - } - - return res; -} static int do_fchown(int fd, const char *user, const char *group) { @@ -113,7 +84,7 @@ static int do_fchown(int fd, const char *user, const char *group) return 0; } -static int screenshot_save(char *path, const void *data, size_t len) +static int save_data_to_tmpfile(char *path, const void *data, size_t len) { int fd, ret = 0; @@ -211,7 +182,7 @@ static void processing_app_msg_image(const void *data, size_t len) sh_data = data; sh_len = len - 4 - sh_info_len - 4; - if (!screenshot_save(path, sh_data, sh_len)) + if (!save_data_to_tmpfile(path, sh_data, sh_len)) send_screenshot_msg(path, angle, sh_info, sh_info_len); else LOGE("Cannot save screenshot\n"); @@ -233,7 +204,7 @@ static void processing_ui_screenshot(const void *data, size_t len) err_code = *(uint32_t *)data; data += 4; - if (!screenshot_save(path, sh_data, sh_len)) { + if (!save_data_to_tmpfile(path, sh_data, sh_len)) { sendACKToHost(NMSG_GET_UI_SCREENSHOT, err_code, path, sizeof(path)); } else { @@ -241,6 +212,70 @@ static void processing_ui_screenshot(const void *data, size_t len) } } +static void send_uihv_data_msg(const char *path, size_t path_len) +{ + struct msg_data_t *msg; + + msg = malloc(MSG_DATA_HDR_LEN + path_len); + if (!msg) { + LOGE("Cannot alloc message: %d bytes\n", + MSG_DATA_HDR_LEN + path_len); + return; + } + + fill_data_msg_head(msg, NMSG_UI_HIERARCHY, 0, path_len); + memcpy(msg->payload, path, path_len); + + if (write_to_buf(msg) != 0) + LOGE("write to buf fail\n"); + free(msg); +} + +static void processing_uihv_data_common(const void *data, size_t len) +{ + char path[] = "/tmp/uihv_data_XXXXXX"; + + if (!save_data_to_tmpfile(path, data, len)) + send_uihv_data_msg(path, sizeof(path)); + else + LOGE("Cannot save uihv_data"); +} + +static void processing_uihv_data_error(const void *data, size_t len) +{ + enum ErrorCode err_code; + + if (len != 4) { + LOGE("Invalid message, len=%zu\n", len); + return; + } + + err_code = *(uint32_t*)data; + LOGE("uihv err_code=%d\n", err_code); + // TODO: system error + if (err_code == ERR_UNKNOWN) + restart_all(); +} + +static void processing_uihv_data(const void *data, size_t len) +{ + uint32_t err_flag; + + if (len < 4) { + LOGE("Message is very small\n"); + return; + } + + err_flag = *(uint32_t *)data; + data += 4; + len -= 4; + + if (err_flag) + processing_uihv_data_error(data, len); + else + processing_uihv_data_common(data, len); +} + static void* recvThread(void* data) { const size_t data_len = 16 * 1024 * 1024; @@ -360,45 +395,7 @@ static void* recvThread(void* data) continue; } else if (msg->type == APP_MSG_GET_UI_HIERARCHY_DATA) { - char *file_name = msg->data; - struct msg_data_t *msg_data; - const int len = msg->length; - - if (len == sizeof(uint32_t)) { - enum ErrorCode err_code = *(uint32_t*)msg->data; - - LOGE("APP_MSG_GET_UI_HIERARCHY_DATA error <%d>\n", err_code); - // TODO: system error - if (err_code == ERR_UNKNOWN) { - restart_all(); - continue; - } - } - - - msg_data = malloc(MSG_DATA_HDR_LEN + len); - if (!msg_data) { - LOGE("Cannot alloc message: %d bytes\n", MSG_DATA_HDR_LEN + len); - goto free_msg; - } - fill_data_msg_head(msg_data, NMSG_UI_HIERARCHY, 0, len); - memcpy(msg_data->payload, msg->data, msg->length); - - if (access(file_name, F_OK) != -1) { - LOGI("APP_MSG_GET_UI_HIERARCHY_DATA> File: <%s>\n", - file_name); - - if (chsmack(file_name) != 0) { - LOGE("chsmack failed\n"); - } - } else { - LOGE("APP_MSG_GET_UI_HIERARCHY> File not found <%s>\n", - file_name); - } - - if (write_to_buf(msg_data) != 0) - LOGE("write to buf fail\n"); - + processing_uihv_data(msg->data, msg->length); continue; } else if (msg->type == APP_MSG_GET_UI_SCREENSHOT) { processing_ui_screenshot(msg->data, msg->length); @@ -435,7 +432,6 @@ static void* recvThread(void* data) pass = 1; } -free_msg: free(msg); LOGI("thread finished %u:%u\n", target->pid, target->ppid); return NULL; diff --git a/ui_viewer/ui_viewer_lib.c b/ui_viewer/ui_viewer_lib.c index b6da368..c27ba10 100644 --- a/ui_viewer/ui_viewer_lib.c +++ b/ui_viewer/ui_viewer_lib.c @@ -140,7 +140,7 @@ static Eina_Bool ecore_animator_cb(__attribute__((unused)) void *data) if (an.get_hierarhy) { raise_app_window(); PRINTMSG("get hierarchy"); - print_log_ui_viewer_info_list((void *)&(an.rendering)); + print_log_ui_viewer_info_list(an.rendering); } if (an.obj_for_screenshot) { diff --git a/ui_viewer/ui_viewer_utils.c b/ui_viewer/ui_viewer_utils.c index 4fe7e65..761ee44 100644 --- a/ui_viewer/ui_viewer_utils.c +++ b/ui_viewer/ui_viewer_utils.c @@ -368,7 +368,21 @@ bool print_log_ui_viewer_hierarchy_error(void) return false; log.type = APP_MSG_GET_UI_HIERARCHY_DATA; - log_ptr = pack_int32(log.data, (uint32_t)err_code); + + /* format: + * +----------+----------+ + * | err_flag | err_code | + * +----------+----------+ + * | 4 | 4 | + * + */ + + /* pack err_flag */ + log_ptr = pack_int32(log.data, 1); + + /* pack err_code */ + log_ptr = pack_int32(log_ptr, (uint32_t)err_code); + log.length = log_ptr - log.data; len = sizeof(log.type) + sizeof(log.length) + log.length; @@ -379,32 +393,61 @@ bool print_log_ui_viewer_hierarchy_error(void) return (res == len); } -void* print_log_ui_viewer_info_list(void *prendering) +static int uihv_data_send_to_socket(const char *path) +{ + struct file_data *fdata; + void *buf, *p; + size_t buf_size; + + + fdata = file_data_create(path); + if (!fdata) + return -1; + + /* format: + * +----------+------+ + * | err_flag | data | + * +----------+------+ + * | 4 | ... | + * + */ + buf_size = 4 + fdata->len; + buf = malloc(buf_size); + + /* pack err_flag */ + p = pack_int32(buf, 0); + + /* pack data */ + memcpy(p, fdata->data, fdata->len); + + /* send data to manager */ + msg_send(APP_MSG_GET_UI_HIERARCHY_DATA, buf, buf_size); + file_data_free(fdata); + + return 0; +} + +void print_log_ui_viewer_info_list(Eina_Bool rendering) { char path[] = TMP_DIR"/swap_ui_viewer_XXXXXX"; int fd; - log_t log; - ssize_t res, len; - char *log_ptr; struct timeval start_tv, finish_tv, tv; - Eina_Bool rendering, cancelled = EINA_FALSE; + Eina_Bool cancelled = EINA_FALSE; if (gTraceInfo.socket.daemonSock == -1) - return NULL; + return; if (get_hierarchy_status() == HIERARCHY_RUNNING) - return NULL; + return; set_hierarchy_status(HIERARCHY_RUNNING); - rendering = *(Eina_Bool*)prendering; - fd = mkstemp(path); if (fd == -1) { set_hierarchy_status(HIERARCHY_NOT_RUNNING); PRINTERR("Cannot make temp file, err=%d templ='%s'", errno, path); - return NULL; + return; } gettimeofday(&start_tv, NULL); @@ -417,26 +460,12 @@ void* print_log_ui_viewer_info_list(void *prendering) close(fd); if (!cancelled) { - log.type = APP_MSG_GET_UI_HIERARCHY_DATA; - log_ptr = pack_string(log.data, path); - log.length = log_ptr - log.data; - len = sizeof(log.type) + sizeof(log.length) + log.length; - - pthread_mutex_lock(&(gTraceInfo.socket.sockMutex)); - res = send(gTraceInfo.socket.daemonSock, &log, len, MSG_NOSIGNAL); - pthread_mutex_unlock(&(gTraceInfo.socket.sockMutex)); - - ui_viewer_log("getting hierarchy filename: %s\n", - log.data); - - if (res != len) - ui_viewer_log("can't send hierarchy info\n"); - set_hierarchy_status(HIERARCHY_NOT_RUNNING); - } else { - remove(path); + if (uihv_data_send_to_socket(path)) + PRINTERR("Cannot send uihv_data"); } + remove(path); - return NULL; + set_hierarchy_status(HIERARCHY_NOT_RUNNING); } static int screenshot_send_to_socket(enum ErrorCode err, const char *path) diff --git a/ui_viewer/ui_viewer_utils.h b/ui_viewer/ui_viewer_utils.h index 3ea5148..e5a28a9 100644 --- a/ui_viewer/ui_viewer_utils.h +++ b/ui_viewer/ui_viewer_utils.h @@ -78,7 +78,7 @@ char * _strncpy(char *dest, const char *src, size_t n); bool print_log_fmt(int msgType, const char *func_name, int line, ...); bool print_log_str(int msgType, char *st); bool print_log_ui_viewer_hierarchy_status(enum ErrorCode *err_code); -void* print_log_ui_viewer_info_list(void *prendering); +void print_log_ui_viewer_info_list(Eina_Bool rendering); bool print_log_ui_viewer_hierarchy_error(void); bool print_log_ui_obj_screenshot(Evas_Object *obj); bool printLog(log_t* log, int msgType); -- 2.7.4