From da85f4874062f0c721b8f3a62df633adac52e931 Mon Sep 17 00:00:00 2001 From: jongmyeongko Date: Mon, 24 Oct 2016 10:56:16 +0900 Subject: [PATCH] make app2sd more robust on some failure cases. - ensure a given waiting time before app2sd-server is terminated - apply retrial logic for client api Change-Id: I733bf20313f72ccd7350aeea5ef35c9395be2527 Signed-off-by: jongmyeongko --- plugin/app2sd/src/app2sd_client_interface.c | 62 ++++++++++++++++++----------- plugin/app2sd/src/app2sd_server.c | 5 ++- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/plugin/app2sd/src/app2sd_client_interface.c b/plugin/app2sd/src/app2sd_client_interface.c index 427d58e..0e34756 100644 --- a/plugin/app2sd/src/app2sd_client_interface.c +++ b/plugin/app2sd/src/app2sd_client_interface.c @@ -32,6 +32,9 @@ #include "app2sd_client_interface.h" #include "app2ext_utils.h" +#define CONNECTION_RETRY_MAX 5 +#define CONNECTION_WAIT_USEC (1000000 / 2) /* 0.5 sec */ + static int app2sd_gdbus_shared_connection(GDBusConnection **connection) { GError *error = NULL; @@ -58,6 +61,7 @@ static int __app2sd_call_server_method(const gchar *method_name, { int ret = APP2EXT_SUCCESS; int result = 0; + int retry_cnt = 0; GDBusConnection *conn = NULL; GDBusProxy *proxy = NULL; GError *error = NULL; @@ -71,34 +75,44 @@ static int __app2sd_call_server_method(const gchar *method_name, } /* method call */ - proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, - APP2SD_BUS_NAME, APP2SD_OBJECT_PATH, APP2SD_INTERFACE_NAME, - NULL, &error); - if (proxy == NULL) { - _E("failed to create new proxy, error(%s)", error->message); - g_error_free(error); - ret = APP2EXT_ERROR_DBUS_FAILED; - goto out; - } + do { + proxy = g_dbus_proxy_new_sync(conn, + G_DBUS_PROXY_FLAGS_NONE, NULL, + APP2SD_BUS_NAME, APP2SD_OBJECT_PATH, + APP2SD_INTERFACE_NAME, + NULL, &error); + if (proxy == NULL) { + _E("failed to create new proxy, error(%s)", + error->message); + g_error_free(error); + ret = APP2EXT_ERROR_DBUS_FAILED; + retry_cnt++; + usleep(CONNECTION_WAIT_USEC); + continue; + } - value = g_dbus_proxy_call_sync(proxy, method_name, param, - G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, &error); - if (error != NULL) { - _E("proxy call sync error(%s)", error->message); - g_error_free(error); - ret = APP2EXT_ERROR_DBUS_FAILED; - goto out; - } + value = g_dbus_proxy_call_sync(proxy, method_name, param, + G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, &error); + g_object_unref(proxy); + if (error != NULL) { + _E("proxy call sync error(%s)", error->message); + g_error_free(error); + ret = APP2EXT_ERROR_DBUS_FAILED; + retry_cnt++; + usleep(CONNECTION_WAIT_USEC); + continue; + } + + g_variant_get(value, "(i)", &result); + g_variant_unref(value); - g_variant_get(value, "(i)", &result); - g_variant_unref(value); + _D("result(%d)", result); + if (result) + ret = result; - _D("result(%d)", result); - if (result) - ret = result; + break; + } while (retry_cnt <= CONNECTION_RETRY_MAX); -out: if (conn) g_object_unref(conn); diff --git a/plugin/app2sd/src/app2sd_server.c b/plugin/app2sd/src/app2sd_server.c index 04afa1e..cd863af 100644 --- a/plugin/app2sd/src/app2sd_server.c +++ b/plugin/app2sd/src/app2sd_server.c @@ -24,6 +24,7 @@ #define APPFW_UID 301 int processing_busy_cnt; +guint source_id; GMainLoop *app2sd_mainloop = NULL; @@ -766,7 +767,9 @@ static void handle_method_call(GDBusConnection *connection, parameters, invocation, sender_uid); } - g_timeout_add_seconds(5, __exit_app2sd_server, NULL); + if (source_id) + g_source_remove(source_id); + source_id = g_timeout_add_seconds(5, __exit_app2sd_server, NULL); processing_busy_cnt--; } -- 2.7.4