]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/LeiInput.pm
lei: TSTP affects all curl and related subprocesses
[public-inbox.git] / lib / PublicInbox / LeiInput.pm
index fe736981ba6565d111871f6778b11838d1ecf83d..dd40d83840c57cb2e790fd86d30699b8a11f60c5 100644 (file)
@@ -8,6 +8,7 @@ use v5.10.1;
 use PublicInbox::DS;
 use PublicInbox::Spawn qw(which popen_rd);
 use PublicInbox::InboxWritable qw(eml_from_path);
+use PublicInbox::AutoReap;
 
 # JMAP RFC 8621 4.1.1
 # https://www.iana.org/assignments/imap-jmap-keywords/imap-jmap-keywords.xhtml
@@ -57,6 +58,12 @@ sub check_input_format ($;$) {
        1;
 }
 
+sub input_mbox_cb { # base MboxReader callback
+       my ($eml, $self) = @_;
+       $eml->header_set($_) for (qw(Status X-Status));
+       $self->input_eml_cb($eml);
+}
+
 # import a single file handle of $name
 # Subclass must define ->input_eml_cb and ->input_mbox_cb
 sub input_fh {
@@ -96,13 +103,13 @@ sub handle_http_input ($$@) {
        push @$curl, '-s', @$curl_opt;
        my $cmd = $curl->for_uri($lei, $uri);
        $lei->qerr("# $cmd");
-       my $rdr = { 2 => $lei->{2}, pgid => 0 };
-       my ($fh, $pid) = popen_rd($cmd, undef, $rdr);
+       my ($fh, $pid) = popen_rd($cmd, undef, { 2 => $lei->{2} });
+       my $ar = PublicInbox::AutoReap->new($pid);
        grep(/\A--compressed\z/, @$curl) or
                $fh = IO::Uncompress::Gunzip->new($fh, MultiStream => 1);
        eval { $self->input_fh('mboxrd', $fh, $url, @args) };
        my $err = $@;
-       waitpid($pid, 0);
+       $ar->join;
        $? || $err and
                $lei->child_error($?, "@$cmd failed".$err ? " $err" : '');
 }
@@ -337,8 +344,8 @@ $input is `eml', not --in-format=$in_fmt
 --mail-sync specified but no inputs support it
 
                # non-fatal if some inputs support support sync
-               $lei->err("# --mail-sync will only be used for @{$sync->{ok}}");
-               $lei->err("# --mail-sync is not supported for: @{$sync->{no}}");
+               warn("# --mail-sync will only be used for @{$sync->{ok}}\n");
+               warn("# --mail-sync is not supported for: @{$sync->{no}}\n");
        }
        if ($net) {
                $net->{-can_die} = 1;
@@ -378,7 +385,7 @@ sub process_inputs {
        }
        # always commit first, even on error partial work is acceptable for
        # lei <import|tag|convert>
-       my $wait = $self->{lei}->{sto}->ipc_do('done') if $self->{lei}->{sto};
+       my $wait = $self->{lei}->{sto}->wq_do('done') if $self->{lei}->{sto};
        $self->{lei}->fail($err) if $err;
 }