core: sd_notify() when all dbus name is owned 09/210609/3
authorDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 18 Jul 2019 01:51:12 +0000 (10:51 +0900)
committerDongwoo Lee <dwoo08.lee@samsung.com>
Thu, 25 Jul 2019 06:07:14 +0000 (15:07 +0900)
If pass is waken-up by thermal method call, sd_notify() should be
called after all dbus name is successfully owned including thermal
dbus. To handle this case, this patch refactors name acquired event
callback.

Change-Id: I88549a81aaa38082c3d7e53c995d9f62145a6266
Signed-off-by: Dongwoo Lee <dwoo08.lee@samsung.com>
include/pass/gdbus-util.h
src/core/gdbus-util.c
src/core/main.c
src/thermal/thermal.c

index 0efbd68350fcdd3d873e51b244eaf21e7760aaa1..2f8e0783c61146ce4bfc4dbdda699e65d0e7e1ec 100644 (file)
@@ -42,8 +42,7 @@ int pass_gdbus_unregister_systemd_startup_callback(guint id);
 int pass_gdbus_get_systemd_dbus_property_string(const char *iface,
                const char *prop, const char **value);
 int pass_gdbus_export_interface(passdbus idx, gpointer instance, const char *obj_path);
-int pass_gdbus_get_name(passdbus idx, const char *name,
-               GBusNameAcquiredCallback gdbus_name_cb);
+int pass_gdbus_get_name(passdbus idx, const char *name);
 int pass_gdbus_connect_signal(gpointer instance, int num_signals,
                struct pass_gdbus_signal_info *signal_infos);
 void pass_gdbus_disconnect_signal(gpointer instance, int num_signals,
index 147e5081f4179f9637231af2f85b88bdcd53e7ae..eca425d81c449a2502fe3c3efde3a82b2b52b79c 100644 (file)
 
 #include <errno.h>
 #include <stdbool.h>
+#include <systemd/sd-daemon.h>
 
 #include <pass/gdbus-util.h>
 #include <pass/log.h>
 
 static GDBusConnection *g_dbus_sys_conn[PASS_DBUS_MAX] = {NULL, };
+static int dbus_name_owned;
 
 int pass_gdbus_export_interface(passdbus idx, gpointer instance,
                                const char *obj_path)
@@ -51,8 +53,14 @@ int pass_gdbus_export_interface(passdbus idx, gpointer instance,
        return -1;
 }
 
-int pass_gdbus_get_name(passdbus idx, const char *name,
-                       GBusNameAcquiredCallback gdbus_name_cb)
+static void pass_name_acquired_cb(GDBusConnection *connection,
+                               const gchar *name, gpointer user_data)
+{
+       if (++dbus_name_owned == PASS_DBUS_MAX)
+               sd_notify(0, "READY=1");
+}
+
+int pass_gdbus_get_name(passdbus idx, const char *name)
 {
        guint id;
 
@@ -63,7 +71,7 @@ int pass_gdbus_get_name(passdbus idx, const char *name,
 
        id = g_bus_own_name_on_connection(g_dbus_sys_conn[idx], name,
                        G_BUS_NAME_OWNER_FLAGS_NONE,
-                       gdbus_name_cb, NULL, NULL, NULL);
+                       pass_name_acquired_cb, NULL, NULL, NULL);
        if (id == 0)
                return -ENOSYS;
 
@@ -224,5 +232,6 @@ void pass_gdbus_put_system_connection(passdbus idx)
        if (g_dbus_sys_conn[idx]) {
                g_object_unref(g_dbus_sys_conn[idx]);
                g_dbus_sys_conn[idx] = NULL;
+               dbus_name_owned--;
        }
 }
index f78e6c6f426b11205511612b344c3d6590fd6a37..d93a23cf8194607f01369171cfe31c548d48183f 100644 (file)
@@ -22,7 +22,6 @@
 #include <string.h>
 #include <gio/gio.h>
 #include <sys/reboot.h>
-#include <systemd/sd-daemon.h>
 
 #include <pass/common.h>
 #include <pass/device-notifier.h>
@@ -44,12 +43,6 @@ static void sig_usr1(int signo)
        g_main_loop_quit(g_mainloop);
 }
 
-static void pass_name_acquired_cb(GDBusConnection *connection,
-                               const gchar *name, gpointer user_data)
-{
-       sd_notify(0, "READY=1");
-}
-
 static int late_init(void)
 {
        int ret;
@@ -57,8 +50,7 @@ static int late_init(void)
        signal(SIGTERM, sig_quit);
        signal(SIGUSR1, sig_usr1);
 
-       ret = pass_gdbus_get_name(PASS_DBUS_CORE,
-                               DBUS_PASS_BUS_NAME, pass_name_acquired_cb);
+       ret = pass_gdbus_get_name(PASS_DBUS_CORE, DBUS_PASS_BUS_NAME);
        if (ret < 0)
                return ret;
 
index 2858248c4c3fd964318316423410973f9cce1cc6..18c8eea6d4c09333866bfa80743ac12ac10eaf04 100644 (file)
@@ -328,8 +328,7 @@ static int thermal_probe(void *data)
                goto out;
        }
 
-       ret = pass_gdbus_get_name(PASS_DBUS_THERMAL,
-                               DBUS_THERMAL_BUS_NAME, NULL);
+       ret = pass_gdbus_get_name(PASS_DBUS_THERMAL, DBUS_THERMAL_BUS_NAME);
        if (ret < 0) {
                _E("Failed to own dbus name '%s'\n", DBUS_THERMAL_BUS_NAME);
                ret = -EINVAL;