Enhance the priority of the periodic watchdog_cb() 22/169222/6
authorHyotaek Shim <hyotaek.shim@samsung.com>
Mon, 5 Feb 2018 05:14:24 +0000 (14:14 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Mon, 5 Feb 2018 06:49:21 +0000 (15:49 +0900)
to avoid crash under unexpectedly blocked sync calls or intensive workload

Change-Id: Idb66cacde1dfc211f25b0802cc1ed491bbd58af9
Signed-off-by: Hyotaek Shim <hyotaek.shim@samsung.com>
src/core/edbus-handler.c
src/core/main.c
src/shared/dbus.c
src/shared/dbus.h

index b77f942..bc0241a 100644 (file)
@@ -858,7 +858,7 @@ void edbus_init(void *data)
        }
 
        for (int i = 0 ; i < EDBUS_INIT_RETRY_COUNT; ++i) {
-               ret = dbus_handle_request_bus_name(handle, DEVICED_BUS_NAME);
+               ret = dbus_handle_request_bus_name(handle, DEVICED_BUS_NAME, NULL, NULL);
                if (ret > 0)
                        break;
                _E("failed to request bus name:retry %d", i);
index 6b482cf..55b7011 100644 (file)
@@ -68,41 +68,29 @@ void watchdog_notify(void)
                _E("aw_notify failed(%d)", ret);
 }
 
-static gboolean watchdog_cb(void *data)
-{
-       watchdog_notify();
-       return G_SOURCE_CONTINUE;
-}
-
-static gboolean deviced_main_cb(void *data)
+static void deviced_dbus_name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
 {
        int ret;
-       guint timer;
-
        ret = booting_finished();
        if (ret == 1) {
                _I("notify relaunch");
                device_notify(DEVICE_NOTIFIER_BOOTING_DONE, &ret);
        }
-       signal(SIGTERM, sig_quit);
-       signal(SIGUSR1, sig_usr1);
-
-       timer = g_timeout_add_seconds(WATCHDOG_TIMEOUT, watchdog_cb, NULL);
-       if (timer) {
-               ret = aw_register(WATCHDOG_TIMEOUT * 2);
-               if (ret < 0)
-                       _E("aw_register failed");
-       }
 
        _I("sd_notify(READY=1)");
        sd_notify(0, "READY=1");
+}
 
