From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 426191F935 for ; Sat, 27 Jun 2020 10:04:05 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 27/34] testcommon: $ENV{TAIL} supports non-@ARGV redirects Date: Sat, 27 Jun 2020 10:03:53 +0000 Message-Id: <20200627100400.9871-28-e@yhbt.net> In-Reply-To: <20200627100400.9871-1-e@yhbt.net> References: <20200627100400.9871-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Existing use of the $ENV{TAIL} relied on parsing --std{out,err}, which was only usable for read-only daemons. However, -watch doesn't use PublicInbox::Daemon code(*), so attempt to figure out redirects. (*) -watch won't able to run as a daemon in cases when git-credential prompts for IMAP/NNTP passwords. PublicInbox::Daemon is also designed for read-only parallelism where all worker processes are the same. Any subprocesses spawned by -watch are to do specific tasks for a particular set of inboxes. --- lib/PublicInbox/TestCommon.pm | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index 7b4da8b5f09..b03e93e0f5b 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -276,11 +276,11 @@ sub tick (;$) { } sub wait_for_tail ($;$) { - my ($tail_pid, $stop) = @_; + my ($tail_pid, $want) = @_; my $wait = 2; if ($^O eq 'linux') { # GNU tail may use inotify state $tail_has_inotify; - return tick if $stop && $tail_has_inotify; + return tick if $want < 0 && $tail_has_inotify; my $end = time + $wait; my @ino; do { @@ -297,7 +297,7 @@ sub wait_for_tail ($;$) { local $/ = "\n"; @info = grep(/^inotify wd:/, <$fh>); } - } while (scalar(@info) < 2 && time <= $end and tick); + } while (scalar(@info) < $want && time <= $end and tick); } else { sleep($wait); } @@ -337,6 +337,18 @@ sub start_script { next unless /\A--std(?:err|out)=(.+)\z/; push @paths, $1; } + if ($opt) { + for (1, 2) { + my $f = $opt->{$_} or next; + if (!ref($f)) { + push @paths, $f; + } elsif (ref($f) eq 'GLOB' && $^O eq 'linux') { + my $fd = fileno($f); + my $f = readlink "/proc/$$/fd/$fd"; + push @paths, $f if -e $f; + } + } + } if (@paths) { defined($tail_pid = fork) or die "fork: $!\n"; if ($tail_pid == 0) { @@ -346,7 +358,7 @@ sub start_script { exec(split(' ', $tail_cmd), @paths); die "$tail_cmd failed: $!"; } - wait_for_tail($tail_pid); + wait_for_tail($tail_pid, scalar @paths); } } defined(my $pid = fork) or die "fork: $!\n"; @@ -414,7 +426,7 @@ sub DESTROY { my ($self) = @_; return if $self->{owner} != $$; if (my $tail_pid = delete $self->{tail_pid}) { - PublicInbox::TestCommon::wait_for_tail($tail_pid, 1); + PublicInbox::TestCommon::wait_for_tail($tail_pid, -1); CORE::kill('TERM', $tail_pid); } $self->join('TERM');