[FIX] epoll_ctl error, double stopping
authorAnastasia Lyupa <a.lyupa@samsung.com>
Mon, 21 Oct 2013 15:31:31 +0000 (19:31 +0400)
committerAnastasia Lyupa <a.lyupa@samsung.com>
Wed, 23 Oct 2013 15:03:14 +0000 (19:03 +0400)
- 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 <a.lyupa@samsung.com>
daemon/da_protocol.c
daemon/da_protocol.h
daemon/daemon.c

index 66e7d96a77de67d91c4d43ac8c714e1267c4920b..a403ba0bcdf64a3d9f8a4d7acd2949311c66bac4 100644 (file)
@@ -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,
index 3c779392b92f15e14f9c6789a24930e6f8cbcb30..d4d92fbf0f5bce71031f48b628724f3a2a35e581 100644 (file)
@@ -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;
 
index 8cdbfbd17f7fdbf43bc1dd9f87e50708a2c909c9..3607c3a358597a03aaecccc46c5b3afb40a75244 100644 (file)
@@ -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)