From: Ian Jackson Date: Tue, 11 Feb 2020 18:32:49 +0000 (+0000) Subject: git-cache-proxy: Use open-coded fork/exec for git gc X-Git-Tag: archive/debian/6.1.2~7 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=62a48a2db8c1e4eb201d31137f012cb2edb26b9b;p=chiark-utils.git git-cache-proxy: Use open-coded fork/exec for git gc This allows us to handle ENOENT from chdir specially. We want to tolerate this, because it can happen if the previous lockholder cleaned it all up. Signed-off-by: Ian Jackson --- diff --git a/scripts/git-cache-proxy b/scripts/git-cache-proxy index 636ebfe..ec5ff7f 100755 --- a/scripts/git-cache-proxy +++ b/scripts/git-cache-proxy @@ -447,12 +447,19 @@ sub housekeeping () { $mode_action = sub { my $gclog = "$subdir/gc.log"; unlink $gclog or $!==ENOENT or hkfail "remove $gclog: $!"; - my $r = system qw(sh -ec), - 'cd "$1"; shift; exec "$@"', 'x', "$subdir\\.git", - qw(git gc --quiet); - if ($r) { + my $child = fork // hkfail "fork (for $subdir): $!"; + if (!$child) { + if (!chdir "$subdir\\.git") { + exit 0 if $!==ENOENT; + die "for gc: chdir $subdir: $!\n"; + } + exec qw(git gc --quiet); + die "exec git gc (for $subdir): $!\n"; + } + waitpid($child, 0) == $child or hkfail "waitpid failed! $!"; + if ($?) { logm 'err', - "housekeeping: subdirs $subdir: gc failed (status $r)"; + "housekeeping: subdirs $subdir: gc failed (wait status $?)"; } else { update_gcstamp("$subdir\\.git"); logm 'debug',