From 1b28c70ac87cc1a1b599f39bef0a5f95fd4ba5ab Mon Sep 17 00:00:00 2001 From: Anastasia Lyupa Date: Mon, 21 Oct 2013 19:31:31 +0400 Subject: [PATCH] [FIX] epoll_ctl error, double stopping - don't call stop_all at the end if it was successfully called before or if start was unsuccessful - epoll_add_input_events: no error if fd exists Change-Id: I86119301519e6c2a891323a7db93a070b31d01ab Signed-off-by: Anastasia Lyupa --- daemon/da_protocol.c | 60 ++++++++++++++++++++++++++++++++++++++-------------- daemon/da_protocol.h | 2 ++ daemon/daemon.c | 14 ++++++------ 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/daemon/da_protocol.c b/daemon/da_protocol.c index 66e7d96..a403ba0 100644 --- a/daemon/da_protocol.c +++ b/daemon/da_protocol.c @@ -543,6 +543,21 @@ static void reset_conf(struct conf_t *conf) memset(conf, 0, sizeof(*conf)); } +static void running_status_on(struct prof_session_t *prof_session) +{ + prof_session->running_status = 1; +} + +static void running_status_off(struct prof_session_t *prof_session) +{ + prof_session->running_status = 0; +} + +int check_running_status(struct prof_session_t *prof_session) +{ + return prof_session->running_status; +} + static void reset_app_inst(struct user_space_inst_t *us_inst) { free_data_list((struct data_list_t **)&us_inst->app_inst_list); @@ -586,6 +601,7 @@ static void reset_prof_session(struct prof_session_t *prof_session) reset_conf(&prof_session->conf); reset_user_space_inst(&prof_session->user_space_inst); reset_replay_event_seq(&prof_session->replay_event_seq); + running_status_off(prof_session); } static struct msg_t *gen_binary_info_reply(struct app_info_t *app_info) @@ -780,29 +796,40 @@ struct msg_t *gen_stop_msg(void) enum ErrorCode stop_all(void) { - LOGI("entry\n"); enum ErrorCode error_code = ERR_NO; - struct msg_t *msg = gen_stop_msg(); + struct msg_t *msg; - terminate_all(); - stop_profiling(); + LOGI("entry\n"); - if (msg == NULL) { - LOGE("cannot generate stop message\n"); - return ERR_UNKNOWN; - } else { - if (ioctl_send_msg(msg) != 0) { - LOGE("ioctl send filed\n"); + // stop all only if it has not been called yet + if (check_running_status(&prof_session)) { + msg = gen_stop_msg(); + terminate_all(); + stop_profiling(); + + if (msg == NULL) { + LOGE("cannot generate stop message\n"); error_code = ERR_UNKNOWN; + goto stop_all_exit; + } else { + if (ioctl_send_msg(msg) != 0) { + LOGE("ioctl send failed\n"); + error_code = ERR_UNKNOWN; + free_msg(msg); + goto stop_all_exit; + } + free_msg(msg); } - free_msg(msg); - } - //we reset only app inst no lib no confing reset - reset_app_inst(&prof_session.user_space_inst); - stop_transfer(); + // we reset only app inst no lib no confing reset + reset_app_inst(&prof_session.user_space_inst); + stop_transfer(); + running_status_off(&prof_session); + } else + LOGI("already stopped\n"); - LOGI("finished\n"); +stop_all_exit: + LOGI("finished: ret = %d\n", error_code); return error_code; } struct binary_ack { @@ -976,6 +1003,7 @@ static int process_msg_start(struct msg_buf_t *msg_control) } err_code = ERR_NO; + running_status_on(&prof_session); send_ack: get_serialized_time(&serialized_time); sendACKToHost(NMSG_START, err_code, (void *)&serialized_time, diff --git a/daemon/da_protocol.h b/daemon/da_protocol.h index 3c77939..d4d92fb 100644 --- a/daemon/da_protocol.h +++ b/daemon/da_protocol.h @@ -251,6 +251,7 @@ struct prof_session_t { struct conf_t conf; struct user_space_inst_t user_space_inst; struct replay_event_seq_t replay_event_seq; + unsigned running_status:1; // to stop properly (1 - it is running, 0 - no) }; int parseHostMessage(struct msg_t *log, char *msg); @@ -378,6 +379,7 @@ enum ErrorCode stop_all(void); void reset_msg(struct msg_t *msg); void reset_replay_event_seq(struct replay_event_seq_t *res); void reset_system_info(struct system_info_t *sys); +int check_running_status(struct prof_session_t *prof_session); extern struct prof_session_t prof_session; diff --git a/daemon/daemon.c b/daemon/daemon.c index 8cdbfbd..3607c3a 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -837,8 +837,9 @@ static void epoll_add_input_events() if (g_key_dev[i].fd >= 0) { ev.data.fd = g_key_dev[i].fd; if (epoll_ctl(manager.efd, - EPOLL_CTL_ADD, g_key_dev[i].fd, &ev) < 0) - LOGE("keyboard device file epoll_ctl error\n"); + EPOLL_CTL_ADD, g_key_dev[i].fd, &ev) < 0 + && errno != EEXIST) + LOGE("keyboard device file epoll_ctl error: %s\n", strerror(errno)); } } @@ -848,8 +849,9 @@ static void epoll_add_input_events() ev.data.fd = g_touch_dev[i].fd; if (epoll_ctl(manager.efd, EPOLL_CTL_ADD, - g_touch_dev[i].fd, &ev) < 0) - LOGE("touch device file epoll_ctl error\n"); + g_touch_dev[i].fd, &ev) < 0 + && errno != EEXIST) + LOGE("touch device file epoll_ctl error: %s\n", strerror(errno)); } } } @@ -863,14 +865,14 @@ static void epoll_del_input_events() if (g_key_dev[i].fd >= 0) if (epoll_ctl(manager.efd, EPOLL_CTL_DEL, g_key_dev[i].fd, NULL) < 0) - LOGE("keyboard device file epoll_ctl error\n"); + LOGE("keyboard device file epoll_ctl error: %s\n", strerror(errno)); for (i = 0; g_touch_dev[i].fd != ARRAY_END; i++) if (g_touch_dev[i].fd >= 0) if (epoll_ctl(manager.efd, EPOLL_CTL_DEL, g_touch_dev[i].fd, NULL) < 0) - LOGE("touch device file epoll_ctl error\n"); + LOGE("touch device file epoll_ctl error: %s\n", strerror(errno)); } static bool initialize_epoll_events(void) -- 2.7.4