Fix launch waiting logic 50/208750/6
authorhyunho <hhstark.kang@samsung.com>
Fri, 28 Jun 2019 02:21:44 +0000 (11:21 +0900)
committerhyunho <hhstark.kang@samsung.com>
Fri, 28 Jun 2019 07:03:46 +0000 (16:03 +0900)
Currently, if an widget application die while viewer is waiting for
the widget app's response, restart logic for
terminated instance would be ignored.
This patch enables viewer to stop waiting for launching and
insert terminated instance to the restart queue again.

Change-Id: I535dac35e3e4d39e326b259ad49aa4ce0121fed8
Signed-off-by: hyunho <hhstark.kang@samsung.com>
widget_viewer_evas/src/widget_viewer_evas.c

index 78cd1e3cb2f2c80038078451558808f34daa2a9a..6acf5765dbe7b6401ae1374ba1b6dd0ea20572da 100644 (file)
 
 #define WIDGET_PRIVILEGE "http://tizen.org/privilege/widget.viewer"
 #define WIDGET_LAUNCH_TIMEOUT  7000
-#define MAX_NO_RESPONSE_COUNT 2
+#define MAX_NO_RESPONSE_COUNT 5
 
 /*!
  * \note
@@ -741,6 +741,31 @@ static void __launch_instance()
        }
 }
 
+static int __clear_launch_waiting(char *instance_id)
+{
+       struct widget_info *info;
+       int ret;
+
+       LOGW("Clear launch waiting !! %s", instance_id);
+       info = g_hash_table_lookup(s_info.widget_table, instance_id);
+       if (!info)
+               LOGE("Unable to find a proper instance");/* LCOV_EXCL_LINE */
+
+       __remove_launch_info(instance_id);
+       if (info && info->no_response_count < MAX_NO_RESPONSE_COUNT) {
+               ret = aul_terminate_pid(info->pid);
+               if (ret != AUL_R_OK) {
+                       LOGW("Fail to term widget(%d) pid(%d) !!",
+                               ret, info->pid);
+                       return 0;
+               }
+               info->no_response_count++;
+               LOGW("Widget is not responding(%d) !! %s(%d)",
+                               info->no_response_count, instance_id, info->pid);
+       }
+       return 0;
+}
+
 /* LCOV_EXCL_START */
 static int __restart_terminated_widget(const char *widget_id)
 {
@@ -748,19 +773,22 @@ static int __restart_terminated_widget(const char *widget_id)
        gpointer key, value;
        struct widget_info *widget_instance_info;
        int target_pid = 0;
+       char *instance_id;
+       int pid;
+       char *id;
 
        g_hash_table_iter_init(&iter, s_info.widget_table);
        while (g_hash_table_iter_next(&iter, &key, &value)) {
                widget_instance_info = (struct widget_info *)value;
-               if (strcmp(widget_instance_info->widget_id, widget_id) == 0) {
-                       if (widget_instance_info->restart) {
-                               target_pid = widget_instance_info->pid;
-                               LOGW("Prepare restart (%s)(%d)", widget_id, target_pid);
-                               break;
-                       } else {
-                               LOGW("There is no restart event for (%s)",
-                                               widget_instance_info->instance_id);
-                       }
+               if (strcmp(widget_instance_info->widget_id, widget_id) != 0)
+                       continue;
+               if (widget_instance_info->restart) {
+                       target_pid = widget_instance_info->pid;
+                       LOGW("Prepare restart (%s)(%d)", widget_id, target_pid);
+                       break;
+               } else {
+                       LOGW("There is no restart event for (%s)",
+                                       widget_instance_info->instance_id);
                }
        }
 
@@ -772,17 +800,26 @@ static int __restart_terminated_widget(const char *widget_id)
        if (widget_instance_info->no_response_count >= MAX_NO_RESPONSE_COUNT) {
                LOGE("WIDGET IS NOT RESPONDING(%s) STOP AUTO RESTART", widget_id);
                widget_instance_info->no_response_count = 0;
+               aul_widget_write_log(LOG_TAG, "[%s:%d]  not responding (%s)",
+                       __FUNCTION__, __LINE__, widget_id);
                return 0;
        }
 
        g_hash_table_iter_init(&iter, s_info.widget_table);
        while (g_hash_table_iter_next(&iter, &key, &value)) {
                widget_instance_info = (struct widget_info *)value;
-               if (widget_instance_info->restart &&
-                               widget_instance_info->pid == target_pid &&
-                               (strcmp(widget_instance_info->widget_id, widget_id) == 0)) {
-                       __add_launch_list(widget_instance_info->instance_id);
+               pid = widget_instance_info->pid;
+               instance_id = widget_instance_info->instance_id;
+               id = widget_instance_info->widget_id;
+               if (!(widget_instance_info->restart && pid == target_pid &&
+                       (strcmp(id, widget_id) == 0)))
+                       continue;
+               if (s_info.launching_instance_id &&
+                       strcmp(s_info.launching_instance_id, instance_id) == 0) {
+                       __remove_launch_timer();
+                       __clear_launch_waiting(instance_id);
                }
+               __add_launch_list(instance_id);
        }
        if (s_info.launch_timer == 0)
                __launch_instance();
@@ -794,21 +831,9 @@ static int __restart_terminated_widget(const char *widget_id)
 static gboolean __launch_timeout_cb(gpointer user_data)
 {
        char *instance_id = (char *)user_data;
-       struct widget_info *info;
 
        LOGW("Timeout called !! %s", instance_id);
-       info = g_hash_table_lookup(s_info.widget_table, instance_id);
-       if (!info)
-               LOGE("Unable to find a proper instance");/* LCOV_EXCL_LINE */
-
-       __remove_launch_info(instance_id);
-       if (info && info->no_response_count < MAX_NO_RESPONSE_COUNT) {
-               info->no_response_count++;
-               LOGW("Widget is not responding(%d) !! %s(%d)",
-                               info->no_response_count, instance_id, info->pid);
-
-               aul_terminate_pid(info->pid);
-       }
+       __clear_launch_waiting(instance_id);
        __launch_instance();
        return G_SOURCE_REMOVE;
 }