raster pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=53c66c98c2ae13a8c96b4ae1f9d735cda179e89d

commit 53c66c98c2ae13a8c96b4ae1f9d735cda179e89d
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
Date:   Tue Apr 12 14:11:32 2016 +0900

    ecore - system modules - fix eldbus interdependency and complaints
    
    so ecore uses ecore system modules ... that use eldbus. eldbus inits
    ecore. this is a vicious cycle. eldbus shouldnt init ecore. it's a
    dependency but should be provided outside of initting eldbus. this all
    led to hack-arounds on initting eldbus in these ecore modules that
    just break things like shutting down eldbus when still in use.
    
    this ensures any pending messages are canceled on ecore module shutdown.
    this ensures every ecore module fully inits and shuts down eldbus as
    they should so refcounting the inits works.
    this stops eldbus from inittign ecore to avoid the circuluar dependency.
    
    this stops lots of CRI/ERR complaints eg if you run elua with no
    cmdline options.
    
    this is just better.
    
    @fix
---
 src/lib/eldbus/eldbus_core.c                       | 11 -----
 .../ecore/system/systemd/ecore_system_systemd.c    | 37 +++++++---------
 .../ecore/system/upower/ecore_system_upower.c      | 49 ++++++++++++++++------
 3 files changed, 52 insertions(+), 45 deletions(-)

diff --git a/src/lib/eldbus/eldbus_core.c b/src/lib/eldbus/eldbus_core.c
index 29899d1..f5bfc4a 100644
--- a/src/lib/eldbus/eldbus_core.c
+++ b/src/lib/eldbus/eldbus_core.c
@@ -115,15 +115,6 @@ eldbus_init(void)
         return 0;
      }
 
-   if (!ecore_init())
-     {
-        ERR("Unable to initialize ecore");
-        eina_log_domain_unregister(_eldbus_log_dom);
-        _eldbus_log_dom = -1;
-        eina_shutdown();
-        return 0;
-     }
-
    eina_magic_string_set(ELDBUS_CONNECTION_MAGIC, "Eldbus_Connection");
    eina_magic_string_set(ELDBUS_MESSAGE_MAGIC, "Eldbus_Message");
    eina_magic_string_set(ELDBUS_SIGNAL_HANDLER_MAGIC, "Eldbus_Signal_Handler");
@@ -154,7 +145,6 @@ pending_failed:
 signal_handler_failed:
    eldbus_message_shutdown();
 message_failed:
-   ecore_shutdown();
    eina_log_domain_unregister(eldbus_model_log_dom);
    eldbus_model_log_dom = -1;
    eina_log_domain_unregister(_eldbus_log_dom);
@@ -257,7 +247,6 @@ eldbus_shutdown(void)
    eldbus_signal_handler_shutdown();
    eldbus_message_shutdown();
 
-   ecore_shutdown();
    eina_log_domain_unregister(eldbus_model_log_dom);
    eldbus_model_log_dom = -1;
    eina_log_domain_unregister(_eldbus_log_dom);
diff --git a/src/modules/ecore/system/systemd/ecore_system_systemd.c 
b/src/modules/ecore/system/systemd/ecore_system_systemd.c
index 26b0867..edc86a6 100644
--- a/src/modules/ecore/system/systemd/ecore_system_systemd.c
+++ b/src/modules/ecore/system/systemd/ecore_system_systemd.c
@@ -11,7 +11,7 @@ static Eldbus_Connection *_conn = NULL;
 
 static Eina_List *_objs = NULL;
 static Eina_List *_proxies = NULL;
-static Eina_Bool _eldbus_initialized = EINA_FALSE;
+static Eina_List *_eldbus_pending = NULL;
 
 #ifdef CRI
 #undef CRI
