summaryrefslogtreecommitdiff
path: root/src/bin/efreet/efreetd_cache.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-04-23 10:33:41 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-04-23 21:17:40 +0900
commitd9ad9b585a7e3bec43114400cd6c7d3be94cc81b (patch)
treef963a2d33d56a7f5c4b34991cf78e719f61d39ed /src/bin/efreet/efreetd_cache.c
parent3041b80b8bd89087e9aaa7530cc2b453dfdd3fd4 (diff)
efreetd - make efreetd use eio and not ecore_file_monitor for monitoring
this should fix T5130 - freebsd's efreetd polling regularly @fix
Diffstat (limited to 'src/bin/efreet/efreetd_cache.c')
-rw-r--r--src/bin/efreet/efreetd_cache.c227
1 files changed, 117 insertions, 110 deletions
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 @@
5#include <Eina.h> 5#include <Eina.h>
6#include <Ecore.h> 6#include <Ecore.h>
7#include <Ecore_File.h> 7#include <Ecore_File.h>
8#include <Eio.h>
8#include <Eet.h> 9#include <Eet.h>
9#include "efreetd.h" 10#include "efreetd.h"
10#include "efreetd_ipc.h" 11#include "efreetd_ipc.h"
@@ -19,7 +20,9 @@
19#include <unistd.h> 20#include <unistd.h>
20 21
21static Eina_Hash *icon_change_monitors = NULL; 22static Eina_Hash *icon_change_monitors = NULL;
23static Eina_Hash *icon_change_monitors_mon = NULL;
22static Eina_Hash *desktop_change_monitors = NULL; 24static Eina_Hash *desktop_change_monitors = NULL;
25static Eina_Hash *desktop_change_monitors_mon = NULL;
23 26
24static Ecore_Event_Handler *cache_exe_del_handler = NULL; 27static Ecore_Event_Handler *cache_exe_del_handler = NULL;
25static Ecore_Event_Handler *cache_exe_data_handler = NULL; 28static Ecore_Event_Handler *cache_exe_data_handler = NULL;
@@ -40,6 +43,8 @@ static Eina_Bool icon_flush = EINA_FALSE;
40static Eina_Bool desktop_queue = EINA_FALSE; 43static Eina_Bool desktop_queue = EINA_FALSE;
41static Eina_Bool icon_queue = EINA_FALSE; 44static Eina_Bool icon_queue = EINA_FALSE;
42 45
46static Eina_List *_handlers = NULL;
47
43static void icon_changes_listen(void); 48static void icon_changes_listen(void);
44static void desktop_changes_listen(void); 49static void desktop_changes_listen(void);
45 50
@@ -72,11 +77,13 @@ static Subdir_Cache *subdir_cache = NULL;
72static Eina_Bool subdir_need_save = EINA_FALSE; 77static Eina_Bool subdir_need_save = EINA_FALSE;
73 78
74static Eina_Hash *mime_monitors = NULL; 79static Eina_Hash *mime_monitors = NULL;
80static Eina_Hash *mime_monitors_mon = NULL;
75static Ecore_Timer *mime_update_timer = NULL; 81static Ecore_Timer *mime_update_timer = NULL;
76static Ecore_Exe *mime_cache_exe = NULL; 82static Ecore_Exe *mime_cache_exe = NULL;
77 83
78static void mime_cache_init(void); 84static void mime_cache_init(void);
79static void mime_cache_shutdown(void); 85static void mime_cache_shutdown(void);
86static Eina_Bool mime_update_cache_cb(void *data EINA_UNUSED);
80 87
81static void 88static void
82subdir_cache_dir_free(Subdir_Cache_Dir *cd) 89subdir_cache_dir_free(Subdir_Cache_Dir *cd)
@@ -310,8 +317,10 @@ icon_cache_update_cache_cb(void *data EINA_UNUSED)
310 if ((!icon_flush) && (!icon_exts)) return ECORE_CALLBACK_CANCEL; 317 if ((!icon_flush) && (!icon_exts)) return ECORE_CALLBACK_CANCEL;
311 318
312 if (icon_change_monitors) eina_hash_free(icon_change_monitors); 319 if (icon_change_monitors) eina_hash_free(icon_change_monitors);
320 if (icon_change_monitors_mon) eina_hash_free(icon_change_monitors_mon);
313 icon_change_monitors = eina_hash_string_superfast_new 321 icon_change_monitors = eina_hash_string_superfast_new
314 (EINA_FREE_CB(ecore_file_monitor_del)); 322 (EINA_FREE_CB(eio_monitor_del));
323 icon_change_monitors_mon = eina_hash_pointer_new(NULL);
315 icon_changes_listen(); 324 icon_changes_listen();
316 subdir_cache_save(); 325 subdir_cache_save();
317 326
@@ -367,8 +376,10 @@ desktop_cache_update_cache_cb(void *data EINA_UNUSED)
367 desktop_queue = EINA_FALSE; 376 desktop_queue = EINA_FALSE;
368 377
369 if (desktop_change_monitors) eina_hash_free(desktop_change_monitors); 378 if (desktop_change_monitors) eina_hash_free(desktop_change_monitors);
379 if (desktop_change_monitors_mon) eina_hash_free(desktop_change_monitors_mon);
370 desktop_change_monitors = eina_hash_string_superfast_new 380 desktop_change_monitors = eina_hash_string_superfast_new
371 (EINA_FREE_CB(ecore_file_monitor_del)); 381 (EINA_FREE_CB(eio_monitor_del));
382 desktop_change_monitors_mon = eina_hash_pointer_new(NULL);
372 desktop_changes_listen(); 383 desktop_changes_listen();
373 subdir_cache_save(); 384 subdir_cache_save();
374 385
@@ -409,73 +420,40 @@ cache_desktop_update(void)
409 desktop_cache_timer = ecore_timer_add(0.2, desktop_cache_update_cache_cb, NULL); 420 desktop_cache_timer = ecore_timer_add(0.2, desktop_cache_update_cache_cb, NULL);
410} 421}
411 422
412static void 423static Eina_Bool
413icon_changes_cb(void *data EINA_UNUSED, Ecore_File_Monitor *em EINA_UNUSED, 424_cb_monitor_event(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
414 Ecore_File_Event event, const char *path EINA_UNUSED)
415{ 425{
416 switch (event) 426 Eio_Monitor_Event *ev = event;
417 {
418 case ECORE_FILE_EVENT_NONE:
419 /* noop */
420 break;
421
422 case ECORE_FILE_EVENT_CREATED_FILE:
423 case ECORE_FILE_EVENT_DELETED_FILE:
424 case ECORE_FILE_EVENT_MODIFIED:
425 case ECORE_FILE_EVENT_CLOSED:
426 // a FILE was changed, added or removed
427 cache_icon_update(EINA_FALSE);
428 break;
429
430 case ECORE_FILE_EVENT_DELETED_DIRECTORY:
431 case ECORE_FILE_EVENT_CREATED_DIRECTORY:
432 // the whole tree needs re-monitoring
433 cache_icon_update(EINA_FALSE);
434 break;
435 427
436 case ECORE_FILE_EVENT_DELETED_SELF: 428 // if it's an icon
437 // the whole tree needs re-monitoring 429 if (eina_hash_find(icon_change_monitors_mon, &(ev->monitor)))
430 {
438 cache_icon_update(EINA_FALSE); 431 cache_icon_update(EINA_FALSE);
439 break;
440 } 432 }
441} 433 // if it's a desktop
442 434 else if (eina_hash_find(desktop_change_monitors_mon, &(ev->monitor)))
443static void
444desktop_changes_cb(void *data EINA_UNUSED, Ecore_File_Monitor *em EINA_UNUSED,
445 Ecore_File_Event event, const char *path EINA_UNUSED)
446{
447 /* TODO: Check for desktop*.cache, as this will be created when app is installed */
448 switch (event)
449 { 435 {
450 case ECORE_FILE_EVENT_NONE:
451 /* noop */
452 break;
453
454 case ECORE_FILE_EVENT_CREATED_FILE:
455 case ECORE_FILE_EVENT_DELETED_FILE:
456 case ECORE_FILE_EVENT_MODIFIED:
457 case ECORE_FILE_EVENT_CLOSED:
458 // a FILE was changed, added or removed
459 cache_desktop_update();
460 break;
461
462 case ECORE_FILE_EVENT_DELETED_DIRECTORY:
463 case ECORE_FILE_EVENT_CREATED_DIRECTORY:
464 // the whole tree needs re-monitoring
465 cache_desktop_update();
466 break;
467
468 case ECORE_FILE_EVENT_DELETED_SELF:
469 // the whole tree needs re-monitoring
470 cache_desktop_update(); 436 cache_desktop_update();
471 break;
472 } 437 }
438 // if it's a mime file
439 else if (eina_hash_find(mime_monitors_mon, &(ev->monitor)))
440 {
441 if ((!strcmp("/etc/mime.types", ev->filename)) ||
442 (!strcmp("globs", ecore_file_file_get(ev->filename))))
443 {
444 mime_cache_shutdown();
445 mime_cache_init();
446 if (mime_update_timer) ecore_timer_del(mime_update_timer);
447 mime_update_timer = ecore_timer_add(0.2, mime_update_cache_cb, NULL);
448 }
449 }
450 return ECORE_CALLBACK_PASS_ON;
473} 451}
474 452
475static void 453static void
476icon_changes_monitor_add(const struct stat *st, const char *path) 454icon_changes_monitor_add(const struct stat *st, const char *path)
477{ 455{
478 Ecore_File_Monitor *mon; 456 Eio_Monitor *mon;
479 char *realp = NULL; 457 char *realp = NULL;
480 const char *monpath = path; 458 const char *monpath = path;
481 459
@@ -486,15 +464,22 @@ icon_changes_monitor_add(const struct stat *st, const char *path)
486 if (!realp) return; 464 if (!realp) return;
487 monpath = realp; 465 monpath = realp;
488 } 466 }
489 mon = ecore_file_monitor_add(monpath, icon_changes_cb, NULL); 467 if (ecore_file_is_dir(monpath))
468 {
469 mon = eio_monitor_add(monpath);
470 if (mon)
471 {
472 eina_hash_add(icon_change_monitors, path, mon);
473 eina_hash_add(icon_change_monitors_mon, &mon, mon);
474 }
475 }
490 free(realp); 476 free(realp);
491 if (mon) eina_hash_add(icon_change_monitors, path, mon);
492} 477}
493 478
494static void 479static void
495desktop_changes_monitor_add(const struct stat *st, const char *path) 480desktop_changes_monitor_add(const struct stat *st, const char *path)
496{ 481{
497 Ecore_File_Monitor *mon; 482 Eio_Monitor *mon;
498 char *realp = NULL; 483 char *realp = NULL;
499 const char *monpath = path; 484 const char *monpath = path;
500 485
@@ -505,9 +490,16 @@ desktop_changes_monitor_add(const struct stat *st, const char *path)
505 if (!realp) return; 490 if (!realp) return;
506 monpath = realp; 491 monpath = realp;
507 } 492 }
508 mon = ecore_file_monitor_add(monpath, desktop_changes_cb, NULL); 493 if (ecore_file_is_dir(monpath))
494 {
495 mon = eio_monitor_add(monpath);
496 if (mon)
497 {
498 eina_hash_add(desktop_change_monitors, path, mon);
499 eina_hash_add(desktop_change_monitors_mon, &mon, mon);
500 }
501 }
509 free(realp); 502 free(realp);
510 if (mon) eina_hash_add(desktop_change_monitors, path, mon);
511} 503}
512 504
513static int 505static int
@@ -882,67 +874,55 @@ mime_update_cache_cb(void *data EINA_UNUSED)
882} 874}
883 875
884static void 876static void
885mime_changes_cb(void *data EINA_UNUSED, Ecore_File_Monitor *em EINA_UNUSED,
886 Ecore_File_Event event, const char *path EINA_UNUSED)
887{
888 switch (event)
889 {
890 case ECORE_FILE_EVENT_NONE:
891 /* noop */
892 break;
893
894 case ECORE_FILE_EVENT_CREATED_FILE:
895 case ECORE_FILE_EVENT_DELETED_FILE:
896 case ECORE_FILE_EVENT_MODIFIED:
897 case ECORE_FILE_EVENT_CLOSED:
898 case ECORE_FILE_EVENT_DELETED_DIRECTORY:
899 case ECORE_FILE_EVENT_CREATED_DIRECTORY:
900 case ECORE_FILE_EVENT_DELETED_SELF:
901 mime_cache_shutdown();
902 mime_cache_init();
903 if (mime_update_timer) ecore_timer_del(mime_update_timer);
904 mime_update_timer = ecore_timer_add(0.2, mime_update_cache_cb, NULL);
905 break;
906 }
907}
908
909static void
910mime_cache_init(void) 877mime_cache_init(void)
911{ 878{
912 Ecore_File_Monitor *mon; 879 Eio_Monitor *mon;
913 Eina_List *datadirs, *l; 880 Eina_List *datadirs, *l;
914 const char *s; 881 const char *s;
915 char buf[PATH_MAX]; 882 char buf[PATH_MAX];
916 883
917 mime_monitors = eina_hash_string_superfast_new(NULL); 884 mime_monitors = eina_hash_string_superfast_new
885 (EINA_FREE_CB(eio_monitor_del));
886 mime_monitors_mon = eina_hash_pointer_new(NULL);
918 887
919 mon = ecore_file_monitor_add("/etc/mime.types", mime_changes_cb, NULL); 888 if (ecore_file_is_dir("/etc"))
920 if (mon) eina_hash_add(mime_monitors, "/etc/mime.types", mon); 889 {
921 mon = ecore_file_monitor_add("/usr/share/mime/globs", mime_changes_cb, NULL); 890 mon = eio_monitor_add("/etc"); // specifically look at /etc/mime.types
922 if (mon) eina_hash_add(mime_monitors, "/usr/share/mime/globs", mon); 891 if (mon)
892 {
893 eina_hash_add(mime_monitors, "/etc", mon);
894 eina_hash_add(mime_monitors_mon, &mon, mon);
895 }
896 }
897 if (ecore_file_is_dir("/usr/share/mime"))
898 {
899 mon = eio_monitor_add("/usr/share/mime"); // specifically look at /usr/share/mime/globs
900 if (mon)
901 {
902 eina_hash_add(mime_monitors, "/usr/share/mime", mon);
903 eina_hash_add(mime_monitors_mon, &mon, mon);
904 }
905 }
923 906
924 datadirs = efreet_data_dirs_get(); 907 datadirs = efreet_data_dirs_get();
925 EINA_LIST_FOREACH(datadirs, l, s) 908 EINA_LIST_FOREACH(datadirs, l, s)
926 { 909 {
927 snprintf(buf, sizeof(buf), "%s/mime/globs", s); 910 snprintf(buf, sizeof(buf), "%s/mime", s); // specifically lok at XXX/mime/globs
928 if (!eina_hash_find(mime_monitors, buf)) 911 if (ecore_file_is_dir(buf))
929 { 912 {
930 mon = ecore_file_monitor_add(buf, mime_changes_cb, NULL); 913 if (!eina_hash_find(mime_monitors, buf))
931 if (mon) eina_hash_add(mime_monitors, buf, mon); 914 {
915 mon = eio_monitor_add(buf);
916 if (mon)
917 {
918 eina_hash_add(mime_monitors, buf, mon);
919 eina_hash_add(mime_monitors_mon, &mon, mon);
920 }
921 }
932 } 922 }
933 } 923 }
934} 924}
935 925
936static Eina_Bool
937mime_cache_monitor_del(const Eina_Hash *hash EINA_UNUSED,
938 const void *key EINA_UNUSED, void *value,
939 void *data EINA_UNUSED)
940{
941 Ecore_File_Monitor *mon = value;
942 ecore_file_monitor_del(mon);
943 return EINA_TRUE;
944}
945
946static void 926static void
947mime_cache_shutdown(void) 927mime_cache_shutdown(void)
948{ 928{
@@ -953,10 +933,14 @@ mime_cache_shutdown(void)
953 } 933 }
954 if (mime_monitors) 934 if (mime_monitors)
955 { 935 {
956 eina_hash_foreach(mime_monitors, mime_cache_monitor_del, NULL);
957 eina_hash_free(mime_monitors); 936 eina_hash_free(mime_monitors);
958 mime_monitors = NULL; 937 mime_monitors = NULL;
959 } 938 }
939 if (mime_monitors_mon)
940 {
941 eina_hash_free(mime_monitors_mon);
942 mime_monitors_mon = NULL;
943 }
960} 944}
961 945
962Eina_Bool 946Eina_Bool
@@ -989,12 +973,27 @@ cache_init(void)
989 } 973 }
990 974
991 icon_change_monitors = eina_hash_string_superfast_new 975 icon_change_monitors = eina_hash_string_superfast_new
992 (EINA_FREE_CB(ecore_file_monitor_del)); 976 (EINA_FREE_CB(eio_monitor_del));
977 icon_change_monitors_mon = eina_hash_pointer_new(NULL);
993 desktop_change_monitors = eina_hash_string_superfast_new 978 desktop_change_monitors = eina_hash_string_superfast_new
994 (EINA_FREE_CB(ecore_file_monitor_del)); 979 (EINA_FREE_CB(eio_monitor_del));
980 desktop_change_monitors_mon = eina_hash_pointer_new(NULL);
995 981
996 efreet_cache_update = 0; 982 efreet_cache_update = 0;
997 if (!efreet_init()) goto error; 983 if (!efreet_init()) goto error;
984 eio_init();
985
986#define MONITOR_EVENT(ev, fn) \
987_handlers = eina_list_append(_handlers, ecore_event_handler_add(ev, fn, NULL))
988 MONITOR_EVENT(EIO_MONITOR_FILE_CREATED, _cb_monitor_event);
989 MONITOR_EVENT(EIO_MONITOR_FILE_DELETED, _cb_monitor_event);
990 MONITOR_EVENT(EIO_MONITOR_FILE_MODIFIED, _cb_monitor_event);
991 MONITOR_EVENT(EIO_MONITOR_DIRECTORY_CREATED, _cb_monitor_event);
992 MONITOR_EVENT(EIO_MONITOR_DIRECTORY_DELETED, _cb_monitor_event);
993 MONITOR_EVENT(EIO_MONITOR_DIRECTORY_MODIFIED, _cb_monitor_event);
994 MONITOR_EVENT(EIO_MONITOR_SELF_RENAME, _cb_monitor_event);
995 MONITOR_EVENT(EIO_MONITOR_SELF_DELETED, _cb_monitor_event);
996
998 subdir_cache_init(); 997 subdir_cache_init();
999 mime_cache_init(); 998 mime_cache_init();
1000 mime_update_launch(); 999 mime_update_launch();
@@ -1025,6 +1024,7 @@ Eina_Bool
1025cache_shutdown(void) 1024cache_shutdown(void)
1026{ 1025{
1027 const char *data; 1026 const char *data;
1027 Ecore_Event_Handler *handler;
1028 1028
1029 eina_prefix_free(pfx); 1029 eina_prefix_free(pfx);
1030 pfx = NULL; 1030 pfx = NULL;
@@ -1040,8 +1040,12 @@ cache_shutdown(void)
1040 1040
1041 if (icon_change_monitors) eina_hash_free(icon_change_monitors); 1041 if (icon_change_monitors) eina_hash_free(icon_change_monitors);
1042 icon_change_monitors = NULL; 1042 icon_change_monitors = NULL;
1043 if (icon_change_monitors_mon) eina_hash_free(icon_change_monitors_mon);
1044 icon_change_monitors_mon = NULL;
1043 if (desktop_change_monitors) eina_hash_free(desktop_change_monitors); 1045 if (desktop_change_monitors) eina_hash_free(desktop_change_monitors);
1044 desktop_change_monitors = NULL; 1046 desktop_change_monitors = NULL;
1047 if (desktop_change_monitors_mon) eina_hash_free(desktop_change_monitors_mon);
1048 desktop_change_monitors_mon = NULL;
1045 EINA_LIST_FREE(desktop_system_dirs, data) 1049 EINA_LIST_FREE(desktop_system_dirs, data)
1046 eina_stringshare_del(data); 1050 eina_stringshare_del(data);
1047 EINA_LIST_FREE(desktop_extra_dirs, data) 1051 EINA_LIST_FREE(desktop_extra_dirs, data)
@@ -1050,5 +1054,8 @@ cache_shutdown(void)
1050 eina_stringshare_del(data); 1054 eina_stringshare_del(data);
1051 EINA_LIST_FREE(icon_exts, data) 1055 EINA_LIST_FREE(icon_exts, data)
1052 eina_stringshare_del(data); 1056 eina_stringshare_del(data);
1057 EINA_LIST_FREE(_handlers, handler)
1058 ecore_event_handler_del(handler);
1059 eio_shutdown();
1053 return EINA_TRUE; 1060 return EINA_TRUE;
1054} 1061}