argos-systemd: stop watchdog while suspending on idle 54/189254/5 submit/tizen/20181004.081606
authorByungSoo Kim <bs1770.kim@samsung.com>
Mon, 6 Aug 2018 08:06:57 +0000 (17:06 +0900)
committerŁukasz Stelmach <l.stelmach@samsung.com>
Thu, 20 Sep 2018 12:06:52 +0000 (14:06 +0200)
Systemd sometimes misdetected the watchdog while device goes to the suspend state.
If other process failed to suspend,
montonic time of systemd goes on although some process has been already frozen.
So when device woke up, systemd expired the watchdog timer of frozen process and killed it abnormally.

If argos-watchdog receives dbus signal about both suspend and resume,
it can stop and restart the watchdog timer.

Change-Id: Ied02df1e81cca21a05edbeb84f6746d612cc6b05
Signed-off-by: ByungSoo Kim <bs1770.kim@samsung.com>
Signed-off-by: Łukasz Stelmach <l.stelmach@samsung.com>
CMakeLists.txt
packaging/argos_watchdog.spec
src/argos-systemd.c

index ea66e12..80f9979 100644 (file)
@@ -14,7 +14,7 @@ SET(HEADERS
 
 INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 
-SET(PKG_MODULES dlog)
+SET(PKG_MODULES ${PKG_MODULES} glib-2.0 dlog)
 
 IF(LIBSYSTEMD STREQUAL on)
        SET(PKG_MODULES ${PKG_MODULES} libsystemd)
index e5dc2c5..446b5f6 100644 (file)
@@ -12,6 +12,7 @@ Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
 BuildRequires:  cmake
 BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(glib-2.0)
 %if %{?libsystemd} == on
 BuildRequires: pkgconfig(libsystemd)
 %endif
index 70e7168..b1b8792 100644 (file)
 #include "common.h"
 #include <systemd/sd-daemon.h>
 #include <stdlib.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <string.h>
 
 #define SEC_TO_USEC (1000*1000)
 
+#define DEVICED_PATH_DISPLAY            "/Org/Tizen/System/DeviceD/Display"
+#define DEVICED_INTERFACE_DISPLAY       "org.tizen.system.deviced.display"
+#define WAKEUP_SIGNAL                   "wakeup"
+#define SUSPEND_SIGNAL                  "sleep"
+
 static unsigned int saved_timeout=0;
+static GDBusConnection *conn;
+static unsigned int sig_wakeup_id;
+static unsigned int sig_suspend_id;
 
 /* Now, systemd support to enable/disable runtime watchdog */
 /* https://github.com/systemd/systemd/commit/2787d83c2 */
@@ -35,9 +46,32 @@ int systemd_change_watchdog_timeout(unsigned int timeout)
        return ret;
 }
 
+static void _aw_signal_handler(GDBusConnection *connection, const gchar *sender,
+                       const gchar *path, const gchar *interface, const gchar *signal,
+                       GVariant *parameters, gpointer user_data) {
+
+       if (!strcmp(signal, WAKEUP_SIGNAL))
+               systemd_change_watchdog_timeout(saved_timeout);
+       else if (!strcmp(signal, SUSPEND_SIGNAL))
+               systemd_change_watchdog_timeout(0);
+}
+
 int _aw_register(unsigned int timeout)
 {
        int ret;
+       GError *err = NULL;
+       conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
+
+       if (conn == NULL)
+               return -1;
+
+       sig_wakeup_id = g_dbus_connection_signal_subscribe(conn, NULL,
+                       DEVICED_INTERFACE_DISPLAY, WAKEUP_SIGNAL, DEVICED_PATH_DISPLAY,
+                       NULL, G_DBUS_SIGNAL_FLAGS_NONE, _aw_signal_handler, NULL, NULL);
+
+       sig_suspend_id = g_dbus_connection_signal_subscribe(conn, NULL,
+                       DEVICED_INTERFACE_DISPLAY, SUSPEND_SIGNAL, DEVICED_PATH_DISPLAY,
+                       NULL, G_DBUS_SIGNAL_FLAGS_NONE, _aw_signal_handler, NULL, NULL);
 
        ret = systemd_change_watchdog_timeout(timeout);
        if(ret <=0)