@@ -122,11 +122,12 @@ static void _locale_envs_unset(void)
 }
 
 static void _locale_get(void *data EINA_UNUSED, const Eldbus_Message *msg,
-                        Eldbus_Pending *pending EINA_UNUSED)
+                        Eldbus_Pending *pending)
 {
    Eldbus_Message_Iter *variant, *array;
    const char *errname, *errmsg, *val;
 
+   _eldbus_pending = eina_list_remove(_eldbus_pending, pending);
    if (eldbus_message_error_get(msg, &errname, &errmsg))
      {
         ERR("Message error %s - %s", errname, errmsg);
@@ -174,6 +175,7 @@ _props_changed_locale(void *data, const Eldbus_Message *msg)
    Eldbus_Proxy *proxy = data;
    Eldbus_Message_Iter *changed, *entry, *invalidated;
    const char *iface, *prop;
+   Eldbus_Pending *pend;
 
    if (!eldbus_message_arguments_get(msg, "sa{sv}as",
                                      &iface, &changed, &invalidated))
@@ -201,7 +203,8 @@ _props_changed_locale(void *data, const Eldbus_Message *msg)
    return;
 
  changed_locale:
-   eldbus_proxy_property_get(proxy, "Locale", _locale_get, NULL);
+   pend = eldbus_proxy_property_get(proxy, "Locale", _locale_get, NULL);
+   _eldbus_pending = eina_list_append(_eldbus_pending, pend);
 }
 
 static Eina_Bool
@@ -250,22 +253,7 @@ static void _ecore_system_systemd_shutdown(void);
 static Eina_Bool
 _ecore_system_systemd_init(void)
 {
-   int ref;
-
-   ref = eldbus_init();
-   if (!ref) return EINA_FALSE;
-   if (ref > 1)
-     {
-        // remove extra ref here, otherwise we have a loop like this:
-        // eldbus -> ecore -> (this module) -> eldbus
-        // and neither eldbus nor ecore can't be shutdown
-        _eldbus_initialized = EINA_FALSE;
-        eldbus_shutdown();
-     }
-   else
-     {
-        _eldbus_initialized = EINA_TRUE;
-     }
+   eldbus_init();
 
    _log_dom = eina_log_domain_register("ecore_system_systemd", NULL);
    if (_log_dom < 0)
@@ -305,6 +293,8 @@ _ecore_system_systemd_init(void)
 static void
 _ecore_system_systemd_shutdown(void)
 {
+   Eldbus_Pending *pend;
+
    DBG("ecore system 'systemd' unloaded");
 
    while (_proxies)
@@ -331,9 +321,12 @@ _ecore_system_systemd_shutdown(void)
         _log_dom = -1;
      }
 
-   if (_eldbus_initialized)
-     eldbus_shutdown();
-   _eldbus_initialized = EINA_FALSE;
+   EINA_LIST_FREE(_eldbus_pending, pend)
+     {
+        eldbus_pending_cancel(pend);
+     }
+
+   eldbus_shutdown();
 }
 
 EINA_MODULE_INIT(_ecore_system_systemd_init);
diff --git a/src/modules/ecore/system/upower/ecore_system_upower.c 
b/src/modules/ecore/system/upower/ecore_system_upower.c
index e07694c..abc621f 100644
--- a/src/modules/ecore/system/upower/ecore_system_upower.c
+++ b/src/modules/ecore/system/upower/ecore_system_upower.c
@@ -45,6 +45,8 @@ static Eina_Bool _ecore_on_battery = EINA_FALSE;
 static Eina_Bool _ecore_low_battery = EINA_FALSE;
 static int _ecore_battery_level = -1;
 
+static Eina_List *_eldbus_pending = NULL;
+
 static Eina_Bool _ecore_system_upower_display_device_init(void);
 static void _ecore_system_upower_shutdown(void);
 
@@ -89,11 +91,12 @@ _warning_level_from_variant(Eldbus_Message_Iter *variant)
 static void
 _warning_level_get_cb(void *data EINA_UNUSED,
                       const Eldbus_Message *msg,
-                      Eldbus_Pending *pending EINA_UNUSED)
+                      Eldbus_Pending *pending)
 {
    Eldbus_Message_Iter *variant;
    const char *errname, *errmsg;
 
+   _eldbus_pending = eina_list_remove(_eldbus_pending, pending);
    if (eldbus_message_error_get(msg, &errname, &errmsg))
      {
 // don't print errors because this results in complaints about upower not
@@ -113,8 +116,11 @@ _warning_level_get_cb(void *data EINA_UNUSED,
 static void
 _warning_level_get(Eldbus_Proxy *proxy)
 {
-   eldbus_proxy_property_get(proxy, "WarningLevel",
-                             _warning_level_get_cb, NULL);
+   Eldbus_Pending *pend;
+
+   pend = eldbus_proxy_property_get(proxy, "WarningLevel",
+                                    _warning_level_get_cb, NULL);
+   _eldbus_pending = eina_list_append(_eldbus_pending, pend);
 }
 
 static void
@@ -135,11 +141,12 @@ _on_low_battery_from_variant(Eldbus_Message_Iter *variant)
 
 static void
 _on_low_battery_get_cb(void *data EINA_UNUSED, const Eldbus_Message *msg,
-                        Eldbus_Pending *pending EINA_UNUSED)
+                        Eldbus_Pending *pending)
 {
    Eldbus_Message_Iter *variant;
    const char *errname, *errmsg;
 
+   _eldbus_pending = eina_list_remove(_eldbus_pending, pending);
    if (eldbus_message_error_get(msg, &errname, &errmsg))
      {
         ERR("Message error %s - %s", errname, errmsg);
@@ -157,8 +164,11 @@ _on_low_battery_get_cb(void *data EINA_UNUSED, const 
Eldbus_Message *msg,
 static void
 _on_low_battery_get(Eldbus_Proxy *proxy)
 {
-   eldbus_proxy_property_get(proxy, "OnLowBattery",
-                             _on_low_battery_get_cb, NULL);
+   Eldbus_Pending *pend;
+
+   pend = eldbus_proxy_property_get(proxy, "OnLowBattery",
+                                    _on_low_battery_get_cb, NULL);
+   _eldbus_pending = eina_list_append(_eldbus_pending, pend);
 }
 
 static void
@@ -179,11 +189,12 @@ _on_battery_from_variant(Eldbus_Message_Iter *variant)
 
 static void
 _on_battery_get_cb(void *data EINA_UNUSED, const Eldbus_Message *msg,
-                        Eldbus_Pending *pending EINA_UNUSED)
+                        Eldbus_Pending *pending)
 {
    Eldbus_Message_Iter *variant;
    const char *errname, *errmsg;
 
+   _eldbus_pending = eina_list_remove(_eldbus_pending, pending);
    if (eldbus_message_error_get(msg, &errname, &errmsg))
      {
         ERR("Message error %s - %s", errname, errmsg);
@@ -201,8 +212,11 @@ _on_battery_get_cb(void *data EINA_UNUSED, const 
Eldbus_Message *msg,
 static void
 _on_battery_get(Eldbus_Proxy *proxy)
 {
-   eldbus_proxy_property_get(proxy, "OnBattery",
-                             _on_battery_get_cb, NULL);
+   Eldbus_Pending *pend;
+
+   pend = eldbus_proxy_property_get(proxy, "OnBattery",
+                                    _on_battery_get_cb, NULL);
+   _eldbus_pending = eina_list_append(_eldbus_pending, pend);
 }
 
 static void
@@ -263,11 +277,12 @@ _daemon_version_from_variant(Eldbus_Message_Iter *variant)
 
 static void
 _daemon_version_get_cb(void *data EINA_UNUSED, const Eldbus_Message *msg,
-                          Eldbus_Pending *pending EINA_UNUSED)
+                          Eldbus_Pending *pending)
 {
    Eldbus_Message_Iter *variant;
    const char *errname, *errmsg;
 
+   _eldbus_pending = eina_list_remove(_eldbus_pending, pending);
    if (eldbus_message_error_get(msg, &errname, &errmsg))
      {
         ERR("Message error %s - %s", errname, errmsg);
@@ -285,8 +300,11 @@ _daemon_version_get_cb(void *data EINA_UNUSED, const 
Eldbus_Message *msg,
 static void
 _daemon_version_get(Eldbus_Proxy *proxy)
 {
-   eldbus_proxy_property_get(proxy, "DaemonVersion",
-                             _daemon_version_get_cb, NULL);
+   Eldbus_Pending *pend;
+
+   pend = eldbus_proxy_property_get(proxy, "DaemonVersion",
+                                    _daemon_version_get_cb, NULL);
+   _eldbus_pending = eina_list_append(_eldbus_pending, pend);
 }
 
 static void
@@ -445,6 +463,8 @@ _ecore_system_upower_init(void)
 static void
 _ecore_system_upower_shutdown(void)
 {
+   Eldbus_Pending *pend;
+
    DBG("ecore system 'upower' unloaded");
 
    eldbus_name_owner_changed_callback_del(_conn, "org.freedesktop.UPower",
@@ -486,6 +506,11 @@ _ecore_system_upower_shutdown(void)
         _log_dom = -1;
      }
 
+   EINA_LIST_FREE(_eldbus_pending, pend)
+     {
+        eldbus_pending_cancel(pend);
+     }
+
    eldbus_shutdown();
 }
 

-- 


Reply via email to