From 16feac74a4f10e4b6b49862d6f22f0210a0ecc16 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Tue, 12 Jun 2018 10:04:26 +0900 Subject: [PATCH] Change TEP mount check function In a child process, the usable gdbus threads cannot be found. This patch uses libdbus instead of gdbus. Change-Id: Id8df46a15984c3a38c0725bebd57968fbb147112 Signed-off-by: Hwankyu Jhun --- CMakeLists.txt | 3 ++ packaging/launchpad.spec | 1 + src/launchpad_common.c | 92 +++++++++++++++++++++++++++++++----------------- src/launchpad_signal.c | 4 +++ 4 files changed, 67 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 709a6e9..782f03d 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ PKG_CHECK_MODULES(${this_target_pool} REQUIRED vconf libtzplatform-config libcap + dbus-1 ) FOREACH(flag ${${this_target_pool}_CFLAGS}) @@ -34,6 +35,7 @@ PKG_CHECK_MODULES(${this_target_loader} REQUIRED buxton2 libsystemd gio-2.0 + dbus-1 ) FOREACH(flag ${${this_target_loader}_CFLAGS}) @@ -47,6 +49,7 @@ PKG_CHECK_MODULES(${this_target_lib} REQUIRED security-manager libtzplatform-config tanchor + dbus-1 ) FOREACH(flag ${${this_target_lib}_CFLAGS}) diff --git a/packaging/launchpad.spec b/packaging/launchpad.spec index fcb64e7..435beb3 100644 --- a/packaging/launchpad.spec +++ b/packaging/launchpad.spec @@ -24,6 +24,7 @@ BuildRequires: pkgconfig(ttrace) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(libcap) BuildRequires: pkgconfig(tanchor) +BuildRequires: pkgconfig(dbus-1) Requires(post): /sbin/ldconfig Requires(post): /usr/bin/systemctl diff --git a/src/launchpad_common.c b/src/launchpad_common.c index 7888427..79adfc6 100644 --- a/src/launchpad_common.c +++ b/src/launchpad_common.c @@ -38,7 +38,7 @@ #include #include #include -#include +#include #include "launchpad_common.h" #include "key.h" @@ -930,59 +930,85 @@ int _set_priority(int prio) static int __is_tep_mount_done(const char *tep_path) { - GError *err = NULL; - GDBusConnection *conn; - GDBusMessage *msg = NULL; - GDBusMessage *reply = NULL; - GVariant *body; - int ret = -1; - - conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + DBusError err; + DBusConnection *conn; + DBusMessage *msg = NULL; + DBusMessageIter args; + DBusPendingCall *pending = NULL; + dbus_bool_t r; + dbus_int32_t i; + int ret = 0; + + dbus_error_init(&err); + conn = dbus_bus_get_private(DBUS_BUS_SYSTEM, &err); if (!conn) { - _E("g_bus_get_sync() is failed. %s", err->message); + _E("Failed to connect to D-Bus Daemon"); + ret = -1; goto end; } - msg = g_dbus_message_new_method_call(TEP_BUS_NAME, + msg = dbus_message_new_method_call(TEP_BUS_NAME, TEP_OBJECT_PATH, TEP_INTERFACE_NAME, TEP_IS_MOUNTED_METHOD); if (!msg) { - _E("g_dbus_message_new_method_call() is failed. %s", - err->message); + _E("Message is NULL"); + ret = -1; goto end; } - g_dbus_message_set_body(msg, g_variant_new("(s)", tep_path)); - - reply = g_dbus_connection_send_message_with_reply_sync(conn, - msg, - G_DBUS_SEND_MESSAGE_FLAGS_NONE, - 500, - NULL, - NULL, - &err); - if (!reply) { - _E("Failed to send message with reply. %s", err->message); + + dbus_message_iter_init_append(msg, &args); + r = dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &tep_path); + if (!r) { + _E("Out of memory"); + ret = -1; + goto end; + } + + r = dbus_connection_send_with_reply(conn, msg, &pending, 500); + if (!r || !pending) { + _E("Failed to send message"); + ret = -1; goto end; } - body = g_dbus_message_get_body(reply); - if (!body) { - _E("Failed to get message body."); + dbus_connection_flush(conn); + dbus_message_unref(msg); + + dbus_pending_call_block(pending); + msg = dbus_pending_call_steal_reply(pending); + if (!msg) { + _E("Failed to get reply message"); + ret = -1; goto end; } - g_variant_get(body, "(i)", &ret); + dbus_pending_call_unref(pending); + if (!dbus_message_iter_init(msg, &args)) { + _E("Message has no arguments!"); + ret = -1; + } else if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_INT32) { + _E("Argument is not integer! type(%d)", + dbus_message_iter_get_arg_type(&args)); + ret = -1; + } else { + dbus_message_iter_get_basic(&args, &i); + ret = i; + } + + _D("Result: %d", ret); end: if (msg) - g_object_unref(msg); - if (reply) - g_object_unref(reply); + dbus_message_unref(msg); + if (conn) - g_object_unref(conn); + dbus_connection_close(conn); - g_clear_error(&err); + if (dbus_error_is_set(&err)) { + _E("D-Bus error(%s)", err.message); + dbus_error_free(&err); + } return ret; } diff --git a/src/launchpad_signal.c b/src/launchpad_signal.c index 1742dcf..deb581c 100644 --- a/src/launchpad_signal.c +++ b/src/launchpad_signal.c @@ -362,4 +362,8 @@ void _signal_fini(void) for (i = 0; i < _NSIG; i++) signal(i, SIG_DFL); #endif + if (bus) { + g_object_unref(bus); + bus = NULL; + } } -- 2.7.4