… | |
… | |
1658 | } |
1658 | } |
1659 | } |
1659 | } |
1660 | |
1660 | |
1661 | #if EV_USE_SIGNALFD |
1661 | #if EV_USE_SIGNALFD |
1662 | if (ev_is_active (&sigfd_w)) |
1662 | if (ev_is_active (&sigfd_w)) |
1663 | { |
|
|
1664 | /*ev_ref (EV_A);*/ |
|
|
1665 | /*ev_io_stop (EV_A_ &sigfd_w);*/ |
|
|
1666 | |
|
|
1667 | close (sigfd); |
1663 | close (sigfd); |
1668 | } |
|
|
1669 | #endif |
1664 | #endif |
1670 | |
1665 | |
1671 | #if EV_USE_INOTIFY |
1666 | #if EV_USE_INOTIFY |
1672 | if (fs_fd >= 0) |
1667 | if (fs_fd >= 0) |
1673 | close (fs_fd); |
1668 | close (fs_fd); |
… | |
… | |
2752 | # if EV_USE_SIGNALFD |
2747 | # if EV_USE_SIGNALFD |
2753 | if (sigfd < 0) /*TODO*/ |
2748 | if (sigfd < 0) /*TODO*/ |
2754 | # endif |
2749 | # endif |
2755 | { |
2750 | { |
2756 | # if _WIN32 |
2751 | # if _WIN32 |
|
|
2752 | evpipe_init (EV_A); |
|
|
2753 | |
2757 | signal (w->signum, ev_sighandler); |
2754 | signal (w->signum, ev_sighandler); |
2758 | # else |
2755 | # else |
2759 | struct sigaction sa; |
2756 | struct sigaction sa; |
2760 | |
2757 | |
2761 | evpipe_init (EV_A); |
2758 | evpipe_init (EV_A); |
… | |
… | |
2859 | static void noinline |
2856 | static void noinline |
2860 | infy_add (EV_P_ ev_stat *w) |
2857 | infy_add (EV_P_ ev_stat *w) |
2861 | { |
2858 | { |
2862 | w->wd = inotify_add_watch (fs_fd, w->path, IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY | IN_DONT_FOLLOW | IN_MASK_ADD); |
2859 | w->wd = inotify_add_watch (fs_fd, w->path, IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY | IN_DONT_FOLLOW | IN_MASK_ADD); |
2863 | |
2860 | |
2864 | if (w->wd < 0) |
2861 | if (w->wd >= 0) |
|
|
2862 | { |
|
|
2863 | struct statfs sfs; |
|
|
2864 | |
|
|
2865 | /* now local changes will be tracked by inotify, but remote changes won't */ |
|
|
2866 | /* unless the filesystem is known to be local, we therefore still poll */ |
|
|
2867 | /* also do poll on <2.6.25, but with normal frequency */ |
|
|
2868 | |
|
|
2869 | if (!fs_2625) |
|
|
2870 | w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; |
|
|
2871 | else if (!statfs (w->path, &sfs) |
|
|
2872 | && (sfs.f_type == 0x1373 /* devfs */ |
|
|
2873 | || sfs.f_type == 0xEF53 /* ext2/3 */ |
|
|
2874 | || sfs.f_type == 0x3153464a /* jfs */ |
|
|
2875 | || sfs.f_type == 0x52654973 /* reiser3 */ |
|
|
2876 | || sfs.f_type == 0x01021994 /* tempfs */ |
|
|
2877 | || sfs.f_type == 0x58465342 /* xfs */)) |
|
|
2878 | w->timer.repeat = 0.; /* filesystem is local, kernel new enough */ |
|
|
2879 | else |
|
|
2880 | w->timer.repeat = w->interval ? w->interval : NFS_STAT_INTERVAL; /* remote, use reduced frequency */ |
2865 | { |
2881 | } |
|
|
2882 | else |
|
|
2883 | { |
|
|
2884 | /* can't use inotify, continue to stat */ |
2866 | w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; |
2885 | w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; |
2867 | ev_timer_again (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ |
|
|
2868 | |
2886 | |
2869 | /* monitor some parent directory for speedup hints */ |
2887 | /* if path is not there, monitor some parent directory for speedup hints */ |
2870 | /* note that exceeding the hardcoded path limit is not a correctness issue, */ |
2888 | /* note that exceeding the hardcoded path limit is not a correctness issue, */ |
2871 | /* but an efficiency issue only */ |
2889 | /* but an efficiency issue only */ |
2872 | if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) |
2890 | if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) |
2873 | { |
2891 | { |
2874 | char path [4096]; |
2892 | char path [4096]; |
… | |
… | |
2890 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2908 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2891 | } |
2909 | } |
2892 | } |
2910 | } |
2893 | |
2911 | |
2894 | if (w->wd >= 0) |
2912 | if (w->wd >= 0) |
2895 | { |
|
|
2896 | struct statfs sfs; |
|
|
2897 | |
|
|
2898 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2913 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2899 | |
2914 | |
2900 | /* now local changes will be tracked by inotify, but remote changes won't */ |
2915 | /* now re-arm timer, if required */ |
2901 | /* unless the filesystem it known to be local, we therefore still poll */ |
2916 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
2902 | /* also do poll on <2.6.25, but with normal frequency */ |
|
|
2903 | |
|
|
2904 | if (fs_2625 && !statfs (w->path, &sfs)) |
|
|
2905 | if (sfs.f_type == 0x1373 /* devfs */ |
|
|
2906 | || sfs.f_type == 0xEF53 /* ext2/3 */ |
|
|
2907 | || sfs.f_type == 0x3153464a /* jfs */ |
|
|
2908 | || sfs.f_type == 0x52654973 /* reiser3 */ |
|
|
2909 | || sfs.f_type == 0x01021994 /* tempfs */ |
|
|
2910 | || sfs.f_type == 0x58465342 /* xfs */) |
|
|
2911 | return; |
|
|
2912 | |
|
|
2913 | w->timer.repeat = w->interval ? w->interval : fs_2625 ? NFS_STAT_INTERVAL : DEF_STAT_INTERVAL; |
|
|
2914 | ev_timer_again (EV_A_ &w->timer); |
2917 | ev_timer_again (EV_A_ &w->timer); |
2915 | } |
2918 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
2916 | } |
2919 | } |
2917 | |
2920 | |
2918 | static void noinline |
2921 | static void noinline |
2919 | infy_del (EV_P_ ev_stat *w) |
2922 | infy_del (EV_P_ ev_stat *w) |
2920 | { |
2923 | { |
… | |
… | |
3025 | { |
3028 | { |
3026 | fd_intern (fs_fd); |
3029 | fd_intern (fs_fd); |
3027 | ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ); |
3030 | ev_io_init (&fs_w, infy_cb, fs_fd, EV_READ); |
3028 | ev_set_priority (&fs_w, EV_MAXPRI); |
3031 | ev_set_priority (&fs_w, EV_MAXPRI); |
3029 | ev_io_start (EV_A_ &fs_w); |
3032 | ev_io_start (EV_A_ &fs_w); |
|
|
3033 | ev_unref (EV_A); |
3030 | } |
3034 | } |
3031 | } |
3035 | } |
3032 | |
3036 | |
3033 | inline_size void |
3037 | inline_size void |
3034 | infy_fork (EV_P) |
3038 | infy_fork (EV_P) |
… | |
… | |
3036 | int slot; |
3040 | int slot; |
3037 | |
3041 | |
3038 | if (fs_fd < 0) |
3042 | if (fs_fd < 0) |
3039 | return; |
3043 | return; |
3040 | |
3044 | |
|
|
3045 | ev_ref (EV_A); |
3041 | ev_io_stop (EV_A_ &fs_w); |
3046 | ev_io_stop (EV_A_ &fs_w); |
3042 | close (fs_fd); |
3047 | close (fs_fd); |
3043 | fs_fd = infy_newfd (); |
3048 | fs_fd = infy_newfd (); |
3044 | |
3049 | |
3045 | if (fs_fd >= 0) |
3050 | if (fs_fd >= 0) |
3046 | { |
3051 | { |
3047 | fd_intern (fs_fd); |
3052 | fd_intern (fs_fd); |
3048 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3053 | ev_io_set (&fs_w, fs_fd, EV_READ); |
3049 | ev_io_start (EV_A_ &fs_w); |
3054 | ev_io_start (EV_A_ &fs_w); |
|
|
3055 | ev_unref (EV_A); |
3050 | } |
3056 | } |
3051 | |
3057 | |
3052 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3058 | for (slot = 0; slot < EV_INOTIFY_HASHSIZE; ++slot) |
3053 | { |
3059 | { |
3054 | WL w_ = fs_hash [slot].head; |
3060 | WL w_ = fs_hash [slot].head; |
… | |
… | |
3062 | w->wd = -1; |
3068 | w->wd = -1; |
3063 | |
3069 | |
3064 | if (fs_fd >= 0) |
3070 | if (fs_fd >= 0) |
3065 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3071 | infy_add (EV_A_ w); /* re-add, no matter what */ |
3066 | else |
3072 | else |
|
|
3073 | { |
|
|
3074 | w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; |
|
|
3075 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
3067 | ev_timer_again (EV_A_ &w->timer); |
3076 | ev_timer_again (EV_A_ &w->timer); |
|
|
3077 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
|
|
3078 | } |
3068 | } |
3079 | } |
3069 | } |
3080 | } |
3070 | } |
3081 | } |
3071 | |
3082 | |
3072 | #endif |
3083 | #endif |
… | |
… | |
3142 | |
3153 | |
3143 | if (fs_fd >= 0) |
3154 | if (fs_fd >= 0) |
3144 | infy_add (EV_A_ w); |
3155 | infy_add (EV_A_ w); |
3145 | else |
3156 | else |
3146 | #endif |
3157 | #endif |
|
|
3158 | { |
3147 | ev_timer_again (EV_A_ &w->timer); |
3159 | ev_timer_again (EV_A_ &w->timer); |
|
|
3160 | ev_unref (EV_A); |
|
|
3161 | } |
3148 | |
3162 | |
3149 | ev_start (EV_A_ (W)w, 1); |
3163 | ev_start (EV_A_ (W)w, 1); |
3150 | |
3164 | |
3151 | EV_FREQUENT_CHECK; |
3165 | EV_FREQUENT_CHECK; |
3152 | } |
3166 | } |
… | |
… | |
3161 | EV_FREQUENT_CHECK; |
3175 | EV_FREQUENT_CHECK; |
3162 | |
3176 | |
3163 | #if EV_USE_INOTIFY |
3177 | #if EV_USE_INOTIFY |
3164 | infy_del (EV_A_ w); |
3178 | infy_del (EV_A_ w); |
3165 | #endif |
3179 | #endif |
|
|
3180 | |
|
|
3181 | if (ev_is_active (&w->timer)) |
|
|
3182 | { |
|
|
3183 | ev_ref (EV_A); |
3166 | ev_timer_stop (EV_A_ &w->timer); |
3184 | ev_timer_stop (EV_A_ &w->timer); |
|
|
3185 | } |
3167 | |
3186 | |
3168 | ev_stop (EV_A_ (W)w); |
3187 | ev_stop (EV_A_ (W)w); |
3169 | |
3188 | |
3170 | EV_FREQUENT_CHECK; |
3189 | EV_FREQUENT_CHECK; |
3171 | } |
3190 | } |