From d9ad9b585a7e3bec43114400cd6c7d3be94cc81b Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Sun, 23 Apr 2017 10:33:41 +0900 Subject: [PATCH] efreetd - make efreetd use eio and not ecore_file_monitor for monitoring this should fix T5130 - freebsd's efreetd polling regularly @fix --- src/Makefile_Efreet.am | 13 +- src/bin/efreet/efreetd_cache.c | 227 +++++++++++++++++---------------- 2 files changed, 127 insertions(+), 113 deletions(-) diff --git a/src/Makefile_Efreet.am b/src/Makefile_Efreet.am index fe969f935c..f955cec33e 100644 --- a/src/Makefile_Efreet.am +++ b/src/Makefile_Efreet.am @@ -83,9 +83,16 @@ bin/efreet/efreetd_ipc.c \ bin/efreet/efreetd_cache.h \ bin/efreet/efreetd_cache.c -bin_efreet_efreetd_CPPFLAGS = -I$(top_builddir)/src/lib/efl $(EFREET_COMMON_CPPFLAGS) -bin_efreet_efreetd_LDADD = $(USE_EFREET_BIN_LIBS) -bin_efreet_efreetd_DEPENDENCIES = @USE_EFREET_INTERNAL_LIBS@ +bin_efreet_efreetd_CPPFLAGS = \ + -I$(top_builddir)/src/lib/efl \ + $(EFREET_COMMON_CPPFLAGS) \ + @EIO_CFLAGS@ +bin_efreet_efreetd_LDADD = $(USE_EFREET_BIN_LIBS) @USE_EIO_LIBS@ +bin_efreet_efreetd_DEPENDENCIES = \ + @USE_EFREET_INTERNAL_LIBS@ \ + lib/eio/libeio.la \ + lib/efreet/libefreet_mime.la \ + lib/efreet/libefreet_trash.la efreetinternal_bindir=$(libdir)/efreet/$(MODULE_ARCH) efreetinternal_bin_PROGRAMS = \ diff --git a/src/bin/efreet/efreetd_cache.c b/src/bin/efreet/efreetd_cache.c index 75a87c220b..7f3dc07e98 100644 --- a/src/bin/efreet/efreetd_cache.c +++ b/src/bin/efreet/efreetd_cache.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "efreetd.h" #include "efreetd_ipc.h" @@ -19,7 +20,9 @@ #include static Eina_Hash *icon_change_monitors = NULL; +static Eina_Hash *icon_change_monitors_mon = NULL; static Eina_Hash *desktop_change_monitors = NULL; +static Eina_Hash *desktop_change_monitors_mon = NULL; static Ecore_Event_Handler *cache_exe_del_handler = NULL; static Ecore_Event_Handler *cache_exe_data_handler = NULL; @@ -40,6 +43,8 @@ static Eina_Bool icon_flush = EINA_FALSE; static Eina_Bool desktop_queue = EINA_FALSE; static Eina_Bool icon_queue = EINA_FALSE; +static Eina_List *_handlers = NULL; + static void icon_changes_listen(void); static void desktop_changes_listen(void); @@ -72,11 +77,13 @@ static Subdir_Cache *subdir_cache = NULL; static Eina_Bool subdir_need_save = EINA_FALSE; static Eina_Hash *mime_monitors = NULL; +static Eina_Hash *mime_monitors_mon = NULL; static Ecore_Timer *mime_update_timer = NULL; static Ecore_Exe *mime_cache_exe = NULL; static void mime_cache_init(void); static void mime_cache_shutdown(void); +static Eina_Bool mime_update_cache_cb(void *data EINA_UNUSED); static void subdir_cache_dir_free(Subdir_Cache_Dir *cd) @@ -310,8 +317,10 @@ icon_cache_update_cache_cb(void *data EINA_UNUSED) if ((!icon_flush) && (!icon_exts)) return ECORE_CALLBACK_CANCEL; if (icon_change_monitors) eina_hash_free(icon_change_monitors); + if (icon_change_monitors_mon) eina_hash_free(icon_change_monitors_mon); icon_change_monitors = eina_hash_string_superfast_new - (EINA_FREE_CB(ecore_file_monitor_del)); + (EINA_FREE_CB(eio_monitor_del)); + icon_change_monitors_mon = eina_hash_pointer_new(NULL); icon_changes_listen(); subdir_cache_save(); @@ -367,8 +376,10 @@ desktop_cache_update_cache_cb(void *data EINA_UNUSED) desktop_queue = EINA_FALSE; if (desktop_change_monitors) eina_hash_free(desktop_change_monitors); + if (desktop_change_monitors_mon) eina_hash_free(desktop_change_monitors_mon); desktop_change_monitors = eina_hash_string_superfast_new - (EINA_FREE_CB(ecore_file_monitor_del)); + (EINA_FREE_CB(eio_monitor_del)); + desktop_change_monitors_mon = eina_hash_pointer_new(NULL); desktop_changes_listen(); subdir_cache_save(); @@ -409,73 +420,40 @@ cache_desktop_update(void) desktop_cache_timer = ecore_timer_add(0.2, desktop_cache_update_cache_cb, NULL); } -static void -icon_changes_cb(void *data EINA_UNUSED, Ecore_File_Monitor *em EINA_UNUSED, - Ecore_File_Event event, const char *path EINA_UNUSED) +static Eina_Bool +_cb_monitor_event(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) { - switch (event) + Eio_Monitor_Event *ev = event; + + // if it's an icon + if (eina_hash_find(icon_change_monitors_mon, &(ev->monitor))) { - case ECORE_FILE_EVENT_NONE: - /* noop */ - break; - - case ECORE_FILE_EVENT_CREATED_FILE: - case ECORE_FILE_EVENT_DELETED_FILE: - case ECORE_FILE_EVENT_MODIFIED: - case ECORE_FILE_EVENT_CLOSED: - // a FILE was changed, added or removed cache_icon_update(EINA_FALSE); - break; - - case ECORE_FILE_EVENT_DELETED_DIRECTORY: - case ECORE_FILE_EVENT_CREATED_DIRECTORY: - // the whole tree needs re-monitoring - cache_icon_update(EINA_FALSE); - break; - - case ECORE_FILE_EVENT_DELETED_SELF: - // the whole tree needs re-monitoring - cache_icon_update(EINA_FALSE); - break; } -} - -static void -desktop_changes_cb(void *data EINA_UNUSED, Ecore_File_Monitor *em EINA_UNUSED, - Ecore_File_Event event, const char *path EINA_UNUSED) -{ - /* TODO: Check for desktop*.cache, as this will be created when app is installed */ - switch (event) + // if it's a desktop + else if (eina_hash_find(desktop_change_monitors_mon, &(ev->monitor))) { - case ECORE_FILE_EVENT_NONE: - /* noop */ - break; - - case ECORE_FILE_EVENT_CREATED_FILE: - case ECORE_FILE_EVENT_DELETED_FILE: - case ECORE_FILE_EVENT_MODIFIED: - case ECORE_FILE_EVENT_CLOSED: - // a FILE was changed, added or removed cache_desktop_update(); - break; - - case ECORE_FILE_EVENT_DELETED_DIRECTORY: - case ECORE_FILE_EVENT_CREATED_DIRECTORY: - // the whole tree needs re-monitoring - cache_desktop_update(); - break; - - case ECORE_FILE_EVENT_DELETED_SELF: - // the whole tree needs re-monitoring - cache_desktop_update(); - break; } + // if it's a mime file + else if (eina_hash_find(mime_monitors_mon, &(ev->monitor))) + { + if ((!strcmp("/etc/mime.types", ev->filename)) || + (!strcmp("globs", ecore_file_file_get(ev->filename)))) + { + mime_cache_shutdown(); + mime_cache_init(); + if (mime_update_timer) ecore_timer_del(mime_update_timer); + mime_update_timer = ecore_timer_add(0.2, mime_update_cache_cb, NULL); + } + } + return ECORE_CALLBACK_PASS_ON; } static void icon_changes_monitor_add(const struct stat *st, const char *path) { - Ecore_File_Monitor *mon; + Eio_Monitor *mon; char *realp = NULL; const char *monpath = path; @@ -486,15 +464,22 @@ icon_changes_monitor_add(const struct stat *st, const char *path) if (!realp) return; monpath = realp; } - mon = ecore_file_monitor_add(monpath, icon_changes_cb, NULL); + if (ecore_file_is_dir(monpath)) + { + mon = eio_monitor_add(monpath); + if (mon) + { + eina_hash_add(icon_change_monitors, path, mon); + eina_hash_add(icon_change_monitors_mon, &mon, mon); + } + } free(realp); - if (mon) eina_hash_add(icon_change_monitors, path, mon); } static void desktop_changes_monitor_add(const struct stat *st, const char *path) { - Ecore_File_Monitor *mon; + Eio_Monitor *mon; char *realp = NULL; const char *monpath = path; @@ -505,9 +490,16 @@ desktop_changes_monitor_add(const struct stat *st, const char *path) if (!realp) return; monpath = realp; } - mon = ecore_file_monitor_add(monpath, desktop_changes_cb, NULL); + if (ecore_file_is_dir(monpath)) + { + mon = eio_monitor_add(monpath); + if (mon) + { + eina_hash_add(desktop_change_monitors, path, mon); + eina_hash_add(desktop_change_monitors_mon, &mon, mon); + } + } free(realp); - if (mon) eina_hash_add(desktop_change_monitors, path, mon); } static int @@ -881,68 +873,56 @@ mime_update_cache_cb(void *data EINA_UNUSED) return EINA_FALSE; } -static void -mime_changes_cb(void *data EINA_UNUSED, Ecore_File_Monitor *em EINA_UNUSED, - Ecore_File_Event event, const char *path EINA_UNUSED) -{ - switch (event) - { - case ECORE_FILE_EVENT_NONE: - /* noop */ - break; - - case ECORE_FILE_EVENT_CREATED_FILE: - case ECORE_FILE_EVENT_DELETED_FILE: - case ECORE_FILE_EVENT_MODIFIED: - case ECORE_FILE_EVENT_CLOSED: - case ECORE_FILE_EVENT_DELETED_DIRECTORY: - case ECORE_FILE_EVENT_CREATED_DIRECTORY: - case ECORE_FILE_EVENT_DELETED_SELF: - mime_cache_shutdown(); - mime_cache_init(); - if (mime_update_timer) ecore_timer_del(mime_update_timer); - mime_update_timer = ecore_timer_add(0.2, mime_update_cache_cb, NULL); - break; - } -} - static void mime_cache_init(void) { - Ecore_File_Monitor *mon; + Eio_Monitor *mon; Eina_List *datadirs, *l; const char *s; char buf[PATH_MAX]; - mime_monitors = eina_hash_string_superfast_new(NULL); + mime_monitors = eina_hash_string_superfast_new + (EINA_FREE_CB(eio_monitor_del)); + mime_monitors_mon = eina_hash_pointer_new(NULL); - mon = ecore_file_monitor_add("/etc/mime.types", mime_changes_cb, NULL); - if (mon) eina_hash_add(mime_monitors, "/etc/mime.types", mon); - mon = ecore_file_monitor_add("/usr/share/mime/globs", mime_changes_cb, NULL); - if (mon) eina_hash_add(mime_monitors, "/usr/share/mime/globs", mon); + if (ecore_file_is_dir("/etc")) + { + mon = eio_monitor_add("/etc"); // specifically look at /etc/mime.types + if (mon) + { + eina_hash_add(mime_monitors, "/etc", mon); + eina_hash_add(mime_monitors_mon, &mon, mon); + } + } + if (ecore_file_is_dir("/usr/share/mime")) + { + mon = eio_monitor_add("/usr/share/mime"); // specifically look at /usr/share/mime/globs + if (mon) + { + eina_hash_add(mime_monitors, "/usr/share/mime", mon); + eina_hash_add(mime_monitors_mon, &mon, mon); + } + } datadirs = efreet_data_dirs_get(); EINA_LIST_FOREACH(datadirs, l, s) { - snprintf(buf, sizeof(buf), "%s/mime/globs", s); - if (!eina_hash_find(mime_monitors, buf)) + snprintf(buf, sizeof(buf), "%s/mime", s); // specifically lok at XXX/mime/globs + if (ecore_file_is_dir(buf)) { - mon = ecore_file_monitor_add(buf, mime_changes_cb, NULL); - if (mon) eina_hash_add(mime_monitors, buf, mon); + if (!eina_hash_find(mime_monitors, buf)) + { + mon = eio_monitor_add(buf); + if (mon) + { + eina_hash_add(mime_monitors, buf, mon); + eina_hash_add(mime_monitors_mon, &mon, mon); + } + } } } } -static Eina_Bool -mime_cache_monitor_del(const Eina_Hash *hash EINA_UNUSED, - const void *key EINA_UNUSED, void *value, - void *data EINA_UNUSED) -{ - Ecore_File_Monitor *mon = value; - ecore_file_monitor_del(mon); - return EINA_TRUE; -} - static void mime_cache_shutdown(void) { @@ -953,10 +933,14 @@ mime_cache_shutdown(void) } if (mime_monitors) { - eina_hash_foreach(mime_monitors, mime_cache_monitor_del, NULL); eina_hash_free(mime_monitors); mime_monitors = NULL; } + if (mime_monitors_mon) + { + eina_hash_free(mime_monitors_mon); + mime_monitors_mon = NULL; + } } Eina_Bool @@ -989,12 +973,27 @@ cache_init(void) } icon_change_monitors = eina_hash_string_superfast_new - (EINA_FREE_CB(ecore_file_monitor_del)); + (EINA_FREE_CB(eio_monitor_del)); + icon_change_monitors_mon = eina_hash_pointer_new(NULL); desktop_change_monitors = eina_hash_string_superfast_new - (EINA_FREE_CB(ecore_file_monitor_del)); + (EINA_FREE_CB(eio_monitor_del)); + desktop_change_monitors_mon = eina_hash_pointer_new(NULL); efreet_cache_update = 0; if (!efreet_init()) goto error; + eio_init(); + +#define MONITOR_EVENT(ev, fn) \ +_handlers = eina_list_append(_handlers, ecore_event_handler_add(ev, fn, NULL)) + MONITOR_EVENT(EIO_MONITOR_FILE_CREATED, _cb_monitor_event); + MONITOR_EVENT(EIO_MONITOR_FILE_DELETED, _cb_monitor_event); + MONITOR_EVENT(EIO_MONITOR_FILE_MODIFIED, _cb_monitor_event); + MONITOR_EVENT(EIO_MONITOR_DIRECTORY_CREATED, _cb_monitor_event); + MONITOR_EVENT(EIO_MONITOR_DIRECTORY_DELETED, _cb_monitor_event); + MONITOR_EVENT(EIO_MONITOR_DIRECTORY_MODIFIED, _cb_monitor_event); + MONITOR_EVENT(EIO_MONITOR_SELF_RENAME, _cb_monitor_event); + MONITOR_EVENT(EIO_MONITOR_SELF_DELETED, _cb_monitor_event); + subdir_cache_init(); mime_cache_init(); mime_update_launch(); @@ -1025,6 +1024,7 @@ Eina_Bool cache_shutdown(void) { const char *data; + Ecore_Event_Handler *handler; eina_prefix_free(pfx); pfx = NULL; @@ -1040,8 +1040,12 @@ cache_shutdown(void) if (icon_change_monitors) eina_hash_free(icon_change_monitors); icon_change_monitors = NULL; + if (icon_change_monitors_mon) eina_hash_free(icon_change_monitors_mon); + icon_change_monitors_mon = NULL; if (desktop_change_monitors) eina_hash_free(desktop_change_monitors); desktop_change_monitors = NULL; + if (desktop_change_monitors_mon) eina_hash_free(desktop_change_monitors_mon); + desktop_change_monitors_mon = NULL; EINA_LIST_FREE(desktop_system_dirs, data) eina_stringshare_del(data); EINA_LIST_FREE(desktop_extra_dirs, data) @@ -1050,5 +1054,8 @@ cache_shutdown(void) eina_stringshare_del(data); EINA_LIST_FREE(icon_exts, data) eina_stringshare_del(data); + EINA_LIST_FREE(_handlers, handler) + ecore_event_handler_del(handler); + eio_shutdown(); return EINA_TRUE; }