… | |
… | |
47 | # include EV_CONFIG_H |
47 | # include EV_CONFIG_H |
48 | # else |
48 | # else |
49 | # include "config.h" |
49 | # include "config.h" |
50 | # endif |
50 | # endif |
51 | |
51 | |
|
|
52 | # if HAVE_CLOCK_SYSCALL |
|
|
53 | # ifndef EV_USE_CLOCK_SYSCALL |
|
|
54 | # define EV_USE_CLOCK_SYSCALL 1 |
|
|
55 | # ifndef EV_USE_REALTIME |
|
|
56 | # define EV_USE_REALTIME 0 |
|
|
57 | # endif |
|
|
58 | # ifndef EV_USE_MONOTONIC |
|
|
59 | # define EV_USE_MONOTONIC 1 |
|
|
60 | # endif |
|
|
61 | # endif |
|
|
62 | # endif |
|
|
63 | |
52 | # if HAVE_CLOCK_GETTIME |
64 | # if HAVE_CLOCK_GETTIME |
53 | # ifndef EV_USE_MONOTONIC |
65 | # ifndef EV_USE_MONOTONIC |
54 | # define EV_USE_MONOTONIC 1 |
66 | # define EV_USE_MONOTONIC 1 |
55 | # endif |
67 | # endif |
56 | # ifndef EV_USE_REALTIME |
68 | # ifndef EV_USE_REALTIME |
… | |
… | |
164 | # endif |
176 | # endif |
165 | #endif |
177 | #endif |
166 | |
178 | |
167 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
179 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
168 | |
180 | |
|
|
181 | #ifndef EV_USE_CLOCK_SYSCALL |
|
|
182 | # if __linux && __GLIBC__ >= 2 |
|
|
183 | # define EV_USE_CLOCK_SYSCALL 1 |
|
|
184 | # else |
|
|
185 | # define EV_USE_CLOCK_SYSCALL 0 |
|
|
186 | # endif |
|
|
187 | #endif |
|
|
188 | |
169 | #ifndef EV_USE_MONOTONIC |
189 | #ifndef EV_USE_MONOTONIC |
170 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
190 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
171 | # define EV_USE_MONOTONIC 1 |
191 | # define EV_USE_MONOTONIC 1 |
172 | # else |
192 | # else |
173 | # define EV_USE_MONOTONIC 0 |
193 | # define EV_USE_MONOTONIC 0 |
… | |
… | |
287 | # endif |
307 | # endif |
288 | #endif |
308 | #endif |
289 | |
309 | |
290 | #if EV_USE_INOTIFY |
310 | #if EV_USE_INOTIFY |
291 | # include <sys/utsname.h> |
311 | # include <sys/utsname.h> |
|
|
312 | # include <sys/statfs.h> |
292 | # include <sys/inotify.h> |
313 | # include <sys/inotify.h> |
293 | /* some very old inotify.h headers don't have IN_DONT_FOLLOW */ |
314 | /* some very old inotify.h headers don't have IN_DONT_FOLLOW */ |
294 | # ifndef IN_DONT_FOLLOW |
315 | # ifndef IN_DONT_FOLLOW |
295 | # undef EV_USE_INOTIFY |
316 | # undef EV_USE_INOTIFY |
296 | # define EV_USE_INOTIFY 0 |
317 | # define EV_USE_INOTIFY 0 |
297 | # endif |
318 | # endif |
298 | #endif |
319 | #endif |
299 | |
320 | |
300 | #if EV_SELECT_IS_WINSOCKET |
321 | #if EV_SELECT_IS_WINSOCKET |
301 | # include <winsock.h> |
322 | # include <winsock.h> |
|
|
323 | #endif |
|
|
324 | |
|
|
325 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
|
|
326 | /* which makes programs even slower. might work on other unices, too. */ |
|
|
327 | #if EV_USE_CLOCK_SYSCALL |
|
|
328 | # include <syscall.h> |
|
|
329 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
|
|
330 | # undef EV_USE_MONOTONIC |
|
|
331 | # define EV_USE_MONOTONIC 1 |
302 | #endif |
332 | #endif |
303 | |
333 | |
304 | #if EV_USE_EVENTFD |
334 | #if EV_USE_EVENTFD |
305 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
335 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
306 | # include <stdint.h> |
336 | # include <stdint.h> |
… | |
… | |
1659 | { |
1689 | { |
1660 | #if EV_MULTIPLICITY |
1690 | #if EV_MULTIPLICITY |
1661 | struct ev_loop *loop = ev_default_loop_ptr; |
1691 | struct ev_loop *loop = ev_default_loop_ptr; |
1662 | #endif |
1692 | #endif |
1663 | |
1693 | |
1664 | ev_loop_fork (EV_A); |
1694 | postfork = 1; /* must be in line with ev_loop_fork */ |
1665 | } |
1695 | } |
1666 | |
1696 | |
1667 | /*****************************************************************************/ |
1697 | /*****************************************************************************/ |
1668 | |
1698 | |
1669 | void |
1699 | void |
… | |
… | |
2414 | # ifdef _WIN32 |
2444 | # ifdef _WIN32 |
2415 | # undef lstat |
2445 | # undef lstat |
2416 | # define lstat(a,b) _stati64 (a,b) |
2446 | # define lstat(a,b) _stati64 (a,b) |
2417 | # endif |
2447 | # endif |
2418 | |
2448 | |
2419 | #define DEF_STAT_INTERVAL 5.0074891 |
2449 | #define DEF_STAT_INTERVAL 5.0074891 |
|
|
2450 | #define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ |
2420 | #define MIN_STAT_INTERVAL 0.1074891 |
2451 | #define MIN_STAT_INTERVAL 0.1074891 |
2421 | |
2452 | |
2422 | static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
2453 | static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
2423 | |
2454 | |
2424 | #if EV_USE_INOTIFY |
2455 | #if EV_USE_INOTIFY |
2425 | # define EV_INOTIFY_BUFSIZE 8192 |
2456 | # define EV_INOTIFY_BUFSIZE 8192 |
… | |
… | |
2429 | { |
2460 | { |
2430 | 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); |
2461 | 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); |
2431 | |
2462 | |
2432 | if (w->wd < 0) |
2463 | if (w->wd < 0) |
2433 | { |
2464 | { |
|
|
2465 | w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; |
2434 | ev_timer_start (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ |
2466 | ev_timer_again (EV_A_ &w->timer); /* this is not race-free, so we still need to recheck periodically */ |
2435 | |
2467 | |
2436 | /* monitor some parent directory for speedup hints */ |
2468 | /* monitor some parent directory for speedup hints */ |
2437 | /* note that exceeding the hardcoded limit is not a correctness issue, */ |
2469 | /* note that exceeding the hardcoded path limit is not a correctness issue, */ |
2438 | /* but an efficiency issue only */ |
2470 | /* but an efficiency issue only */ |
2439 | if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) |
2471 | if ((errno == ENOENT || errno == EACCES) && strlen (w->path) < 4096) |
2440 | { |
2472 | { |
2441 | char path [4096]; |
2473 | char path [4096]; |
2442 | strcpy (path, w->path); |
2474 | strcpy (path, w->path); |
… | |
… | |
2456 | } |
2488 | } |
2457 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2489 | while (w->wd < 0 && (errno == ENOENT || errno == EACCES)); |
2458 | } |
2490 | } |
2459 | } |
2491 | } |
2460 | else |
2492 | else |
2461 | ev_timer_stop (EV_A_ &w->timer); /* we can watch this in a race-free way */ |
2493 | { |
2462 | |
|
|
2463 | if (w->wd >= 0) |
|
|
2464 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
2494 | wlist_add (&fs_hash [w->wd & (EV_INOTIFY_HASHSIZE - 1)].head, (WL)w); |
|
|
2495 | |
|
|
2496 | /* now local changes will be tracked by inotify, but remote changes won't */ |
|
|
2497 | /* unless the filesystem it known to be local, we therefore still poll */ |
|
|
2498 | /* also do poll on <2.6.25, but with normal frequency */ |
|
|
2499 | struct statfs sfs; |
|
|
2500 | |
|
|
2501 | if (fs_2625 && !statfs (w->path, &sfs)) |
|
|
2502 | if (sfs.f_type == 0x1373 /* devfs */ |
|
|
2503 | || sfs.f_type == 0xEF53 /* ext2/3 */ |
|
|
2504 | || sfs.f_type == 0x3153464a /* jfs */ |
|
|
2505 | || sfs.f_type == 0x52654973 /* reiser3 */ |
|
|
2506 | || sfs.f_type == 0x01021994 /* tempfs */ |
|
|
2507 | || sfs.f_type == 0x58465342 /* xfs */) |
|
|
2508 | return; |
|
|
2509 | |
|
|
2510 | w->timer.repeat = w->interval ? w->interval : fs_2625 ? NFS_STAT_INTERVAL : DEF_STAT_INTERVAL; |
|
|
2511 | ev_timer_again (EV_A_ &w->timer); |
|
|
2512 | } |
2465 | } |
2513 | } |
2466 | |
2514 | |
2467 | static void noinline |
2515 | static void noinline |
2468 | infy_del (EV_P_ ev_stat *w) |
2516 | infy_del (EV_P_ ev_stat *w) |
2469 | { |
2517 | { |
… | |
… | |
2522 | for (ofs = 0; ofs < len; ofs += sizeof (struct inotify_event) + ev->len) |
2570 | for (ofs = 0; ofs < len; ofs += sizeof (struct inotify_event) + ev->len) |
2523 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
2571 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
2524 | } |
2572 | } |
2525 | |
2573 | |
2526 | void inline_size |
2574 | void inline_size |
2527 | infy_init (EV_P) |
2575 | check_2625 (EV_P) |
2528 | { |
2576 | { |
2529 | if (fs_fd != -2) |
|
|
2530 | return; |
|
|
2531 | |
|
|
2532 | /* kernels < 2.6.25 are borked |
2577 | /* kernels < 2.6.25 are borked |
2533 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
2578 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
2534 | */ |
2579 | */ |
2535 | { |
|
|
2536 | struct utsname buf; |
2580 | struct utsname buf; |
2537 | int major, minor, micro; |
2581 | int major, minor, micro; |
2538 | |
2582 | |
2539 | fs_fd = -1; |
|
|
2540 | |
|
|
2541 | if (uname (&buf)) |
2583 | if (uname (&buf)) |
2542 | return; |
2584 | return; |
2543 | |
2585 | |
2544 | if (sscanf (buf.release, "%d.%d.%d", &major, &minor, µ) != 3) |
2586 | if (sscanf (buf.release, "%d.%d.%d", &major, &minor, µ) != 3) |
2545 | return; |
2587 | return; |
2546 | |
2588 | |
2547 | if (major < 2 |
2589 | if (major < 2 |
2548 | || (major == 2 && minor < 6) |
2590 | || (major == 2 && minor < 6) |
2549 | || (major == 2 && minor == 6 && micro < 25)) |
2591 | || (major == 2 && minor == 6 && micro < 25)) |
2550 | return; |
2592 | return; |
2551 | } |
2593 | |
|
|
2594 | fs_2625 = 1; |
|
|
2595 | } |
|
|
2596 | |
|
|
2597 | void inline_size |
|
|
2598 | infy_init (EV_P) |
|
|
2599 | { |
|
|
2600 | if (fs_fd != -2) |
|
|
2601 | return; |
|
|
2602 | |
|
|
2603 | fs_fd = -1; |
|
|
2604 | |
|
|
2605 | check_2625 (EV_A); |
2552 | |
2606 | |
2553 | fs_fd = inotify_init (); |
2607 | fs_fd = inotify_init (); |
2554 | |
2608 | |
2555 | if (fs_fd >= 0) |
2609 | if (fs_fd >= 0) |
2556 | { |
2610 | { |
… | |
… | |
2584 | w->wd = -1; |
2638 | w->wd = -1; |
2585 | |
2639 | |
2586 | if (fs_fd >= 0) |
2640 | if (fs_fd >= 0) |
2587 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2641 | infy_add (EV_A_ w); /* re-add, no matter what */ |
2588 | else |
2642 | else |
2589 | ev_timer_start (EV_A_ &w->timer); |
2643 | ev_timer_again (EV_A_ &w->timer); |
2590 | } |
2644 | } |
2591 | } |
2645 | } |
2592 | } |
2646 | } |
2593 | |
2647 | |
2594 | #endif |
2648 | #endif |
… | |
… | |
2649 | ev_stat_start (EV_P_ ev_stat *w) |
2703 | ev_stat_start (EV_P_ ev_stat *w) |
2650 | { |
2704 | { |
2651 | if (expect_false (ev_is_active (w))) |
2705 | if (expect_false (ev_is_active (w))) |
2652 | return; |
2706 | return; |
2653 | |
2707 | |
2654 | /* since we use memcmp, we need to clear any padding data etc. */ |
|
|
2655 | memset (&w->prev, 0, sizeof (ev_statdata)); |
|
|
2656 | memset (&w->attr, 0, sizeof (ev_statdata)); |
|
|
2657 | |
|
|
2658 | ev_stat_stat (EV_A_ w); |
2708 | ev_stat_stat (EV_A_ w); |
2659 | |
2709 | |
|
|
2710 | if (w->interval < MIN_STAT_INTERVAL && w->interval) |
2660 | if (w->interval < MIN_STAT_INTERVAL) |
2711 | w->interval = MIN_STAT_INTERVAL; |
2661 | w->interval = w->interval ? MIN_STAT_INTERVAL : DEF_STAT_INTERVAL; |
|
|
2662 | |
2712 | |
2663 | ev_timer_init (&w->timer, stat_timer_cb, w->interval, w->interval); |
2713 | ev_timer_init (&w->timer, stat_timer_cb, 0., w->interval ? w->interval : DEF_STAT_INTERVAL); |
2664 | ev_set_priority (&w->timer, ev_priority (w)); |
2714 | ev_set_priority (&w->timer, ev_priority (w)); |
2665 | |
2715 | |
2666 | #if EV_USE_INOTIFY |
2716 | #if EV_USE_INOTIFY |
2667 | infy_init (EV_A); |
2717 | infy_init (EV_A); |
2668 | |
2718 | |
2669 | if (fs_fd >= 0) |
2719 | if (fs_fd >= 0) |
2670 | infy_add (EV_A_ w); |
2720 | infy_add (EV_A_ w); |
2671 | else |
2721 | else |
2672 | #endif |
2722 | #endif |
2673 | ev_timer_start (EV_A_ &w->timer); |
2723 | ev_timer_again (EV_A_ &w->timer); |
2674 | |
2724 | |
2675 | ev_start (EV_A_ (W)w, 1); |
2725 | ev_start (EV_A_ (W)w, 1); |
2676 | |
2726 | |
2677 | EV_FREQUENT_CHECK; |
2727 | EV_FREQUENT_CHECK; |
2678 | } |
2728 | } |