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.
}
sub wait_for_tail ($;$) {
}
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;
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 {
my $end = time + $wait;
my @ino;
do {
local $/ = "\n";
@info = grep(/^inotify wd:/, <$fh>);
}
local $/ = "\n";
@info = grep(/^inotify wd:/, <$fh>);
}
- } while (scalar(@info) < 2 && time <= $end and tick);
+ } while (scalar(@info) < $want && time <= $end and tick);
next unless /\A--std(?:err|out)=(.+)\z/;
push @paths, $1;
}
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) {
if (@paths) {
defined($tail_pid = fork) or die "fork: $!\n";
if ($tail_pid == 0) {
exec(split(' ', $tail_cmd), @paths);
die "$tail_cmd failed: $!";
}
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";
}
}
defined(my $pid = fork) or die "fork: $!\n";
my ($self) = @_;
return if $self->{owner} != $$;
if (my $tail_pid = delete $self->{tail_pid}) {
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');
CORE::kill('TERM', $tail_pid);
}
$self->join('TERM');