Fix: ecore-file inotify fd would be duplicated in children
authorraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 22 Feb 2011 06:09:46 +0000 (06:09 +0000)
committerraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 22 Feb 2011 06:09:46 +0000 (06:09 +0000)
on fork. Have it detecti this on next monitor add and re-init
the inotify fd and fd handler.

git-svn-id: http://svn.enlightenment.org/svn/e/trunk/ecore@57228 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

ChangeLog
src/lib/ecore_file/ecore_file_monitor_inotify.c

index f6febcf..8b9d474 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -58,3 +58,9 @@
 
        * Remove 300 second timeout so large downloads work in ecore_con.
 
+2011-02-22  Carsten Haitzler (The Rasterman)
+
+        * Fix: ecore-file inotify fd would be duplicated in children
+        on fork. Have it detecti this on next monitor add and re-init the
+        inotify fd and fd handler.
+
index e9bb595..0491f29 100644 (file)
@@ -47,6 +47,7 @@ struct _Ecore_File_Monitor_Inotify
 
 static Ecore_Fd_Handler *_fdh = NULL;
 static Ecore_File_Monitor    *_monitors = NULL;
+static pid_t             _inotify_fd_pid = -1;
 
 static Eina_Bool           _ecore_file_monitor_inotify_handler(void *data, Ecore_Fd_Handler *fdh);
 static Ecore_File_Monitor *_ecore_file_monitor_inotify_monitor_find(int wd);
@@ -64,7 +65,7 @@ ecore_file_monitor_inotify_init(void)
    fd = inotify_init();
    if (fd < 0)
      return 0;
-
+   
    _fdh = ecore_main_fd_handler_add(fd, ECORE_FD_READ, _ecore_file_monitor_inotify_handler,
                                     NULL, NULL, NULL);
    if (!_fdh)
@@ -73,6 +74,7 @@ ecore_file_monitor_inotify_init(void)
         return 0;
      }
 
+   _inotify_fd_pid = getpid();
    return 1;
 }
 
@@ -90,6 +92,7 @@ ecore_file_monitor_inotify_shutdown(void)
         ecore_main_fd_handler_del(_fdh);
         close(fd);
      }
+   _inotify_fd_pid = -1;
    return 1;
 }
 
@@ -103,6 +106,14 @@ ecore_file_monitor_inotify_add(const char *path,
    Ecore_File_Monitor *em;
    int len;
 
+   if (_inotify_fd_pid == -1) return NULL;
+
+   if (_inotify_fd_pid != getpid())
+     {
+        ecore_file_monitor_inotify_shutdown();
+        ecore_file_monitor_inotify_init();
+     }
+   
    em = calloc(1, sizeof(Ecore_File_Monitor_Inotify));
    if (!em) return NULL;