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 01B031F4C4; Fri, 8 Nov 2024 12:06:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1731067607; bh=IWaiMuXu+pYo7GV+Fff6GsCENKOIxBxiCgC8m9Xqkzg=; h=From:To:Cc:Subject:Date:From; b=eOLSi8kp+BwvYoifQvLLFJAnl2qxtPbDeANHC+oJIHU2lnfwsb3FJxqnRrJp3CCwV gYIFqylFAr2A7ItR3Ss6YveBqE4RLL2/mHlnSDT+cabihYkG58KCHmRwIjJqGC+NHE Nkm+pG70PvpB4NSMrQzEtW8UVvuunxSy1P7D0U14= From: Eric Wong To: meta@public-inbox.org Cc: Eric Wong Subject: [PATCH] EOFpipe: avoid uninitialized variables in lei tests Date: Fri, 8 Nov 2024 12:06:46 +0000 Message-ID: <20241108120646.2173509-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Eric Wong EINTR can happen due to spurious wakeups and lead to uninitialized variable warnings when comparing the result of ->do_read to a numeric value. Thus avoid EINTR by making the pipe non-blocking on initialization. Furthermore, our ->do_read API is overkill and not appropriate for only detecting EOF on a pipe since it is designed for parsing network protocols. Relying on level-triggering makes more sense here, since we only want to detect EOF and don't have to worry about event loop monopolization. --- lib/PublicInbox/EOFpipe.pm | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/EOFpipe.pm b/lib/PublicInbox/EOFpipe.pm index 77b699a2..3eaa0e4e 100644 --- a/lib/PublicInbox/EOFpipe.pm +++ b/lib/PublicInbox/EOFpipe.pm @@ -4,21 +4,29 @@ package PublicInbox::EOFpipe; use v5.12; use parent qw(PublicInbox::DS); -use PublicInbox::Syscall qw(EPOLLIN EPOLLONESHOT $F_SETPIPE_SZ); +use PublicInbox::Syscall qw(EPOLLIN $F_SETPIPE_SZ); +use Errno qw(EAGAIN); sub new { my (undef, $rd, @cb_args) = @_; my $self = bless { cb_args => \@cb_args }, __PACKAGE__; # 4096: page size fcntl($rd, $F_SETPIPE_SZ, 4096) if $F_SETPIPE_SZ; - $self->SUPER::new($rd, EPOLLIN|EPOLLONESHOT); + $rd->blocking(0); # avoid EINTR + $self->SUPER::new($rd, EPOLLIN); # level trigger for spurious wakeup } sub event_step { my ($self) = @_; - if ($self->do_read(my $buf, 1) == 0) { # auto-closed + my $r = sysread $self->{sock}, my $buf, 1; + if (!defined $r) { + warn "W: EOFpipe read: $!\n" if $! != EAGAIN; + } elsif ($r == 0) { + $self->close; my ($cb, @args) = @{delete $self->{cb_args}}; $cb->(@args); + } else { + warn "BUG? EOFpipe read $r bytes, expected 0\n"; } }