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 589471F452 for ; Fri, 27 Oct 2023 22:21:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1698445276; bh=R/MEs7SJmHl2Pxn4E6ollGp3BzVvq3KutcqjOl+QqcQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NuGMxXM4KEcpkmwYG3Y8/TYgMHcj2WkU6iaJ708xSbz+vAmQ+DAWoFLgZf8YuC2z6 bKq2NqqrhyNpCGJqEE+MJDGl8XWaUHs3qK/SAFGetYo/DPzLM9Qb8mVh7PGKbgjWU+ thcHicBialip0ryQ423yHZVFbagc4LcNZTH1aURc= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 01/10] spawn: croak directly in C pi_fork_exec Date: Fri, 27 Oct 2023 22:21:07 +0000 Message-ID: <20231027222116.4034363-2-e@80x24.org> In-Reply-To: <20231027222116.4034363-1-e@80x24.org> References: <20231027222116.4034363-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This saves us some Perl code in the wrapper, since the SpawnPP implementation also dies directly. --- lib/PublicInbox/Spawn.pm | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm index 1fa7a41f..5740ee58 100644 --- a/lib/PublicInbox/Spawn.pm +++ b/lib/PublicInbox/Spawn.pm @@ -89,7 +89,7 @@ int pi_fork_exec(SV *redirref, SV *file, SV *cmdref, SV *envref, SV *rlimref, AV *env = (AV *)SvRV(envref); AV *rlim = (AV *)SvRV(rlimref); const char *filename = SvPV_nolen(file); - pid_t pid; + pid_t pid = -1; char **argv, **envp; sigset_t set, old; int ret, perrnum; @@ -100,17 +100,17 @@ int pi_fork_exec(SV *redirref, SV *file, SV *cmdref, SV *envref, SV *rlimref, AV2C_COPY(argv, cmd); AV2C_COPY(envp, env); - if (sigfillset(&set)) return -1; - if (sigdelset(&set, SIGABRT)) return -1; - if (sigdelset(&set, SIGBUS)) return -1; - if (sigdelset(&set, SIGFPE)) return -1; - if (sigdelset(&set, SIGILL)) return -1; - if (sigdelset(&set, SIGSEGV)) return -1; + if (sigfillset(&set)) goto out; + if (sigdelset(&set, SIGABRT)) goto out; + if (sigdelset(&set, SIGBUS)) goto out; + if (sigdelset(&set, SIGFPE)) goto out; + if (sigdelset(&set, SIGILL)) goto out; + if (sigdelset(&set, SIGSEGV)) goto out; /* no XCPU/XFSZ here */ - if (sigprocmask(SIG_SETMASK, &set, &old)) return -1; + if (sigprocmask(SIG_SETMASK, &set, &old)) goto out; chld_is_member = sigismember(&old, SIGCHLD); - if (chld_is_member < 0) return -1; - if (chld_is_member > 0 && sigdelset(&old, SIGCHLD)) return -1; + if (chld_is_member < 0) goto out; + if (chld_is_member > 0 && sigdelset(&old, SIGCHLD)) goto out; pid = vfork(); if (pid == 0) { @@ -171,6 +171,8 @@ int pi_fork_exec(SV *redirref, SV *file, SV *cmdref, SV *envref, SV *rlimref, } else if (perrnum) { errno = perrnum; } +out: + if (pid < 0) croak("E: fork_exec %s: %s\n", filename, strerror(errno)); return (int)pid; } @@ -369,9 +371,7 @@ sub spawn ($;$$) { } my $cd = $opt->{'-C'} // ''; # undef => NULL mapping doesn't work? my $pgid = $opt->{pgid} // -1; - my $pid = pi_fork_exec(\@rdr, $f, $cmd, \@env, $rlim, $cd, $pgid); - die "fork_exec @$cmd failed: $!\n" unless $pid > 0; - $pid; + pi_fork_exec(\@rdr, $f, $cmd, \@env, $rlim, $cd, $pgid); } sub popen_rd {