diff options
author | Mike Blumenkrantz <zmike@osg.samsung.com> | 2018-02-02 16:59:56 -0500 |
---|---|---|
committer | Mike Blumenkrantz <zmike@osg.samsung.com> | 2018-02-02 16:59:44 -0500 |
commit | 7927cfefe3a4c45b6b86ed36bb284d009e154f19 (patch) | |
tree | b0dc22115c37963b5010df03a43206b4ba0a5848 /src/lib/ecore_file/ecore_file_monitor_inotify.c | |
parent | 4e14ba3f4874b03185d5216829ecc1876d11c48e (diff) |
ecore-file: make monitoring truly fork-safe
add a fork reset callback and attempt to preserve existing monitors
during reset
@fix
Diffstat (limited to '')
-rw-r--r-- | src/lib/ecore_file/ecore_file_monitor_inotify.c | 28 |
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 | |||
47 | static void _ecore_file_monitor_inotify_print(char *file, int mask); | 47 | static void _ecore_file_monitor_inotify_print(char *file, int mask); |
48 | #endif | 48 | #endif |
49 | 49 | ||
50 | static Eina_Bool reseting; | ||
50 | static Eina_Hash *monitor_hash; | 51 | static Eina_Hash *monitor_hash; |
51 | 52 | ||
53 | static void | ||
54 | _ecore_file_monitor_inotify_reset() | ||
55 | { | ||
56 | Eina_Iterator *it; | ||
57 | Ecore_File_Monitor *em; | ||
58 | Eina_Hash *h = monitor_hash; | ||
59 | monitor_hash = NULL; | ||
60 | reseting = 1; | ||
61 | ecore_file_monitor_backend_shutdown(); | ||
62 | ecore_file_monitor_backend_init(); | ||
63 | it = eina_hash_iterator_data_new(h); | ||
64 | EINA_ITERATOR_FOREACH(it, em) | ||
65 | _ecore_file_monitor_inotify_monitor(em, em->path); | ||
66 | eina_iterator_free(it); | ||
67 | eina_hash_free(h); | ||
68 | reseting = 0; | ||
69 | } | ||
70 | |||
52 | int | 71 | int |
53 | ecore_file_monitor_backend_init(void) | 72 | ecore_file_monitor_backend_init(void) |
54 | { | 73 | { |
@@ -68,6 +87,8 @@ ecore_file_monitor_backend_init(void) | |||
68 | return 0; | 87 | return 0; |
69 | } | 88 | } |
70 | 89 | ||
90 | if (!reseting) | ||
91 | ecore_fork_reset_callback_add(_ecore_file_monitor_inotify_reset, NULL); | ||
71 | _inotify_fd_pid = getpid(); | 92 | _inotify_fd_pid = getpid(); |
72 | monitor_hash = eina_hash_int32_new(NULL); | 93 | monitor_hash = eina_hash_int32_new(NULL); |
73 | return 1; | 94 | return 1; |
@@ -91,6 +112,8 @@ ecore_file_monitor_backend_shutdown(void) | |||
91 | eina_hash_free(monitor_hash); | 112 | eina_hash_free(monitor_hash); |
92 | monitor_hash = NULL; | 113 | monitor_hash = NULL; |
93 | _inotify_fd_pid = -1; | 114 | _inotify_fd_pid = -1; |
115 | if (!reseting) | ||
116 | ecore_fork_reset_callback_del(_ecore_file_monitor_inotify_reset, NULL); | ||
94 | return 1; | 117 | return 1; |
95 | } | 118 | } |
96 | 119 | ||
@@ -108,10 +131,7 @@ ecore_file_monitor_backend_add(const char *path, | |||
108 | if (_inotify_fd_pid == -1) return NULL; | 131 | if (_inotify_fd_pid == -1) return NULL; |
109 | 132 | ||
110 | if (_inotify_fd_pid != getpid()) | 133 | if (_inotify_fd_pid != getpid()) |
111 | { | 134 | _ecore_file_monitor_inotify_reset(); |
112 | ecore_file_monitor_backend_shutdown(); | ||
113 | ecore_file_monitor_backend_init(); | ||
114 | } | ||
115 | 135 | ||
116 | em = (Ecore_File_Monitor *)calloc(1, sizeof(Ecore_File_Monitor_Inotify)); | 136 | em = (Ecore_File_Monitor *)calloc(1, sizeof(Ecore_File_Monitor_Inotify)); |
117 | if (!em) return NULL; | 137 | if (!em) return NULL; |