cedric pushed a commit to branch master.

commit 7bb467819b304f586e9dda131252f5903fc21a03
Author: Cedric Bail <[email protected]>
Date:   Thu Mar 28 23:28:32 2013 +0900

    ecore: add systemd watchdog support to Ecore main loop.
---
 ChangeLog             |  4 ++++
 NEWS                  |  4 +++-
 src/lib/ecore/ecore.c | 41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 5b5cfb4..0ae8c55 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2013-03-28  Cedric Bail
+
+       * Ecore: automatically turn on Systemd watchdog in Ecore main loop.
+
 2013-03-28  Carsten Haitzler (The Rasterman)
 
         * Change evas_textblock_cursor_word_start() and
diff --git a/NEWS b/NEWS
index f76e48b..1eb636b 100644
--- a/NEWS
+++ b/NEWS
@@ -81,7 +81,9 @@ Additions:
     * Ecore_x: Add manual render code before deiconify
     * Eeze: Add a dummy libmount replacement for when libmount is not there.
     * Ecore_Con: Add systemd socket activation support 
(ECORE_CON_SOCKET_ACTIVATE).
-    * Ecore: notify systemd that we are ready as soon as the main loop is 
running.
+    * Ecore:
+     - notify systemd that we are ready as soon as the main loop is running.
+     - automatically support Watchdog.
     * ecore_imf: Add ecore_imf_context_input_panel_layout_variation_set/get API
     * Add edje_object_part_text_input_panel_layout_variation_set/get API
 
diff --git a/src/lib/ecore/ecore.c b/src/lib/ecore/ecore.c
index fbc0f7f..0527db1 100644
--- a/src/lib/ecore/ecore.c
+++ b/src/lib/ecore/ecore.c
@@ -19,6 +19,10 @@
 # include <sys/mman.h>
 #endif
 
+#ifdef HAVE_SYSTEMD
+# include <systemd/sd-daemon.h>
+#endif
+
 #ifdef HAVE_EVIL
 # include <Evil.h>
 #endif
@@ -69,6 +73,10 @@ struct _Ecore_Safe_Call
    Eina_Bool      suspend : 1;
 };
 
+#ifdef HAVE_SYSTEMD
+static Eina_Bool _systemd_watchdog_cb(void *data);
+#endif
+
 static void _ecore_main_loop_thread_safe_call(Ecore_Safe_Call *order);
 static void _thread_safe_cleanup(void *data);
 static void _thread_callback(void        *data,
@@ -90,6 +98,10 @@ static int _thread_id = -1;
 static int _thread_id_max = 0;
 static int _thread_id_update = 0;
 
+#ifdef HAVE_SYSTEMD
+static Ecore_Timer *_systemd_watchdog = NULL;
+#endif
+
 Eina_Lock _ecore_main_loop_lock;
 int _ecore_main_lock_count;
 
@@ -195,6 +207,18 @@ ecore_init(void)
 #endif
    _ecore_parent = eo_add(ECORE_PARENT_CLASS, NULL);
 
+#ifdef HAVE_SYSTEMD
+   if (getenv("WATCHDOG_USEC"))
+     {
+        double sec;
+
+       sec = ((double) atoi(getenv("WATCHDOG_USEC"))) / 1000 / 1000;
+
+       _systemd_watchdog = ecore_timer_add(sec / 2, _systemd_watchdog_cb, 
NULL);
+       unsetenv("WATCHDOG_USEC");
+     }
+#endif
+
    eina_log_timing(_ecore_log_dom,
                   EINA_LOG_STATE_STOP,
                   EINA_LOG_STATE_INIT);
@@ -246,6 +270,14 @@ ecore_shutdown(void)
                     EINA_LOG_STATE_START,
                     EINA_LOG_STATE_SHUTDOWN);
 
+#ifdef HAVE_SYSTEMD
+     if (_systemd_watchdog)
+       {
+         ecore_timer_del(_systemd_watchdog);
+         _systemd_watchdog = NULL;
+       }
+#endif
+
      if (_ecore_fps_debug) _ecore_fps_debug_shutdown();
      _ecore_coroutine_shutdown();
      _ecore_poller_shutdown();
@@ -753,6 +785,15 @@ _ecore_fps_debug_runtime_add(double t)
      }
 }
 
+#ifdef HAVE_SYSTEMD
+static Eina_Bool
+_systemd_watchdog_cb(EINA_UNUSED void *data)
+{
+   sd_notify(0, "WATCHDOG=1");
+   return ECORE_CALLBACK_RENEW;
+}
+#endif
+
 #if HAVE_MALLINFO
 static Eina_Bool
 _ecore_memory_statistic(EINA_UNUSED void *data)

-- 

------------------------------------------------------------------------------
Own the Future-Intel&reg; Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest.
Compete for recognition, cash, and the chance to get your game 
on Steam. $5K grand prize plus 10 genre and skill prizes. 
Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d

Reply via email to