From: Jinhyung Jo Date: Tue, 10 Oct 2017 09:06:20 +0000 (+0900) Subject: dbus: change from dbus-glib API to GDBus API X-Git-Tag: accepted/tizen/unified/20171012.191841~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fbb3887c013b52229f5310006ec3df850299062a;p=sdk%2Ftarget%2Fsdbd.git dbus: change from dbus-glib API to GDBus API As mentioned in the URL below: https://dbus.freedesktop.org/doc/dbus-glib/ dbus-glib is a deprecated API for use of D-Bus from GLib applications. Do not use it in new code. Since version 2.26, GLib's accompanying GIO library provides a high-level API for D-Bus, "GDBus", based on an independent reimplementation of the D-Bus protocol. The maintainers of D-Bus recommend that GLib applications should use GDBus instead of dbus-glib. Change-Id: I5754e0c40fdb246e0a29766ae795e6dcaebc07e4 Signed-off-by: Jinhyung Jo --- diff --git a/CMakeLists.txt b/CMakeLists.txt index e06a26d..3bc41e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,8 +70,7 @@ pkg_check_modules(pkgs REQUIRED capi-system-info vconf glib-2.0 - dbus-1 - dbus-glib-1 + gio-2.0 dlog ) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 00815b0..372ceb7 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -23,8 +23,7 @@ BuildRequires: pkgconfig(libsmack) BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(dbus-1) -BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(dlog) Requires: dbus Provides: %{name}-profile_common = %{version}-%{release} diff --git a/src/sdb.c b/src/sdb.c index a9820bd..cd9bada 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -1280,101 +1280,101 @@ int should_drop_privileges() { return 1; } -#include -#include -#include +#include +#define DEVICED_BUS "org.tizen.system.deviced" +#define DEVICED_CORE_PATH "/Org/Tizen/System/DeviceD/Core" #define BOOTING_DONE_SIGNAL "BootingDone" #define DEVICED_CORE_INTERFACE "org.tizen.system.deviced.core" -#define SDBD_BOOT_INFO_FILE "/tmp/sdbd_boot_info" +#define SDBD_BOOT_INFO_FILE "/tmp/sdbd_boot_info" -static DBusHandlerResult __sdbd_dbus_signal_filter(DBusConnection *conn, - DBusMessage *message, void *user_data) { - D("got dbus message\n"); - const char *interface; +static GMainLoop *g_mainloop; - DBusError error; - dbus_error_init(&error); - - interface = dbus_message_get_interface(message); - if (interface == NULL) { - D("reject by security issue - no interface\n"); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +static void booting_done_signal_subscriber(GDBusConnection *connection, + const gchar *sender, const gchar *path, const gchar *interface, + const gchar *signal, GVariant *parameters, gpointer user_data) +{ + if (g_strcmp0(signal, BOOTING_DONE_SIGNAL) != 0) { + D("received signal(%s) does not match the desired signal(%s)\n", + signal, BOOTING_DONE_SIGNAL); + return; } - if (dbus_message_is_signal(message, DEVICED_CORE_INTERFACE, - BOOTING_DONE_SIGNAL)) { - booting_done = 1; - if (access(SDBD_BOOT_INFO_FILE, F_OK) == 0) { - D("booting is done before\n"); - } else { - FILE *f = fopen(SDBD_BOOT_INFO_FILE, "w"); - if (f != NULL) { - fprintf(f, "%d", 1); - fclose(f); - } + D("received the \"%s\" signal\n", signal); + + booting_done = 1; + if (access(SDBD_BOOT_INFO_FILE, F_OK) == 0) { + D("booting is already done\n"); + } else { + FILE *info_file = fopen(SDBD_BOOT_INFO_FILE, "w"); + if (info_file != NULL) { + fprintf(info_file, "%d", 1); + fclose(info_file); } D("booting is done\n"); } - D("handled dbus message\n"); - return DBUS_HANDLER_RESULT_HANDLED; + D("handled the booting done signal\n"); + g_main_loop_quit(g_mainloop); } -static void *bootdone_cb(void *x) { - int MAX_LOCAL_BUFSZ = 128; - DBusError error; - DBusConnection *bus; - char rule[MAX_LOCAL_BUFSZ]; - GMainLoop *mainloop; - -/* g_type_init() is deprecated for glib version 2.35.0 or greater, */ -#if !GLIB_CHECK_VERSION(2,35,0) - g_type_init(); -#endif - - dbus_error_init(&error); - bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error); - if (!bus) { - D("Failed to connect to the D-BUS daemon: %s", error.message); - dbus_error_free(&error); +static void *bootdone_cb(void *args) +{ + GError *error = NULL; + GDBusConnection *connection = NULL; + guint id; + + connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (connection == NULL) { + if (error != NULL) { + D("failed to connect to the system bus: %s\n", error->message); + g_error_free(error); + } else { + D("failed to connect to the system bus\n"); + } return NULL; } - dbus_connection_setup_with_g_main(bus, NULL); - snprintf(rule, MAX_LOCAL_BUFSZ, "type='signal',interface='%s'", - DEVICED_CORE_INTERFACE); - /* listening to messages */ - dbus_bus_add_match(bus, rule, &error); - if (dbus_error_is_set(&error)) { - D("Fail to rule set: %s", error.message); - dbus_error_free(&error); - return NULL; + g_mainloop = g_main_loop_new(NULL, false); + if (g_mainloop == NULL) { + D("failed to create a g_main_loop\n"); + goto bootdone_out; } - if (dbus_connection_add_filter(bus, __sdbd_dbus_signal_filter, NULL, NULL) - == FALSE) - return NULL; + id = g_dbus_connection_signal_subscribe(connection, + DEVICED_BUS, DEVICED_CORE_INTERFACE, BOOTING_DONE_SIGNAL, + DEVICED_CORE_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, + booting_done_signal_subscriber, NULL, NULL); + if (id == 0) { + D("failed to subscribe to the booting done signal\n"); + goto bootdone_out; + } - D("booting signal initialized\n"); - mainloop = g_main_loop_new(NULL, FALSE); - g_main_loop_run(mainloop); + D("wait for the booting done signal\n"); + g_main_loop_run(g_mainloop); - D("dbus loop exited"); - g_main_loop_unref(mainloop); - dbus_connection_unref(bus); + g_dbus_connection_signal_unsubscribe(connection, id); + +bootdone_out: + if (g_mainloop != NULL) { + g_main_loop_unref(g_mainloop); + } + if (connection != NULL) { + g_object_unref(connection); + } + D("exit the bootdone_cb thread\n"); return NULL; } -void register_bootdone_cb() { - D("registerd bootdone callback\n"); - +void register_bootdone_cb() +{ sdb_thread_t t; if (sdb_thread_create(&t, bootdone_cb, NULL)) { - D("cannot create service thread\n"); + D("can not create a service thread to check the booting done\n"); return; } + D("created the bootdone_cb thread\n"); } static int sdbd_set_groups(const char *name, int gid, struct group_info default_groups[], int default_groups_size) {