From 30afcadb13f446c99952883bbaa54e102757b682 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 30 Dec 2019 05:04:15 +0000 Subject: spawn: support chdir via -C option This simplifies our admin module a bit and allows solver to be used with v1 inboxes using git versions prior to v1.8.5 (but still >= git v1.8.0). --- lib/PublicInbox/Spawn.pm | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/PublicInbox/Spawn.pm') diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm index 6d42d5bc..d624c521 100644 --- a/lib/PublicInbox/Spawn.pm +++ b/lib/PublicInbox/Spawn.pm @@ -84,7 +84,8 @@ static void xerr(const char *msg) * whatever we'll need in the future. * Be sure to update PublicInbox::SpawnPP if this changes */ -int pi_fork_exec(SV *redirref, SV *file, SV *cmdref, SV *envref, SV *rlimref) +int pi_fork_exec(SV *redirref, SV *file, SV *cmdref, SV *envref, SV *rlimref, + const char *cd) { AV *redir = (AV *)SvRV(redirref); AV *cmd = (AV *)SvRV(cmdref); @@ -118,6 +119,8 @@ int pi_fork_exec(SV *redirref, SV *file, SV *cmdref, SV *envref, SV *rlimref) } for (sig = 1; sig < NSIG; sig++) signal(sig, SIG_DFL); /* ignore errors on signals */ + if (*cd && chdir(cd) < 0) + xerr("chdir"); max = av_len(rlim); for (i = 0; i < max; i += 3) { @@ -216,7 +219,8 @@ sub spawn ($;$$) { } push @$rlim, $r, @$v; } - my $pid = pi_fork_exec($redir, $f, $cmd, \@env, $rlim); + my $cd = $opts->{'-C'} // ''; # undef => NULL mapping doesn't work? + my $pid = pi_fork_exec($redir, $f, $cmd, \@env, $rlim, $cd); $pid < 0 ? undef : $pid; } -- cgit v1.2.3-24-ge0c7