-       return G_SOURCE_REMOVE;
+static gboolean watchdog_cb(void *data)
+{
+       watchdog_notify();
+       return G_SOURCE_CONTINUE;
 }
 
 static int deviced_main(int argc, char **argv)
 {
        int ret;
+       guint timer;
 
        mainloop = g_main_loop_new(NULL, FALSE);
 
@@ -110,15 +98,19 @@ static int deviced_main(int argc, char **argv)
        if (ret)
                return 0;
 
-       if (!dbus_handle_init(G_BUS_TYPE_SYSTEM, DEVICED_BUS_NAME)) {
+       if (!dbus_handle_init(G_BUS_TYPE_SYSTEM, DEVICED_BUS_NAME, deviced_dbus_name_acquired, NULL)) {
                _E("failed to init dbus connection");
        }
        devices_init(NULL);
 
-       ret = g_timeout_add(0, deviced_main_cb, NULL);
-       if (ret <= 0) {
-               _E("failed to add timeout source for deviced_main_cb");
-               return 0;
+       signal(SIGTERM, sig_quit);
+       signal(SIGUSR1, sig_usr1);
+
+       timer = g_timeout_add_seconds_full(G_PRIORITY_HIGH, WATCHDOG_TIMEOUT, watchdog_cb, NULL, NULL);
+       if (timer) {
+               ret = aw_register(WATCHDOG_TIMEOUT * 2);
+               if (ret < 0)
+                       _E("aw_register failed");
        }
 
        /* g_main_loop */
index b7bad4a..eccedcb 100644 (file)
@@ -400,6 +400,8 @@ out:
        dbus_handle_unlock(dh);
 }
 
+extern void booting_done(void);
+
 static void _name_acquired(GDBusConnection *connection, const gchar *name, gpointer user_data)
 {
        dbus_handle_s *dh = (dbus_handle_s *)user_data;
@@ -410,6 +412,7 @@ static void _name_acquired(GDBusConnection *connection, const gchar *name, gpoin
                _E("%s:%d:dbus handle is null\n", __func__, __LINE__);
                return ;
        }
+
        // todo: add bus name?
        //dh->bus_name = name;
 }
@@ -425,7 +428,8 @@ static void _name_lost(GDBusConnection *connection, const gchar *name, gpointer
        _dbus_handle_remove_bus_name(dh, name);
 }
 
-int dbus_handle_request_bus_name(dbus_handle_h handle, const char *bus_name)
+int dbus_handle_request_bus_name(dbus_handle_h handle, const char *bus_name,
+               GBusNameAcquiredCallback acquired_handler, GBusNameLostCallback lost_handler)
 {
        dcl_dbus_handle();
        int id = -1;
@@ -459,7 +463,9 @@ int dbus_handle_request_bus_name(dbus_handle_h handle, const char *bus_name)
                goto out;
        }
 
-       id = g_bus_own_name_on_connection(dh->conn, bus_name, G_BUS_NAME_OWNER_FLAGS_NONE, _name_acquired, _name_lost, dh, NULL);
+       id = g_bus_own_name_on_connection(dh->conn, bus_name, G_BUS_NAME_OWNER_FLAGS_NONE, 
+                       acquired_handler ? acquired_handler : _name_acquired,
+                       lost_handler ? lost_handler : _name_lost, dh, NULL);
        if (!id) {
                _E("failed to own name:%s\n", bus_name);
                goto out;
@@ -2540,7 +2546,8 @@ void dbush_handle_check_owner_name(dbus_handle_h handle, const char *owner_name)
        g_strfreev(strv);
 }
 
-dbus_handle_h dbus_handle_init(GBusType type, const char* bus_name)
+dbus_handle_h dbus_handle_init(GBusType type, const char* bus_name,
+               GBusNameAcquiredCallback acquired_handler, GBusNameLostCallback lost_handler)
 {
        dbus_handle_h handle = NULL;
        int i, ret = 0;
@@ -2557,7 +2564,7 @@ dbus_handle_h dbus_handle_init(GBusType type, const char* bus_name)
                        break;
                usleep(5000);
        }
-       ret = dbus_handle_request_bus_name(handle, bus_name);
+       ret = dbus_handle_request_bus_name(handle, bus_name, acquired_handler, lost_handler);
        if (ret <= 0)
                goto out;
 
index 0cfc2a4..44b83a5 100755 (executable)
@@ -425,7 +425,7 @@ typedef struct {
        void *data;
 } pending_call_data;
 
-int dbus_handle_request_bus_name(dbus_handle_h handle, const char *bus_name);
+int dbus_handle_request_bus_name(dbus_handle_h handle, const char *bus_name, GBusNameAcquiredCallback acquired_handler, GBusNameLostCallback lost_handler);
 
 dbus_handle_h dbus_handle_get_connection(GBusType bus_type, gboolean priv);
 
@@ -456,7 +456,7 @@ int dbus_handle_get_sender_pid(dbus_handle_h handle, const char * sender);
 int dbus_handle_get_sender_credentials(dbus_handle_h handle, const char *name, GDBusCredentials *creds);
 int dbus_handle_watch_name(const char *name, GBusNameAppearedCallback name_appeared_handler, GBusNameVanishedCallback name_vanished_handler, void *user_data);
 void dbus_handle_unwatch_name(guint id);
-dbus_handle_h dbus_handle_init(GBusType type, const char* bus_name);
+dbus_handle_h dbus_handle_init(GBusType type, const char* bus_name, GBusNameAcquiredCallback acquired_handler, GBusNameLostCallback lost_handler);
 char** dbus_handle_get_owner_list(dbus_handle_h handle, const char *bus_name);
 void dbush_handle_check_owner_name(dbus_handle_h handle, const char *owner_name);