discomfitor pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=7927cfefe3a4c45b6b86ed36bb284d009e154f19

commit 7927cfefe3a4c45b6b86ed36bb284d009e154f19
Author: Mike Blumenkrantz <zm...@osg.samsung.com>
Date:   Fri Feb 2 16:59:56 2018 -0500

    ecore-file: make monitoring truly fork-safe
    
    add a fork reset callback and attempt to preserve existing monitors
    during reset
    
    @fix
---
 src/lib/ecore_file/ecore_file_monitor_inotify.c | 28 +++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/src/lib/ecore_file/ecore_file_monitor_inotify.c 
b/src/lib/ecore_file/ecore_file_monitor_inotify.c
index cf04ae6ca8..e4bb6d3b0b 100644
--- a/src/lib/ecore_file/ecore_file_monitor_inotify.c
+++ b/src/lib/ecore_file/ecore_file_monitor_inotify.c
@@ -47,8 +47,27 @@ static int                 
_ecore_file_monitor_inotify_monitor(Ecore_File_Monito
 static void                _ecore_file_monitor_inotify_print(char *file, int 
mask);
 #endif
 
+static Eina_Bool reseting;
 static Eina_Hash *monitor_hash;
 
+static void
+_ecore_file_monitor_inotify_reset()
+{
+   Eina_Iterator *it;
+   Ecore_File_Monitor *em;
+   Eina_Hash *h = monitor_hash;
+   monitor_hash = NULL;
+   reseting = 1;
+   ecore_file_monitor_backend_shutdown();
+   ecore_file_monitor_backend_init();
+   it = eina_hash_iterator_data_new(h);
+   EINA_ITERATOR_FOREACH(it, em)
+     _ecore_file_monitor_inotify_monitor(em, em->path);
+   eina_iterator_free(it);
+   eina_hash_free(h);
+   reseting = 0;
+}
+
 int
 ecore_file_monitor_backend_init(void)
 {
@@ -68,6 +87,8 @@ ecore_file_monitor_backend_init(void)
         return 0;
      }
 
+   if (!reseting)
+     ecore_fork_reset_callback_add(_ecore_file_monitor_inotify_reset, NULL);
    _inotify_fd_pid = getpid();
    monitor_hash = eina_hash_int32_new(NULL);
    return 1;
@@ -91,6 +112,8 @@ ecore_file_monitor_backend_shutdown(void)
    eina_hash_free(monitor_hash);
    monitor_hash = NULL;
    _inotify_fd_pid = -1;
+   if (!reseting)
+     ecore_fork_reset_callback_del(_ecore_file_monitor_inotify_reset, NULL);
    return 1;
 }
 
@@ -108,10 +131,7 @@ ecore_file_monitor_backend_add(const char *path,
    if (_inotify_fd_pid == -1) return NULL;
 
    if (_inotify_fd_pid != getpid())
-     {
-        ecore_file_monitor_backend_shutdown();
-        ecore_file_monitor_backend_init();
-     }
+     _ecore_file_monitor_inotify_reset();
 
    em = (Ecore_File_Monitor *)calloc(1, sizeof(Ecore_File_Monitor_Inotify));
    if (!em) return NULL;

-- 


Reply via email to