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