diff --git a/ChangeLog b/ChangeLog index 5b5cfb4afb..0ae8c55160 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 f76e48bd18..1eb636b1f1 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 fbc0f7f143..0527db111f 100644 --- a/src/lib/ecore/ecore.c +++ b/src/lib/ecore/ecore.c @@ -19,6 +19,10 @@ # include #endif +#ifdef HAVE_SYSTEMD +# include +#endif + #ifdef HAVE_EVIL # include #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)