Add systemd state checking logic 93/203293/1
authorYunmi Ha <yunmi.ha@samsung.com>
Thu, 11 Apr 2019 08:46:41 +0000 (17:46 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Thu, 11 Apr 2019 08:46:41 +0000 (17:46 +0900)
If system session is already running,
storaged can't receive StartupFinished signal.
In that case, add logic to check the systemd state at startup.

Change-Id: Ied8af322c1e8d4e5e34ea84f2e1c8f968c56a733
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/block/block.c
src/storage/storage.c

index 5e638b1..ab6ead9 100644 (file)
@@ -45,6 +45,7 @@
 #include <glib/gstdio.h>
 #include <gio/gio.h>
 #include <libsyscommon/dbus-system.h>
+#include <libsyscommon/systemd-state.h>
 
 #include "log.h"
 #include "config-parser.h"
@@ -2657,13 +2658,7 @@ static void remove_whole_block_device(void)
        }
 }
 
-static void booting_done(GDBusConnection  *conn,
-               const gchar *sender,
-               const gchar *path,
-               const gchar *iface,
-               const gchar *name,
-               GVariant *param,
-               gpointer data)
+static void booting_done(void)
 {
        static int done = 0;
        int ret;
@@ -2685,6 +2680,18 @@ static void booting_done(GDBusConnection  *conn,
        block_boot = true;
 }
 
+static void booting_done_received(GDBusConnection  *conn,
+               const gchar *sender,
+               const gchar *path,
+               const gchar *iface,
+               const gchar *name,
+               GVariant *param,
+               gpointer data)
+{
+       _I("Signal received: %s", SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED);
+       booting_done();
+}
+
 static void block_poweroff(GDBusConnection  *conn,
                const gchar *sender,
                const gchar *path,
@@ -3681,17 +3688,6 @@ static void block_init(void *data)
        if (ret < 0)
                _E("Failed to init pipe.");
 
-       /* System Session is loaded completely */
-       id_booting_done = subscribe_dbus_signal(NULL, SYSTEMD_DBUS_PATH,
-                   SYSTEMD_DBUS_IFACE_MANAGER,
-                   SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED,
-                   booting_done, NULL, NULL);
-
-       id_block_poweroff = subscribe_dbus_signal(NULL, DEVICED_PATH_POWEROFF,
-                       DEVICED_INTERFACE_POWEROFF,
-                       SIGNAL_POWEROFF_STATE,
-                       block_poweroff, NULL, NULL);
-
        for (i = 0; i < THREAD_MAX; i++) {
                th_manager[i].num_dev = 0;
                th_manager[i].op_len = 0;
@@ -3718,6 +3714,23 @@ static void block_init(void *data)
        ret = get_internal_storage_number();
        if (ret < 0)
                _E("Failed to get internal storage number.");
+
+       if (check_system_boot_finished() != 0) {
+               _I("System session is already loaded.");
+               id_booting_done = 0;
+               booting_done();
+       } else {
+               /* System Session is loaded completely */
+               id_booting_done = subscribe_dbus_signal(NULL, SYSTEMD_DBUS_PATH,
+                               SYSTEMD_DBUS_IFACE_MANAGER,
+                               SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED,
+                               booting_done_received, NULL, NULL);
+       }
+
+       id_block_poweroff = subscribe_dbus_signal(NULL, DEVICED_PATH_POWEROFF,
+                       DEVICED_INTERFACE_POWEROFF,
+                       SIGNAL_POWEROFF_STATE,
+                       block_poweroff, NULL, NULL);
 }
 static void terminate_threads(void)
 {
index 7dcfcd7..f08fb44 100644 (file)
@@ -33,6 +33,7 @@
 #include <tzplatform_config.h>
 #include <glib.h>
 #include <libsyscommon/dbus-system.h>
+#include <libsyscommon/systemd-state.h>
 
 #include "log.h"
 #include "config-parser.h"
@@ -636,13 +637,7 @@ static dbus_interface_u storage_interface = {
        .nr_methods = ARRAY_SIZE(storage_methods),
 };
 
-static void booting_done(GDBusConnection  *conn,
-               const gchar *sender,
-               const gchar *path,
-               const gchar *iface,
-               const gchar *name,
-               GVariant *param,
-               gpointer data)
+static void booting_done(void)
 {
        static int done;
 
@@ -652,7 +647,19 @@ static void booting_done(GDBusConnection  *conn,
        _I("Booting done.");
 
        if (init_storage_config_info_all() == -1)
-               _E("Failed remain mem noti control fd init.");
+               _E("Failed to remain mem noti control fd init.");
+}
+
+static void booting_done_received(GDBusConnection  *conn,
+               const gchar *sender,
+               const gchar *path,
+               const gchar *iface,
+               const gchar *name,
+               GVariant *param,
+               gpointer data)
+{
+       _I("Signal received: %s", SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED);
+       booting_done();
 }
 
 static void storage_poweroff(GDBusConnection  *conn,
@@ -711,17 +718,6 @@ static void storage_init(void *data)
 
        storage_config_load(&storage_internal_info);
 
-       /* System Session is loaded completely */
-       id_booting_done = subscribe_dbus_signal(NULL, SYSTEMD_DBUS_PATH,
-                       SYSTEMD_DBUS_IFACE_MANAGER,
-                       SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED,
-                       booting_done, NULL, NULL);
-
-       id_storage_poweroff = subscribe_dbus_signal(NULL, DEVICED_PATH_POWEROFF,
-                       DEVICED_INTERFACE_POWEROFF,
-                       SIGNAL_POWEROFF_STATE,
-                       storage_poweroff, NULL, NULL);
-
        ret = dbus_handle_register_dbus_object(NULL, STORAGED_PATH_STORAGE,
                        &storage_interface);
        if (ret < 0)
@@ -733,6 +729,23 @@ static void storage_init(void *data)
        ret = mkdir(NEED_CLEANUP_DIR_PATH, 0644);
        if (ret < 0)
                _E("Failed to make directory: %d", errno);
+
+       if (check_system_boot_finished() != 0) {
+               _I("System session is already loaded.");
+               id_booting_done = 0;
+               booting_done();
+       } else {
+               /* System Session is loaded completely */
+               id_booting_done = subscribe_dbus_signal(NULL, SYSTEMD_DBUS_PATH,
+                               SYSTEMD_DBUS_IFACE_MANAGER,
+                               SYSTEMD_DBUS_SIGNAL_SYSTEM_STARTUP_FINISHED,
+                               booting_done_received, NULL, NULL);
+       }
+
+       id_storage_poweroff = subscribe_dbus_signal(NULL, DEVICED_PATH_POWEROFF,
+                       DEVICED_INTERFACE_POWEROFF,
+                       SIGNAL_POWEROFF_STATE,
+                       storage_poweroff, NULL, NULL);
 }
 
 static void storage_exit(void *data)