aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ecore_file
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2018-02-02 16:59:56 -0500
committerMike Blumenkrantz <zmike@osg.samsung.com>2018-02-02 16:59:44 -0500
commit7927cfefe3a4c45b6b86ed36bb284d009e154f19 (patch)
treeb0dc22115c37963b5010df03a43206b4ba0a5848 /src/lib/ecore_file
parentelm: call ecore_event_init() during init (diff)
downloadefl-7927cfefe3a4c45b6b86ed36bb284d009e154f19.tar.gz
ecore-file: make monitoring truly fork-safe
add a fork reset callback and attempt to preserve existing monitors during reset @fix
Diffstat (limited to 'src/lib/ecore_file')
-rw-r--r--src/lib/ecore_file/ecore_file_monitor_inotify.c28
1 files 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;