From d86bbf921b231e3c24e7e4ac5c9099901f4191fa Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Wed, 19 Apr 2017 14:59:09 +0300 Subject: [PATCH] Increase size of internel messages (probe - manager) Change-Id: I12dadbd4c564e3aadda42e0d4e9a1abc755007f9 Signed-off-by: Vyacheslav Cherkashin --- daemon/da_protocol.c | 4 +-- daemon/da_protocol.h | 2 +- daemon/target.c | 4 +-- daemon/target.h | 3 +- daemon/threads.c | 78 +++++++++++++++++++++++++++++----------------------- 5 files changed, 51 insertions(+), 40 deletions(-) diff --git a/daemon/da_protocol.c b/daemon/da_protocol.c index d811c03..196ebca 100644 --- a/daemon/da_protocol.c +++ b/daemon/da_protocol.c @@ -1098,7 +1098,7 @@ int send_msg_to_sock(int sock, struct msg_target_t *msg) return err; } -int recv_msg_from_sock(int sock, struct msg_target_t *msg) +int recv_msg_from_sock(int sock, struct msg_target_t *msg, size_t data_len) { ssize_t ret; @@ -1128,7 +1128,7 @@ int recv_msg_from_sock(int sock, struct msg_target_t *msg) } if (msg->length > 0) { - if (msg->length >= TARGER_MSG_MAX_LEN) + if (msg->length >= data_len) return 1; ret = recv(sock, msg->data, msg->length, MSG_WAITALL); diff --git a/daemon/da_protocol.h b/daemon/da_protocol.h index b464dbc..368bab9 100644 --- a/daemon/da_protocol.h +++ b/daemon/da_protocol.h @@ -494,7 +494,7 @@ int check_running_status(const struct prof_session_t *prof_session); extern struct prof_session_t prof_session; int send_msg_to_sock(int sock, struct msg_target_t *msg); -int recv_msg_from_sock(int sock, struct msg_target_t *msg); +int recv_msg_from_sock(int sock, struct msg_target_t *msg, size_t data_len); //debugs void print_replay_event(struct replay_event_t *ev, uint32_t num, char *tab); diff --git a/daemon/target.c b/daemon/target.c index bf8a287..93a7244 100644 --- a/daemon/target.c +++ b/daemon/target.c @@ -112,9 +112,9 @@ int target_send_msg(struct target *t, struct msg_target_t *msg) return send_msg_to_sock(t->socket, msg); } -int target_recv_msg(struct target *t, struct msg_target_t *msg) +int target_recv_msg(struct target *t, struct msg_target_t *msg, size_t data_len) { - return recv_msg_from_sock(t->socket, msg); + return recv_msg_from_sock(t->socket, msg, data_len); } int target_start(struct target *t, void *(*start_routine) (void *)) diff --git a/daemon/target.h b/daemon/target.h index 02449c7..e6c812e 100644 --- a/daemon/target.h +++ b/daemon/target.h @@ -70,7 +70,8 @@ void target_dtor(struct target *t); int target_accept(struct target *t, int sockfd); int target_send_msg(struct target *t, struct msg_target_t *msg); -int target_recv_msg(struct target *t, struct msg_target_t *msg); +int target_recv_msg(struct target *t, struct msg_target_t *msg, + size_t data_len); int target_start(struct target *t, void *(*start_routine) (void *)); int target_wait(struct target *t); diff --git a/daemon/threads.c b/daemon/threads.c index 61cbcc9..a1924ae 100644 --- a/daemon/threads.c +++ b/daemon/threads.c @@ -83,26 +83,34 @@ static int chsmack(const char *filename) } static void* recvThread(void* data) { + const size_t data_len = 16 * 1024 * 1024; struct target *target = data; int pass = 0; uint64_t event; - struct msg_target_t log; + struct _msg_target_t *msg; int err; + msg = malloc(sizeof(*msg) + data_len); + if (!msg) { + LOGE("Out of memory\n"); + return NULL; + } + // initialize target variable target->allocmem = 0; for (;;) { - err = target_recv_msg(target, &log); - if ((err != 0) || (log.length >= TARGER_MSG_MAX_LEN)) { + err = target_recv_msg(target, (struct msg_target_t *)msg, + data_len); + if (err) { /* disconnect */ event = EVENT_STOP; write(target->event_fd, &event, sizeof(event)); break; } - if (IS_PROBE_MSG(log.type)) { - struct msg_data_t *msg_data = (struct msg_data_t *)&log; + if (IS_PROBE_MSG(msg->type)) { + struct msg_data_t *msg_data = (struct msg_data_t *)msg; if (msg_data->len > MAX_RAW_MESSAGE_SIZE) { LOGE("Raw message is too big = %d\n", @@ -116,24 +124,24 @@ static void* recvThread(void* data) continue; } - if (log.type == APP_MSG_STOP) { + if (msg->type == APP_MSG_STOP) { LOGI("APP_MSG_STOP arrived\n"); pthread_cond_broadcast(&target->target_cv); continue; } - log.data[log.length] = '\0'; - if (log.type == APP_MSG_ALLOC) { - target->allocmem = str_to_int64(log.data); + msg->data[msg->length] = '\0'; + if (msg->type == APP_MSG_ALLOC) { + target->allocmem = str_to_int64(msg->data); continue; // don't send to host - } else if (log.type == APP_MSG_PID) { - LOGI("APP_MSG_PID arrived (pid ppid): %s\n", log.data); + } else if (msg->type == APP_MSG_PID) { + LOGI("APP_MSG_PID arrived (pid ppid): %s\n", msg->data); /* only when first APP_MSG_PID is arrived */ if (target_get_pid(target) == UNKNOWN_PID) { int n; pid_t pid, ppid; - n = sscanf(log.data, "%d %d", &pid, &ppid); + n = sscanf(msg->data, "%d %d", &pid, &ppid); if (n != 2) { /** @@ -156,7 +164,7 @@ static void* recvThread(void* data) write(target->event_fd, &event, sizeof(uint64_t)); } continue; // don't send to host - } else if (log.type == APP_MSG_TERMINATE) { + } else if (msg->type == APP_MSG_TERMINATE) { LOGI("APP_MSG_TERMINATE arrived: pid[%d]\n", target_get_pid(target)); @@ -166,21 +174,21 @@ static void* recvThread(void* data) sizeof(uint64_t)); break; - } else if (log.type == APP_MSG_MSG) { + } else if (msg->type == APP_MSG_MSG) { // don't send to host - LOGI("EXTRA '%s'\n", log.data); + LOGI("EXTRA '%s'\n", msg->data); continue; } else if (log.type == APP_MSG_ERROR) { // don't send to host - LOGE("EXTRA '%s'\n", log.data); + LOGE("EXTRA '%s'\n", msg->data); continue; } else if (log.type == APP_MSG_WARNING) { // don't send to host - LOGW("EXTRA '%s'\n", log.data); + LOGW("EXTRA '%s'\n", msg->data); continue; } else if (log.type == APP_MSG_IMAGE) { /* need chsmak */ - void *p = log.data; + void *p = msg->data; char *file_name = p; if (access(file_name, F_OK) != -1) { @@ -197,7 +205,7 @@ static void* recvThread(void* data) struct msg_data_t *msg_data = (struct msg_data_t *)(p); /* check packed size */ - if (log.length != strnlen(file_name, PATH_MAX) + 1 + + if (msg->length != strnlen(file_name, PATH_MAX) + 1 + sizeof(*msg_data) + msg_data->len) { LOGE("Bad packed message\n"); continue; @@ -211,23 +219,23 @@ static void* recvThread(void* data) continue; - } else if (log.type == APP_MSG_GET_UI_HIERARCHY) { + } else if (msg->type == APP_MSG_GET_UI_HIERARCHY) { enum ErrorCode err_code = ERR_UNKNOWN; - if (log.length == sizeof(uint32_t)) { - err_code = *(uint32_t*)log.data; + if (msg->length == sizeof(uint32_t)) { + err_code = *(uint32_t*)msg->data; } sendACKToHost(NMSG_GET_UI_HIERARCHY, err_code, 0, 0); continue; - } else if (log.type == APP_MSG_GET_UI_HIERARCHY_DATA) { - char *file_name = log.data; + } else if (msg->type == APP_MSG_GET_UI_HIERARCHY_DATA) { + char *file_name = msg->data; struct msg_data_t *msg_data; - const int len = log.length; + const int len = msg->length; if (len == sizeof(uint32_t)) { - enum ErrorCode err_code = *(uint32_t*)log.data; + enum ErrorCode err_code = *(uint32_t*)msg->data; LOGE("APP_MSG_GET_UI_HIERARCHY_DATA error <%d>\n", err_code); // TODO: system error @@ -241,10 +249,10 @@ static void* recvThread(void* data) msg_data = malloc(MSG_DATA_HDR_LEN + len); if (!msg_data) { LOGE("Cannot alloc message: %d bytes\n", MSG_DATA_HDR_LEN + len); - return NULL; + goto free_msg; } fill_data_msg_head(msg_data, NMSG_UI_HIERARCHY, 0, len); - memcpy(msg_data->payload, log.data, log.length); + 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", @@ -262,12 +270,12 @@ static void* recvThread(void* data) LOGE("write to buf fail\n"); continue; - } else if (log.type == APP_MSG_GET_UI_SCREENSHOT) { + } else if (msg->type == APP_MSG_GET_UI_SCREENSHOT) { enum ErrorCode err_code = ERR_UNKNOWN; - char *payload = log.data; - int payload_size = log.length; + char *payload = msg->data; + int payload_size = msg->length; - LOGI("APP_MSG_GET_UI_SCREENSHOT> log length = %d\n", log.length); + LOGI("APP_MSG_GET_UI_SCREENSHOT> log length = %d\n", msg->length); if (payload_size >= sizeof(uint32_t)) { char *file_name; @@ -288,7 +296,7 @@ static void* recvThread(void* data) } #ifdef PRINT_TARGET_LOG else if (log.type == APP_MSG_LOG) { - switch(log.data[0]) + switch(msg->data[0]) { case '2': // UI control creation log case '3': // UI event log @@ -302,7 +310,7 @@ static void* recvThread(void* data) } } else { /* not APP_MSG_LOG and not APP_MSG_IMAGE */ - LOGI("Extra MSG TYPE (%d|%d|%s)\n", log.type, log.length, log.data); + LOGI("Extra MSG TYPE (%d|%d|%s)\n", msg->type, msg->length, msg->data); } #endif @@ -317,6 +325,8 @@ static void* recvThread(void* data) pass = 1; } +free_msg: + free(msg); LOGI("thread finished %u:%u\n", target->pid, target->ppid); return NULL; } -- 2.7.4