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, T_SCC_BODY_TEXT_LINE 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 1FD411F461 for ; Sun, 26 Nov 2023 02:11:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1700964666; bh=cWwYpit8GL1CGCuXXttiPrZmrGHu39xO/Msy//t+rO8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Unw5MyJktxTKkcyPOX/AXJmU9cP7zoyC5nhB6246XWjyh6hFEIpoLGAhrzg5TgkzC 1ISOwY7WYAfO3YMFE3xeGVJPTWXAN/kAAdB0mhljooA703VH3rLycAn4W2X0UUPsr4 UiBvGTEcpv/coNWUkiPqHyHn7CmxyGeoO7PPB0CM= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/7] xap_client: attach PID to the IO object Date: Sun, 26 Nov 2023 02:11:00 +0000 Message-ID: <20231126021105.408573-3-e@80x24.org> In-Reply-To: <20231126021105.408573-1-e@80x24.org> References: <20231126021105.408573-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: As with our popen_* uses, we can simplify callers by using attach_pid to handle automatic reaping upon close. --- lib/PublicInbox/CodeSearchIdx.pm | 10 ++-------- lib/PublicInbox/XapClient.pm | 4 +++- t/xap_helper.t | 3 +-- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/PublicInbox/CodeSearchIdx.pm b/lib/PublicInbox/CodeSearchIdx.pm index 81ca5cbc..3764f13e 100644 --- a/lib/PublicInbox/CodeSearchIdx.pm +++ b/lib/PublicInbox/CodeSearchIdx.pm @@ -516,15 +516,9 @@ sub shard_commit { # via wq_io_do send($op_p, "shard_done $self->{shard}", 0); } -sub start_xhc () { - my ($xhc, $pid) = PublicInbox::XapClient::start_helper("-j$NPROC"); - awaitpid($pid, \&cmd_done, ['xap_helper', "-j$NPROC"]); - $xhc; -} - sub dump_roots_start { my ($self, $do_join) = @_; - $XHC //= start_xhc; + $XHC //= PublicInbox::XapClient::start_helper("-j$NPROC"); $do_join // die 'BUG: no $do_join'; progress($self, 'dumping IDs from coderepos'); local $self->{xdb}; @@ -577,7 +571,7 @@ EOM sub dump_ibx_start { my ($self, $do_join) = @_; - $XHC //= start_xhc; + $XHC //= PublicInbox::XapClient::start_helper("-j$NPROC"); my ($sort_opt, $fold_opt); pipe(local $sort_opt->{0}, $DUMP_IBX_WPIPE); pipe(local $fold_opt->{0}, local $sort_opt->{1}); diff --git a/lib/PublicInbox/XapClient.pm b/lib/PublicInbox/XapClient.pm index dda5e044..7737e30d 100644 --- a/lib/PublicInbox/XapClient.pm +++ b/lib/PublicInbox/XapClient.pm @@ -41,7 +41,9 @@ sub start_helper { $cls.'::start(@ARGV)', '--' ]; } my $pid = spawn($cmd, $env, { 0 => $in }); - ((bless { io => $sock, impl => $cls }, __PACKAGE__), $pid); + my $self = bless { io => $sock, impl => $cls }, __PACKAGE__; + PublicInbox::IO::attach_pid($sock, $pid); + $self; } 1; diff --git a/t/xap_helper.t b/t/xap_helper.t index 9e0b234d..02e5ec7d 100644 --- a/t/xap_helper.t +++ b/t/xap_helper.t @@ -173,8 +173,7 @@ my @id2root; my $ar; for my $n (@NO_CXX) { local $ENV{PI_NO_CXX} = $n; - my ($xhc, $pid) = PublicInbox::XapClient::start_helper('-j0'); - $ar = PublicInbox::AutoReap->new($pid); + my $xhc = PublicInbox::XapClient::start_helper('-j0'); pipe(my $err_r, my $err_w); # git patch-id --stable