From cf977e706b07e80f394570a393eb2169b9b9a1a7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 28 Dec 2023 04:23:00 +0000 Subject: pure Perl inotify support This is a step towards improving the out-of-the-box experience in achieving notifications without XS, extra downloads, and .so loading + runtime mmap overhead. This also fixes loongarch support of all Linux syscalls due to a bad regexp :x All the reachable Linux architectures listed at should be supported. At the moment, there appears to be no reachable sparc* Linux machines available to cfarm users. Fixes: b0e5093aa3572a86 (syscall: add support for riscv64, 2022-08-11) --- t/imapd.t | 2 +- t/inotify3.t | 17 +++++++++++++++++ t/lei-auto-watch.t | 4 ++-- t/lei-watch.t | 4 ++-- t/nntpd.t | 2 +- t/watch_maildir.t | 2 +- 6 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 t/inotify3.t (limited to 't') diff --git a/t/imapd.t b/t/imapd.t index 9606291e..549b8766 100644 --- a/t/imapd.t +++ b/t/imapd.t @@ -250,7 +250,7 @@ SKIP: { ok($mic->logout, 'logout works'); -my $have_inotify = eval { require Linux::Inotify2; 1 }; +my $have_inotify = eval { require PublicInbox::Inotify; 1 }; for my $ibx (@ibx) { my $name = $ibx->{name}; diff --git a/t/inotify3.t b/t/inotify3.t new file mode 100644 index 00000000..c25c0f42 --- /dev/null +++ b/t/inotify3.t @@ -0,0 +1,17 @@ +#!perl -w +# Copyright (C) all contributors +# License: AGPL-3.0+ +use v5.12; use PublicInbox::TestCommon; +plan skip_all => 'inotify is Linux-only' if $^O ne 'linux'; +use_ok 'PublicInbox::Inotify3'; +my $in = PublicInbox::Inotify3->new; +my $tmpdir = tmpdir; +my $w = $in->watch("$tmpdir", PublicInbox::Inotify3::IN_ALL_EVENTS()); +$in->blocking(0); +is_xdeeply [ $in->read ], [], 'non-blocking has no events, yet'; +undef $tmpdir; +my @list = $in->read; +ok scalar(@list), 'got events'; +ok $w->cancel, 'watch canceled'; + +done_testing; diff --git a/t/lei-auto-watch.t b/t/lei-auto-watch.t index f871188d..1e190316 100644 --- a/t/lei-auto-watch.t +++ b/t/lei-auto-watch.t @@ -4,10 +4,10 @@ use strict; use v5.10.1; use PublicInbox::TestCommon; use File::Basename qw(basename); plan skip_all => "TEST_FLAKY not enabled for $0" if !$ENV{TEST_FLAKY}; -my $have_fast_inotify = eval { require Linux::Inotify2 } || +my $have_fast_inotify = eval { require PublicInbox::Inotify } || eval { require IO::KQueue }; $have_fast_inotify or - diag("$0 IO::KQueue or Linux::Inotify2 missing, test will be slow"); + diag("$0 IO::KQueue or inotify missing, test will be slow"); test_lei(sub { my ($ro_home, $cfg_path) = setup_public_inboxes; diff --git a/t/lei-watch.t b/t/lei-watch.t index 24d9f5c8..7b357ee0 100644 --- a/t/lei-watch.t +++ b/t/lei-watch.t @@ -5,11 +5,11 @@ use strict; use v5.10.1; use PublicInbox::TestCommon; use File::Path qw(make_path remove_tree); plan skip_all => "TEST_FLAKY not enabled for $0" if !$ENV{TEST_FLAKY}; require_mods('lei'); -my $have_fast_inotify = eval { require Linux::Inotify2 } || +my $have_fast_inotify = eval { require PublicInbox::Inotify } || eval { require IO::KQueue }; $have_fast_inotify or - diag("$0 IO::KQueue or Linux::Inotify2 missing, test will be slow"); + diag("$0 IO::KQueue or inotify missing, test will be slow"); my ($ro_home, $cfg_path) = setup_public_inboxes; test_lei(sub { diff --git a/t/nntpd.t b/t/nntpd.t index 0f3ef596..7052cb6a 100644 --- a/t/nntpd.t +++ b/t/nntpd.t @@ -14,7 +14,7 @@ use PublicInbox::DS; my $version = $ENV{PI_TEST_VERSION} || 1; require_git('2.6') if $version == 2; use_ok 'PublicInbox::Msgmap'; -my $fast_idle = eval { require Linux::Inotify2; 1 } // +my $fast_idle = eval { require PublicInbox::Inotify; 1 } // eval { require IO::KQueue; 1 }; my ($tmpdir, $for_destroy) = tmpdir(); diff --git a/t/watch_maildir.t b/t/watch_maildir.t index 07ebeef6..d7f01b1a 100644 --- a/t/watch_maildir.t +++ b/t/watch_maildir.t @@ -182,7 +182,7 @@ EOM # wait for -watch to setup inotify watches my $sleep = 1; - if (eval { require Linux::Inotify2 } && -d "/proc/$wm->{pid}/fd") { + if (eval { require PublicInbox::Inotify } && -d "/proc/$wm->{pid}/fd") { my $end = time + 2; my (@ino, @ino_info); do { -- cgit v1.2.3-24-ge0c7