From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C4FEA1F55F for ; Fri, 8 Sep 2023 07:53:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1694159601; bh=a8+AnN4p/nEHHLb/Z4lJyxwpvDdsbVNsCxfpi6hxUnU=; h=From:To:Subject:Date:From; b=q0Unj5Sf8kCj3JBEntKBG1+h3HbUKKJNKqZ5X3igwD3qHy6fm3WvArWrZSD2zBS7e O++Qw7GY2bmAcCrvN3f1r6yV3kiRx3vJFmFDaim/tvZ5gRdk8S6zIExQZYvS3XKP1c 287wVA8viqpyN/Y0IMsdEvtdcm3QlkKUqvqmPjGg= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] tail_notify: explicitly detect self deletion Date: Fri, 8 Sep 2023 07:51:29 +0000 Message-ID: <20230908075129.94897-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This allows t/tail_notify.t to pass more reliably using FreeBSD with IO::KQueue. --- lib/PublicInbox/TailNotify.pm | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/TailNotify.pm b/lib/PublicInbox/TailNotify.pm index f4ffb296..bdb92d54 100644 --- a/lib/PublicInbox/TailNotify.pm +++ b/lib/PublicInbox/TailNotify.pm @@ -14,12 +14,14 @@ if ($^O eq 'linux' && eval { require PublicInbox::Inotify; 1 }) { Linux::Inotify2::IN_MODIFY(); $ino_cls = 'PublicInbox::Inotify'; } elsif (eval { require PublicInbox::KQNotify }) { - $TAIL_MOD = PublicInbox::KQNotify::MOVED_TO_OR_CREATE(); + $TAIL_MOD = PublicInbox::KQNotify::MOVED_TO_OR_CREATE() | + IO::KQueue::NOTE_DELETE() | IO::KQueue::NOTE_RENAME(); $ino_cls = 'PublicInbox::KQNotify'; } else { require PublicInbox::FakeInotify; $TAIL_MOD = PublicInbox::FakeInotify::MOVED_TO_OR_CREATE() | - PublicInbox::FakeInotify::IN_MODIFY(); + PublicInbox::FakeInotify::IN_MODIFY() | + PublicInbox::FakeInotify::IN_DELETE(); } require IO::Poll if $ino_cls; @@ -49,6 +51,11 @@ sub new { $self; } +sub delete_self { + for (@_) { return 1 if $_->IN_DELETE_SELF } + undef; +} + sub getlines { my ($self, $timeo) = @_; my ($fh, $buf, $rfds, @ret, @events); @@ -70,13 +77,12 @@ again: } select($rfds, undef, undef, $wait); } - # XXX do we care about @events contents? - # use Data::Dumper; warn '# ',Dumper(\@events); if ($fh = $self->{watch_fh}) { sysread($fh, $buf, -s $fh) and push @ret, split(/^/sm, $buf); my @st = stat($self->{fn}); - if (!@st || "@st[0, 1]" ne $self->{ino_dev}) { + if (!@st || "@st[0, 1]" ne $self->{ino_dev} || + delete_self(@events)) { delete @$self{qw(ino_dev watch_fh)}; } }